Leetcode
DSA problem write-ups, auto-generated from my LeetHub-pushed solutions. Browse by topic on the tags page, or scroll the full list below.
Two Sum
Given an array of integers and a target integer, find the indices of two numbers that add up to the target.
Add Two Numbers
Given two non-empty linked lists representing non-negative integers in reverse order, add them and return the sum as a new linked list.
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring that does not contain any repeating characters.
Median of Two Sorted Arrays
Given two sorted arrays, find the median of the combined sorted array.
Longest Palindromic Substring
Given a string `s`, find and return the longest substring within `s` that is also a palindrome.
Zigzag Conversion
Given a string and a number of rows, arrange the string in a zigzag pattern and then read it line by line to produce a new string.
Reverse Integer
Reverse the digits of a signed 32-bit integer.
String to Integer (atoi)
Implement the `myAtoi` function to convert a string to a 32-bit signed integer.
Palindrome Number
Determine if a given integer reads the same forwards and backward.
Container With Most Water
Given an array representing the heights of vertical lines, find two lines that, along with the x-axis, form a container holding theโฆ
Integer To Roman
Convert an integer into its Roman numeral representation.
Roman To Integer
Convert a Roman numeral string into its corresponding integer value.
Longest Common Prefix
Given an array of strings, find the longest common prefix among them.
Letter Combinations of a Phone Number
Given a string of digits from 2-9, generate all possible letter combinations that the digits can represent, based on a standard phoneโฆ
Remove Nth Node From End of List
Given the head of a linked list, remove the nth node from the end of the list and return its head.
Valid Parentheses
Given a string containing only parentheses, determine if the brackets are correctly matched and ordered.
Search In Rotated Sorted Array
Find a target value in a sorted array that has been rotated at an unknown pivot point.
Combination Sum
Find all unique combinations of distinct integers that sum up to a target value.
Permutations
Find all possible arrangements of distinct integers in an array.
Maximum Subarray
Given an array of integers, find the contiguous subarray with the largest sum and return its sum.
Merge Intervals
Merge overlapping intervals in a list and return the non-overlapping intervals that cover all inputs
Insert Interval
Given a sorted list of non-overlapping intervals and a new interval, insert the new interval into the list while maintaining the sortedโฆ
Add Binary
Given two binary strings, return their sum as a new binary string.
Climbing Stairs
You need to find the number of distinct ways to climb a staircase with `n` steps, given that you can take either 1 or 2 steps at a time.
Validate Binary Search Tree
Determine if a given binary tree is a valid binary search tree (BST).
Binary Tree Level Order Traversal
Given the root of a binary tree, return the values of its nodes level by level, from left to right.
Maximum Depth of Binary Tree
Given the root of a binary tree, determine the maximum depth.
Balanced Binary Tree
Determine if a given binary tree is height-balanced, meaning the heights of the two subtrees of every node never differ by more than one.
Best Time to Buy and Sell Stock
Given an array of stock prices for consecutive days, find the maximum profit that can be achieved by buying on one day and selling on aโฆ
Valid Palindrome
Determine if a given string is a palindrome after converting all uppercase letters to lowercase and removing all non-alphanumericโฆ
Clone Graph
Given a connected undirected graph represented by a reference to one of its nodes, create a deep copy of the entire graph.
Linked List Cycle
Given the head of a linked list, determine if there's a cycle present.
Evaluate Reverse Polish Notation
Given an array of strings representing an arithmetic expression in Reverse Polish Notation (RPN), evaluate the expression and return theโฆ
Min Stack
Design a stack to efficiently track the minimum element in constant time.
Majority Element
Given an array of integers, find the element that appears more than half the time.
Reverse Linked List
Given the head of a singly linked list, reverse the list and return the head of the reversed list.
Implement Trie Prefix Tree
Implement a Trie data structure for efficient string storage and prefix searching.
Contains Duplicate
Given an array of integers, determine if any number appears more than once.
Invert Binary Tree
Given the root of a binary tree, invert the tree by swapping its left and right children at each node.
Implement Queue Using Stacks
Implement a queue data structure (First-In, First-Out) using only the standard operations of two stacks.
Lowest Common Ancestor of a Binary Search Tree
Find the lowest common ancestor (LCA) of two given nodes, `p` and `q`, in a Binary Search Tree (BST).
Lowest Common Ancestor of a Binary Tree
Find the deepest node shared by two given nodes in a binary tree.
Product Of Array Except Self
Compute the product of all elements in an array except for the element at the current index, without using division.
Valid Anagram
Determine if one string is an anagram of another.
First Bad Version
Given the total number of versions of a product and an API that checks if a version is bad, find the first version that is bad.
Coin Change
Find the minimum number of coins to make a target amount, or return -1 if impossible
Ransom Note
Given two strings, `ransomNote` and `magazine`, determine if the `ransomNote` can be constructed using the letters from `magazine`.
Longest Palindrome
Given a string composed of lowercase and uppercase English letters, determine the length of the longest possible palindrome that can beโฆ
Diameter of Binary Tree
The goal is to find the length of the longest path between any two nodes in a binary tree.
Binary Search
Given a sorted array of integers, find the index of a given target value.
Flood Fill
Given a 2D grid representing an image, a starting pixel's coordinates, and a new color, change the color of the starting pixel and allโฆ
Middle of the Linked List
Given the head of a singly linked list, find and return the middle node.
K Closest Points to Origin
Given a list of 2D points and an integer k, find the k points that are closest to the origin (0,0).
Rotting Oranges
Return the minimum time until no fresh oranges remain, or -1 if impossible.
Sum
Given an array of integers, find all unique triplets that sum to zero.
Sum Closest
Given an array of integers, find three distinct numbers whose sum is as close as possible to a given target value.
Sum
Find all unique quadruplets in a given array of integers that sum up to a specific target value.
1 Matrix
Given a binary matrix, find the shortest distance from each cell to the nearest '0' cell.