Coding Interview Problems
In-depth walkthroughs of coding interview problems from top tech companies
181 problems
| Problem | Diff. |
|---|---|
|
T9 predictive text generation
Generate all possible T9 text strings from phone keypad digit presses using DFS backtracking. A classic recursion and combinations interview problem.
|
75 |
|
String permutations and combinations
Given a string of unique characters, return all permutations of all combinations. Solve it with recursion and backtracking.
|
71 |
|
Grid max sum path with dynamic programming
Find the maximum sum path from top-left to bottom-right in a grid using dynamic programming with O(m*n) time and space.
|
59 |
|
Grid max sum path with depth first search
Find the maximum sum path from top-left to bottom-right in a grid using DFS, moving only down or right.
|
56 |
|
Distance between two nodes of a binary tree
Given a binary tree and two node values, find the minimum number of edges between them using the Lowest Common Ancestor (LCA) approach.
|
69 |
|
Boggle word finder
Given a Boggle board and a target word, search the board using DFS with backtracking to determine if the word can be formed by adjacent cells.
|
65 |
|
Find the missing number in a 1 to 10 sequence
Given an array of 9 unique integers from 1 to 10 with one missing, find the missing number using the sum formula in O(n) time and O(1) space.
|
15 |
|
Merge k sorted linked lists
Given k sorted linked lists, merge them into one globally sorted list using a min heap for O(n * k * log(k)) time and O(k) space.
|
65 |
|
Distance of a node from the root of a binary tree
Given the root of a binary tree and a target value, find the minimum distance from the root to the node containing the target. A DFS approach runs in O(n) time.
|
55 |
|
Binary tree serialization and deserialization
Learn how to serialize a binary tree to a string and deserialize it back using recursive pre-order traversal. Covers O(n) time and space solution.
|
59 |
|
Binary tree decompression
Given a compressed, serialized binary tree string, decompress and reconstruct the original tree using level-order traversal with a queue.
|
59 |
|
Return all paths from top-left to bottom-right in a grid
Given a 2D board of letters, find all paths from top-left to bottom-right moving only down or right, returning each path as a string.
|
57 |
|
Introduction to Tries - Inserting Words
Learn how to implement a Trie data structure by building the insert method. Step-by-step walkthrough with visualizations.
|
58 |
|
Introduction to tries - searching for words
Learn how to implement the search method in a Trie data structure, distinguishing complete words from prefixes using word boundaries.
|
57 |
|
Merge intervals: combine overlapping ranges efficiently
Learn how to merge overlapping intervals using sorting and linear scan. Step-by-step walkthrough with visualizations and solutions in 14 languages.
|
55 |
|
Iterative binary search tree validation
Given the root of a binary tree, determine if it is a valid BST using an iterative approach with a queue and bounds tracking.
|
45 |
|
Maximum sum path with negative numbers in a binary tree
Find the maximum sum path between any two nodes in a binary tree that contains both positive and negative values. A classic Google and Facebook interview question.
|
58 |
|
Rotate a square image clockwise by 90 degrees
Given a square matrix representing a black and white image, rotate it clockwise by 90 degrees using transpose and vertical flip.
|
44 |
|
Rotate a square image counterclockwise
Rotate a square 2D matrix 90 degrees counterclockwise using the transpose-then-flip technique. O(m*n) time, O(m*n) space.
|
41 |
|
Spiral matrix
Given an m x n integer matrix, return its elements visited in clockwise spiral order starting from the top left. O(m*n) time and space.
|
50 |
|
Maximum sum path in a binary tree
Find the maximum sum path between any two nodes in a binary tree using post-order recursion with a pivot-node technique.
|
56 |
|
List all BST nodes in the range a..b
Given a BST and two integers a and b, return all node values in the inclusive range [a, b] in sorted order using optimized in-order traversal.
|
55 |
|
Find the kth largest node in a binary search tree
Given a BST and integer k, find the kth largest node using in-order traversal. A classic BST problem asked at Twitter and Facebook.
|
56 |
|
Find the kth smallest node in a binary search tree
Given the root of a BST and integer k, find and return the data of the kth smallest node using in-order traversal.
|
53 |
|
Insert a node at the front of the linked list
Given the head of a singly linked list, insert a new node at the front and return the new head. A fundamental O(1) linked list operation.
|
10 |
|
Insert into a binary search tree
Given the root of a BST and an integer n, insert a new node with data n and return the root without modifying existing node positions.
|
50 |
|
List the ancestors of a binary tree node
Given a binary tree and a target node, find all ancestors from closest to farthest using DFS with backtracking.
|
56 |
|
Sum all nodes of a binary tree without recursion
Sum every node in a binary tree using an iterative BFS approach with a queue, no recursion allowed. Walkthrough, complexity, and solutions in 12 languages.
|
31 |
|
Number of half nodes in a binary tree
Given the root of a binary tree, count the number of half nodes - nodes with exactly one child. Solved with a clean recursive approach using XOR.
|
43 |
|
Number of full nodes in a binary tree
Given the root of a binary tree, count the number of full nodes where both left and right children exist. A classic recursion problem asked at Microsoft and LinkedIn.
|
40 |
|
The deepest node of a binary tree
Find the deepest rightmost node of a binary tree using BFS level-order traversal with a queue in O(n) time and O(n) space.
|
43 |
|
Dump binary tree levels as a nested list
Given a binary tree, collect its node values level by level into a nested list using BFS with a queue. O(n) time, O(n) space.
|
50 |
|
Insert a node at the end of a linked list
Write a method to insert a node at the end of a singly linked list and return the head of the modified list.
|
13 |
|
Level order traversal of a binary tree
Given a binary tree root, traverse nodes level by level from left to right using BFS and return their values as a list.
|
42 |
|
Iterative in-order traversal of a binary tree
Learn how to iteratively traverse a binary tree in-order using a stack. Step-by-step walkthrough with visualizations, complexity analysis, and solutions in 14 languages.
|
53 |
|
Delete the nth node of a doubly linked list
Given the head of a doubly linked list, delete the nth node and return the modified list. Uses a sentinel node for clean edge case handling.
|
43 |
|
Insert a node in a doubly linked list at a specific index
Given the head of a doubly linked list, an integer n, and an index i, insert a new node with data n at index i. Return the modified list head.
|
43 |
|
Iteratively find the maximum node of a binary tree
Given the root of a binary tree, find the maximum data value using an iterative BFS approach with a queue. O(n) time and space.
|
40 |
|
Insert a node in a linked list at a specific index
Given the head of a singly linked list, insert a new node with value n at zero-indexed position i. Return the modified list head.
|
40 |
|
Simple stock trading backtesting
Given closing prices over n days, find the maximum profit from unlimited buy-sell transactions. A greedy algorithm problem frequently asked at Facebook and Bloomberg.
|
37 |
|
Find the maximum binary search tree node
Given the root of a binary search tree, find the maximum data value by traversing to the rightmost node in O(log n) time.
|
34 |
|
Insert a node at the head of a doubly linked list
Given the head of a doubly linked list and an integer, insert a new node at the head and return the modified list. O(1) time and space.
|
33 |
|
Return the transpose of a square image
Given a square image as a 2D array, return its transpose by swapping rows and columns. A classic matrix manipulation problem.
|
17 |
|
Linear time Nth Fibonacci number
Compute the Nth Fibonacci number in O(n) time and O(1) space using an iterative sliding window of two variables.
|
32 |
|
Iteratively find a node in a binary tree
Given the root of a binary tree and a target value, iteratively search the tree using BFS to determine if a node with that value exists.
|
30 |
|
Sum all nodes of a binary tree
Given the root of a binary tree, return the sum of all node values using recursion. A clean intro to recursive tree accumulation.
|
29 |
|
Count the leaves of a binary tree
Given the root of a binary tree, count and return the number of leaf nodes. A leaf node has no children. Solved with recursion in O(n) time.
|
30 |
|
Recursive preorder traversal of a binary tree
Given the root of a binary tree, return a list of node values visited in pre-order traversal using recursion.
|
30 |
|
Recursively find the maximum node of a binary tree
Given the root of a binary tree, recursively find and return the maximum data value of any node. Covers DFS, base cases, and O(n) time complexity.
|
30 |
|
Find the size of a binary tree
Given the root of a binary tree, return its size - the total number of nodes it contains. A classic recursion problem frequently asked at Oracle and Cisco.
|
30 |
|
Iterative pre-order traversal of a binary tree
Given the root of a binary tree, return its node values using iterative pre-order traversal with a stack in O(n) time.
|
33 |
|
Better recursive raise to power
Recursively raise a number to a power in O(log n) time without using Math.pow or the ^ operator. Handles negative exponents.
|
28 |
|
Bubble sort an array of integers
Learn how to implement bubble sort, a classic sorting algorithm that repeatedly swaps adjacent elements to sort an array in-place with O(n^2) time and O(1) space.
|
8 |
|
Simple recursive raise to power
Write a recursive method to raise a number to a power without using Math.pow or the ^ operator. Understand the O(n) time and space recursive approach.
|
15 |
|
Palindrome number tester
Check if a given integer is a palindrome using constant space by reversing it digit by digit with modulo and division.
|
30 |
|
Recursively delete the nth node of a linked list
Learn how to recursively delete the nth node from a linked list using a clean recursive approach with O(n) time and O(n) space complexity.
|
28 |
|
Delete the nth node of a linked list
Given the head of a singly linked list, delete the node at the nth index and return the modified list. Handles edge cases like out-of-bounds indices.
|
26 |
|
Simple sorted string compression
Compress a sorted string by replacing consecutive repeated characters with the character and its count. A classic string manipulation interview question.
|
26 |
|
Are these strings anagrams?
Write a method that checks if two strings are anagrams using a character frequency map. O(n) time, O(n) space.
|
12 |
|
Decimal to binary conversion using recursion
Convert a decimal integer to its minimal binary string representation using recursion. A classic problem testing recursive thinking and base conversion.
|
29 |
|
Mutate DNA pairs by inserting G between adjacent duplicates
Given a DNA string, insert a G between every pair of adjacent identical letters using recursion. Walkthrough, complexity analysis, and solutions in 14 languages.
|
29 |
|
Solving the N-Queens puzzle with backtracking
Place n queens on an n x n chessboard so no two attack each other. Learn the backtracking approach with visual walkthroughs.
|
77 |
|
Unique permutation generator
Generate all distinct permutations of an array that may contain duplicates using backtracking with duplicate pruning.
|
47 |
|
Array arrangement variations
Generate all possible permutations of an array of distinct integers using backtracking. A staple at Meta and Bloomberg.
|
42 |
|
Pattern matcher with wildcards
Given a string and a pattern with ? and * wildcards, determine if the pattern matches the entire string using dynamic programming.
|
83 |
|
String-based multiplication
Multiply two non-negative integers represented as strings without converting them to integers. Uses the grade-school multiplication algorithm.
|
47 |
|
Distinct sum combinations
Find all unique combinations from a list of candidates that sum to a target, using each number at most once. A classic backtracking problem.
|
48 |
|
Speak-and-count sequence generation
Generate the nth term of the count-and-say sequence using iterative run-length encoding. A favorite at Apple, Meta, and Akuna Capital.
|
48 |
|
Sudoku puzzle completion challenge
Solve a Sudoku puzzle using backtracking by filling empty cells with digits 1-9 while respecting row, column, and 3x3 sub-grid constraints.
|
77 |
|
Sudoku board integrity check
Validate a partially filled 9x9 Sudoku board by checking rows, columns, and 3x3 sub-boxes for duplicate digits using HashSets.
|
48 |
|
Find first and last position of element in sorted array
Given a sorted array, find the first and last positions of a target value using binary search in O(log n) time.
|
49 |
|
Maximal balanced parentheses length
Find the length of the longest valid, well-formed parentheses substring using a two-pass counter technique in O(n) time and O(1) space.
|
79 |
|
The next permutation of an array
Rearrange an integer array into the lexicographically next greater permutation in-place with O(1) extra memory.
|
57 |
|
Concatenated word sequence indices
Find all starting indices of substrings that are concatenations of all given words using a sliding window and hash map approach.
|
65 |
|
Integer division without standard operators
Divide two integers without using multiplication, division, or modulus. Uses bit shifting for O(log² n) time.
|
54 |
|
Find the first occurrence of a substring
Given two strings needle and haystack, find the index where needle first appears in haystack. Return -1 if not found. O(n*m) brute force solution.
|
25 |
|
Adjacent node swapping in linked lists
Swap every two adjacent nodes in a linked list without modifying values, using a dummy node and pointer manipulation in O(n) time and O(1) space.
|
45 |
|
Find the first non-duplicate character in a string
Given a string, find and return the first character that appears only once. Solve it in O(n) time using a frequency map with insertion order.
|
17 |
|
Merge two sorted linked lists into one
Given two sorted linked lists, merge them into a single sorted list by splicing nodes together. O(n) time, O(1) space using a dummy node.
|
22 |
|
Quadruple sum quartet
Find all unique quadruplets in an array that sum to a target value using sorting and the two-pointer technique in O(n^3) time.
|
48 |
|
Triad sum nearest target
Given an integer array and a target, find three numbers whose sum is closest to the target. Solve it with sorting and two pointers in O(n^2) time.
|
48 |
|
Decimal to Roman conversion
Convert an integer to its Roman numeral representation using a greedy approach with parallel value and symbol arrays.
|
46 |
|
Pattern-driven string matcher with regex support
Implement regex matching with '.' and '*' support using dynamic programming. A classic hard DP problem asked at Google, Amazon, and Microsoft.
|
85 |
|
Numerical symmetry check: Palindrome integer without string conversion
Determine if an integer is a palindrome without converting it to a string. Reverse only half the digits for an O(log n) solution with O(1) space.
|
23 |
|
Zigzag string transformation
Transform a string into a zigzag pattern across N rows, then read it row by row. A classic string manipulation problem asked at Google, Apple, and Amazon.
|
47 |
|
Mirror image of a 2D array
Flip a 2D integer array on its vertical axis to produce its mirror image. A beginner-friendly matrix problem with O(m*n) time.
|
15 |
|
Sum linked lists as reversed integers
Add two numbers represented as reversed linked lists, returning the sum as a new linked list. A classic interview problem at Apple, Google, and Meta.
|
48 |
|
Flip an image on its horizontal axis
Given a 2D array representing a grayscale image, write a method that returns a copy flipped on its horizontal axis. A classic matrix manipulation problem.
|
14 |
|
Delete the tail node of a linked list
Given a singly linked list, write a method to delete its tail node and return the head of the modified list.
|
10 |
|
Split array with equal sum
Determine if an array can be split into two halves with equal sum using recursion and subset sum reduction.
|
68 |
|
Maximum sum sub-array of size k
Given an array of positive integers and an integer k, find the maximum sum of any contiguous sub-array of size k using the sliding window technique.
|
15 |
|
Delete the head node of a linked list
Given a singly linked list, write a method to delete its head node and return the modified list. A simple but essential linked list operation.
|
11 |
|
Intro to graphs: Generate a non-stop flight service adjacency list
Given a list of origin-destination flight pairs, build an adjacency list mapping each origin to its distinct reachable destinations.
|
59 |
|
Intro to graphs: Flight service checker
Given a flight route graph as an adjacency list, determine if you can fly from an origin to a destination via non-stop or connecting flights using BFS.
|
58 |
|
Recover IP addresses from a digit string
Given a string of digits, return all valid IPv4 addresses that can be formed by inserting dots. Uses DFS backtracking with byte validation.
|
74 |
|
Mirrored binary tree tester
Given the roots of two binary trees, write a method to check if they are mirror images of each other using recursion.
|
63 |
|
Maximum sum level of a binary tree
Given the root of a binary tree, find the level with the maximum sum using BFS with two queues. O(n) time and space.
|
58 |
|
Find and replace CSV delimiter
Write a method to find and replace all commas in a CSV string with a provided replacement string. A classic string manipulation warmup for coding interviews.
|
14 |
|
Unique characters in an ASCII string
Determine whether an ASCII string has all unique characters using a HashSet for O(n) time and O(1) space.
|
4 |
|
Valid parentheses
Given a string of brackets, write a method that checks if every opening bracket has a matching closing bracket in the correct order. A classic stack-based interview problem.
|
50 |
|
Subset summation
Given a list of positive integers and a target, determine if any subset sums to the target. A classic recursion and backtracking interview problem.
|
65 |
|
Recursive String Permutations
Given an input string of unique characters, return all permutations of the string using recursion and backtracking. A classic recursion problem testing divide-and-conquer thinking and the insert-at-every-position technique.
|
70 |
|
Find the lowest common ancestor of two binary tree nodes
Given the root of a binary tree and two target node values, find and return the data of the lowest common ancestor. A classic binary tree recursion problem frequently asked at Facebook, Amazon, and Microsoft.
|
67 |
|
Find duplicate numbers
Given an integer array, write a method that identifies and returns all numbers that appear more than once as a sorted array containing each duplicate value exactly once.
|
14 |
|
Happy numbers
Write a method that checks if a given positive integer is a happy number by repeatedly summing the squares of its digits until it reaches 1 or enters a cycle. A classic set-based cycle detection interview problem.
|
45 |
|
Find the diameter of a binary tree
Given the root of a binary tree, find its diameter - the number of nodes on the longest path between any two nodes. A classic tree recursion problem testing depth-first search and height computation.
|
58 |
|
Convert a binary tree to its mirror image
Learn how to convert a binary tree to its mirror image by recursively swapping left and right children at every node. Walkthrough with visualizations and solutions in 14 languages.
|
55 |
|
Identical binary trees
Given the roots of two binary trees, determine if they are identical. Two trees are identical when they share the same shape and the same data at every node. A classic recursion problem testing base cases and tree traversal.
|
52 |
|
Remove duplicate nodes from a linked list
Given the head of a singly linked list, remove all duplicate nodes while keeping the first occurrence of each value. A classic linked list problem testing set-based traversal and pointer manipulation.
|
29 |
|
Array rotation
Rotate an array to the left by k positions in-place using the three-reversal trick. A classic array manipulation interview problem with O(n) time and O(1) space.
|
52 |
|
Palindrome linked list
Check whether a singly linked list is a palindrome using constant space. Learn the slow/fast pointer technique to find the middle, reverse the second half in-place, and compare both halves node by node.
|
50 |
|
Minimum depth of a binary tree
Given the root of a binary tree, find the minimum depth - the smallest number of node traversals from root to the nearest leaf. A classic BFS / level order traversal problem using a two-queue approach.
|
45 |
|
Nth Fibonacci number with recursion
Write a recursive method to return the nth Fibonacci number. A classic recursion problem testing base cases and the Fibonacci recurrence relation.
|
8 |
|
Is power of two?
Write a method to test whether a given positive integer is a power of 2 using bitwise operations, with constant time and space complexity.
|
38 |
|
Binary search
Search a sorted array for a target value using the binary search algorithm. O(log n) time, O(1) space. A foundational divide-and-conquer interview problem.
|
9 |
|
Reverse an integer
Write a method that reverses an input integer using only constant space. A fundamental number manipulation problem that tests your understanding of modular arithmetic and integer division.
|
24 |
|
Merge sorted arrays
Write a method that merges two sorted arrays into a single globally sorted array using a two-pointer approach. A fundamental sorting and array interview problem.
|
27 |
|
Palindrome tester
Write a method that checks if a string reads the same forward and backward, ignoring case. A classic string manipulation interview problem.
|
4 |
|
Max Profit
Given an array of stock prices over n days, find the maximum profit from a single buy-sell transaction. A classic array problem that tests greedy algorithm thinking.
|
25 |
|
Find the middle of a linked list in one pass
Write a method to find and return the data of the middle node of a singly linked list in one pass using the slow and fast pointer technique.
|
18 |
|
Find the unique number in linear time
Given an array that contains duplicates and exactly one unique number, write a method that finds and returns the unique number using a HashMap for O(n) time complexity.
|
11 |
|
Find the average of contiguous sub-arrays of size k
Given an array of integers and an integer k, find the average of all contiguous subarrays of size k using the sliding window technique in O(n) time.
|
20 |
|
Minimum sum path in a triangle
Given an integer triangle as a nested list, find the minimum sum path from the top to the bottom. A classic dynamic programming interview problem solved with bottom-up DP in O(n) space.
|
70 |
|
Reverse a linked list in pairs
Given a singly-linked list, reverse the list in pairs by swapping adjacent nodes two at a time and return the head of the modified list.
|
58 |
|
Insert interval
Given a list of sorted, non-overlapping intervals and a new interval, write a method to insert it into the list such that there is no overlap between them (merge as needed) and the sorted order is maintained.
|
63 |
|
Generate combinations of parentheses
Given n pairs of parentheses, generate all valid combinations using recursive backtracking. A classic recursion problem frequently asked at Amazon, Google, and Facebook.
|
54 |
|
Maximal Ascending Sequence Length
Find the length of the longest strictly increasing subsequence using binary search and patience sorting. O(n log n) time, O(n) space, with step-by-step walkthrough.
|
49 |
|
Two Sum
Given an array of integers and a target, find indices of two numbers that add up to the target using a hash map in O(n) time.
|
31 |
|
Anagram Checker: verify two strings share the same letters
Learn to check if two strings are anagrams using character frequency counting. Walkthrough with visualizations and solutions in 14 languages.
|
23 |
|
Array Multiplicative Exclusion
Build an output array where each element is the product of every other element, without using division. O(n) time using prefix and suffix products.
|
45 |
|
Binary Search Tree Lowest Common Ancestor Finder
Find the lowest common ancestor of two nodes in a BST using its ordering property. O(h) time, O(1) space.
|
66 |
|
Kth Minimal Node in a Binary Search Tree
Given the root of a binary search tree and an integer k, find and return the kth smallest value among all the node values in the tree. The indexing is 1-based.
|
45 |
|
Frequent Element Finder
Given an array of integers with length n, identify all elements that occur more than n/3 times. Solve it in O(n) time and O(1) space using the extended Boyer-Moore Voting Algorithm.
|
49 |
|
Course Completion Feasibility: detect cycles in prerequisite graphs
Determine if all courses can be completed given prerequisites. DFS cycle detection in O(V+E) time using three-state coloring.
|
53 |
|
Street Safe Heist Strategy: maximize loot without robbing neighbors
Maximize the sum of non-adjacent elements using space-optimized DP. O(n) time, O(1) space walkthrough of the House Robber problem.
|
47 |
|
Counting Set Bits in Binary Representation
Given a positive integer n, create a function to determine how many set bits (1s) are present in its binary form, also referred to as the Hamming weight.
|
23 |
|
Find Pair Indices in Sorted Array
Find two numbers in a sorted array that sum to a target using the two-pointer technique. O(n) time, O(1) space.
|
32 |
|
Locate Lowest Element in a Rotated Array
Find the minimum element in a rotated sorted array using binary search. O(log n) time, O(1) space, with step-by-step walkthrough and solutions in 14 languages.
|
48 |
|
Highest Product of Subarray
Find the contiguous subarray with the highest product using a max/min tracking algorithm. O(n) time, O(1) space, with step-by-step walkthrough and negative number handling.
|
48 |
|
Sentence Formation with Word Dictionary
Find all possible ways to segment a string into valid dictionary words using backtracking with memoization.
|
83 |
|
Unique Lone Integer: find the number that appears only once
Learn to find the single number in an array where every other element appears twice, using XOR bit manipulation. Walkthrough with visualizations and solutions in 14 languages.
|
18 |
|
ASCII Palindrome Checker
Determine if a string is a palindrome after removing non-alphanumeric characters and ignoring case. Two-pointer O(n) time, O(1) space solution.
|
23 |
|
Optimal Path Sum in Binary Trees
Given the root of a binary tree, determine and return the highest possible path sum for any path that contains at least one node. A path consists of a sequence of nodes where each pair of consecutive nodes is connected by an edge, and no node appears more than once.
|
82 |
|
Root-to-Leaf Target Path Sum: find if any path sums to a target
Given a binary tree and a target sum, determine if any root-to-leaf path sums to the target. Recursive DFS solution in O(n) time and O(h) space.
|
40 |
|
Max Depth of Binary Tree
Given the root of a binary tree, determine its maximum depth. The maximum depth of a binary tree is defined as the number of nodes along the longest path from the root node to the most distant leaf node.
|
23 |
|
Tree Structure Equality Check - How to Compare Two Binary Trees
Determine if two binary trees are identical by comparing structure and node values using recursive DFS. O(n) time, O(n) space.
|
35 |
|
Grid Word Hunt
Given an m x n character grid and a target word, determine if the word exists by connecting adjacent cells using DFS with backtracking in O(m * n * 4^k) time.
|
49 |
|
Power Set Exploration
Generate all possible subsets (the power set) of a unique integer array using backtracking and bit manipulation. O(2^n) time and space, with full recursion tree walkthrough and solutions in 14 languages.
|
45 |
|
Color Segregation Challenge
Sort an array of 0s, 1s, and 2s in-place using the Dutch National Flag algorithm. O(n) time, O(1) space. Full walkthrough with solutions in 14 languages.
|
47 |
|
Zero Out Rows and Columns
Given an m x n matrix, if any element is 0, set its entire row and column to 0 in place. Solve it in O(1) space by using the first row and column as markers.
|
47 |
|
String Transformation Cost - Minimum Edit Distance with Dynamic Programming
Master the edit distance problem using 2D dynamic programming. Learn to compute the minimum insert, delete, and replace operations to transform one string into another.
|
82 |
|
Step combinations to reach the summit
Find the number of distinct ways to climb n stairs taking 1 or 2 steps at a time using Fibonacci-like dynamic programming.
|
22 |
|
Combining Overlapping Ranges: merge intervals with sorting
Learn to merge overlapping intervals by sorting and scanning. Step-by-step walkthrough with visualizations and solutions in 14 languages.
|
47 |
|
Leap to the Finish Line: can you reach the last index?
Determine if you can reach the last array index using a greedy maxReach approach. O(n) time, O(1) space walkthrough.
|
48 |
|
Matrix Spiral Traversal
Given an m x n matrix, return all elements in spiral order using four boundary pointers. O(m*n) time, O(m*n) space for the output.
|
48 |
|
Subarray with Maximum Total: Kadane's algorithm explained
Find the contiguous subarray with the largest sum using Kadane's algorithm. O(n) time, O(1) space, with step-by-step walkthrough.
|
49 |
|
Anagram clustering challenge
Group an array of strings so that anagrams appear together using sorted keys and a hash map in O(n * k log k) time.
|
45 |
|
Image Matrix 90-Degree Twist
Rotate an n x n matrix 90 degrees clockwise in-place using the transpose-then-reverse technique. O(n^2) time, O(1) space.
|
45 |
|
Sum Combinations with Repeats
Given an array of unique integers and a target, find all unique combinations that sum to the target. Each number can be reused unlimited times. Solved with backtracking in O(2^target) time.
|
47 |
|
Insertion Index Finder
Given a sorted array of unique integers and a target value, find the index of the target or the position where it should be inserted. O(log n) binary search solution with step-by-step walkthrough and solutions in 14 languages.
|
33 |
|
Pivoted Array Target Search: Binary search in a rotated sorted array
Search for a target in a rotated sorted array using modified binary search. O(log n) time, O(1) space, with step-by-step walkthrough.
|
58 |
|
Combine Multiple Sorted Linked Lists Using a Min-Heap
Learn two approaches to merge k sorted linked lists: min-heap for O(N log k) efficiency and divide-and-conquer for elegant recursion. Complete solutions in 14 languages.
|
82 |
|
Bracket Harmony Check: validate nested brackets with a stack
Learn to validate matching brackets using a stack. Step-by-step walkthrough of the Valid Parentheses problem with visualizations and solutions in 14 languages.
|
22 |
|
Eliminate Node from Tail of Linked List
Given the head of a linked list, remove the nth node from the end and return its head. Solved with the two-pointer technique in O(n) time and O(1) space.
|
48 |
|
Phone Keypad Letter Combinations
Given a string of digits from 2-9, generate all possible letter combinations using backtracking. A classic interview problem at Google, Amazon, Apple, and Meta.
|
45 |
|
Zero-Sum Triplet Finder
Find all unique triplets in an array that sum to zero using sort and two pointers in O(n^2) time.
|
47 |
|
Shared Prefix Finder
Find the longest common prefix shared by an array of strings using the horizontal scanning approach. O(n * m) time, O(1) space.
|
23 |
|
Roman Numeral Conversion to Decimal
Convert a Roman numeral string to its integer value using a hash map and right-to-left traversal with subtraction rule detection. O(n) time, O(1) space.
|
22 |
|
Maximize Water Storage Between Lines
Find two lines that hold the most water using the two-pointer technique in O(n) time and O(1) space.
|
48 |
|
Digit Reversal with Overflow Guard
Reverse the digits of a signed 32-bit integer, returning 0 if the result overflows. O(log n) time, O(1) space.
|
48 |
|
Maximal Symmetric Substring
Given a string s, find and return the longest palindromic substring within s using the expand-around-center technique in O(n^2) time and O(1) space.
|
48 |
|
Central Median from Dual Sorted Lists
Find the median of two sorted arrays in O(log(min(m,n))) time using binary search partitioning. A classic hard problem tested at Google, Amazon, and Uber.
|
83 |
|
Number of islands
Given an m x n grid of 1s (land) and 0s (water), count the number of islands using DFS flood fill in O(m*n) time and space.
|
61 |
|
Longest substring without repeated characters
Given a string, find the length of the longest substring without repeated characters using the sliding window technique. O(n) time, O(n) space.
|
67 |
|
Bottom-up level order binary tree traversal
Traverse a binary tree bottom-up, level by level, returning node values from the deepest level to the root. Uses BFS with a queue and a final reversal for O(n) time and O(n) space.
|
59 |
|
Count paths on a board
Calculate the number of unique paths from top-left to bottom-right in an m×n grid, moving only right or down.
|
45 |
|
Wildcard Parenthesis Validator
Master the art of validating parentheses with wildcards - a favorite interview problem at Amazon, Microsoft, and Apple that tests your greedy algorithm skills.
|
60 |
|
Post-Bigram Word Finder
Find all words that appear immediately after a specific two-word sequence in a string - a classic string parsing challenge.
|
18 |
|
Reverse a linked list
Given the head of a singly linked list, write a method that reverses the list and returns its new head.
|
35 |
|
Find the minimum node in a binary search tree
Given the root of a binary search tree, find and return the minimum data value by traversing to the leftmost node using recursion.
|
34 |
|
Height of a binary tree
Given the root TreeNode of a binary tree, write a method return its height. An empty tree has a height of 0 while a single node tree has a height of 1.
|
32 |