Coding interview problems

In-depth walkthroughs of coding interview problems from top tech companies

Back to the blog
176 problems
Problem Difficulty
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.
Expert
String permutations and combinations
Given a string of unique characters, return all permutations of all combinations. Solve it with recursion and backtracking.
Hard
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.
Challenging
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.
Challenging
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.
Hard
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.
Hard
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.
Beginner
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.
Hard
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.
Challenging
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.
Challenging
Binary tree decompression
Given a compressed, serialized binary tree string, decompress and reconstruct the original tree using level-order traversal with a queue.
Challenging
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.
Challenging
Introduction to Tries - Inserting Words
Learn how to implement a Trie data structure by building the insert method. Step-by-step walkthrough with visualizations.
Challenging
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.
Challenging
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.
Challenging
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.
Regular
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.
Challenging
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.
Regular
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.
Regular
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.
Challenging
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.
Challenging
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.
Challenging
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.
Challenging
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.
Challenging
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.
Warmup
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.
Challenging
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.
Challenging
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.
Easy
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.
Regular
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.
Regular
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.
Regular
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.
Challenging
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.
Beginner
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.
Regular
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.
Challenging
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.
Regular
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.
Regular
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.
Regular
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.
Regular
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.
Easy
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.
Easy
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.
Easy
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.
Beginner
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Warmup
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.
Beginner
Palindrome number tester
Check if a given integer is a palindrome using constant space by reversing it digit by digit with modulo and division.
Easy
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.
Easy
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.
Easy
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.
Easy
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.
Warmup
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.
Easy
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.
Easy
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.
Expert
Unique permutation generator
Generate all distinct permutations of an array that may contain duplicates using backtracking with duplicate pruning.
Regular
Array arrangement variations
Generate all possible permutations of an array of distinct integers using backtracking. A staple at Meta and Bloomberg.
Regular
Pattern matcher with wildcards
Given a string and a pattern with ? and * wildcards, determine if the pattern matches the entire string using dynamic programming.
Expert
String-based multiplication
Multiply two non-negative integers represented as strings without converting them to integers. Uses the grade-school multiplication algorithm.
Regular
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.
Regular
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.
Regular
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.
Expert
Sudoku board integrity check
Validate a partially filled 9x9 Sudoku board by checking rows, columns, and 3x3 sub-boxes for duplicate digits using HashSets.
Regular
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.
Regular
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.
Expert
The next permutation of an array
Rearrange an integer array into the lexicographically next greater permutation in-place with O(1) extra memory.
Challenging
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.
Hard
Integer division without standard operators
Divide two integers without using multiplication, division, or modulus. Uses bit shifting for O(log² n) time.
Challenging
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.
Easy
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.
Regular
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.
Beginner
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.
Beginner
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.
Regular
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.
Regular
Decimal to Roman conversion
Convert an integer to its Roman numeral representation using a greedy approach with parallel value and symbol arrays.
Regular
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.
Expert
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.
Beginner
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.
Regular
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.
Beginner
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.
Regular
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.
Beginner
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.
Warmup
Split array with equal sum
Determine if an array can be split into two halves with equal sum using recursion and subset sum reduction.
Hard
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.
Beginner
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.
Warmup
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.
Challenging
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.
Challenging
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.
Hard
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.
Hard
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.
Challenging
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.
Beginner
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.
Warmup
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.
Challenging
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.
Hard
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.
Hard
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.
Hard
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.
Beginner
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.
Regular
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.
Challenging
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.
Challenging
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.
Challenging
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.
Easy
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.
Challenging
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.
Challenging
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.
Regular
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.
Warmup
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.
Regular
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.
Warmup
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.
Beginner
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.
Easy
Palindrome tester
Write a method that checks if a string reads the same forward and backward, ignoring case. A classic string manipulation interview problem.
Warmup
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.
Easy
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.
Beginner
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.
Warmup
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.
Beginner
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.
Hard
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.
Challenging
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.
Hard
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.
Challenging
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.
Regular
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.
Easy
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.
Beginner
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.
Regular
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.
Hard
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.
Regular
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.
Challenging
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.
Regular
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.
Beginner
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.
Easy
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.
Regular
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.
Regular
Sentence Formation with Word Dictionary
Find all possible ways to segment a string into valid dictionary words using backtracking with memoization.
Expert
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.
Beginner
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.
Beginner
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.
Regular
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.
Beginner
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.
Easy
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.
Regular
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.
Regular
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.
Regular
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.
Regular
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.
Expert
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.
Beginner
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.
Regular
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.
Regular
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.
Regular
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.
Regular
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.
Regular
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.
Easy
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.
Challenging
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.
Expert
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.
Regular
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.
Regular
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.
Regular
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.
Beginner
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.
Beginner
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.
Regular
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.
Regular
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.
Regular
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.
Expert
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.
Challenging
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.
Hard
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.
Challenging
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.
Regular
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.
Challenging
Post-Bigram Word Finder
Find all words that appear immediately after a specific two-word sequence in a string - a classic string parsing challenge.
Beginner
Reverse a linked list
Given the head of a singly linked list, write a method that reverses the list and returns its new head.
Easy
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.
Easy
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.
Easy