Top 50 Coding Interview Questions with Solutions and Patterns (2026)
Preparing for coding interview questions can feel overwhelming when you face thousands of problems across dozens of platforms. The key to efficient preparation is not solving every problem ever written but recognizing the patterns that appear repeatedly. This curated list of 50 essential coding interview questions is organized by pattern and topic so you can build systematic problem-solving skills that transfer across any question an interviewer throws at you.
Whether you are preparing for Google, Meta, Amazon, or a fast-growing startup, these problems represent the core concepts tested in technical interviews. For a deeper dive into each pattern, see our algorithm patterns interview guide.
How to Use This Coding Interview Questions List
Each question below includes the problem category, a brief description, the recommended approach, time complexity, and difficulty level. Rather than providing full code solutions, we focus on pattern identification and approach hints. Work through problems in order within each section, as they build on each other.
Array and String Problems
1. Two Sum
Difficulty: Easy | Pattern: Hash Map
Given an array of integers and a target, find two numbers that add up to the target. Use a hash map to store complements as you iterate.
Time: O(n) | Space: O(n)
2. Best Time to Buy and Sell Stock
Difficulty: Easy | Pattern: Sliding Window / Greedy
Track the minimum price seen so far and calculate the maximum profit at each step.
Time: O(n) | Space: O(1)
3. Contains Duplicate
Difficulty: Easy | Pattern: Hash Set
Use a set to track seen elements. If an element already exists in the set, return true.
Time: O(n) | Space: O(n)
4. Maximum Subarray (Kadane's Algorithm)
Difficulty: Medium | Pattern: Dynamic Programming / Greedy
Maintain a running sum and reset it when it drops below zero. Track the maximum sum seen at any point.
Time: O(n) | Space: O(1)
5. Product of Array Except Self
Difficulty: Medium | Pattern: Prefix/Suffix
Build prefix products from the left and suffix products from the right. Multiply them together for each index.
Time: O(n) | Space: O(n)
6. Three Sum
Difficulty: Medium | Pattern: Two Pointers
Sort the array, fix one element, then use two pointers on the remaining portion. Skip duplicates carefully.
Time: O(n^2) | Space: O(1) excluding output
7. Container With Most Water
Difficulty: Medium | Pattern: Two Pointers
Start with pointers at both ends. Move the pointer at the shorter line inward.
Time: O(n) | Space: O(1)
8. Longest Substring Without Repeating Characters
Difficulty: Medium | Pattern: Sliding Window
Maintain a window with a hash set tracking characters. Expand right and shrink from left when a duplicate is found.
Time: O(n) | Space: O(min(m, n))
9. Minimum Window Substring
Difficulty: Hard | Pattern: Sliding Window
Use two frequency maps and a sliding window. Expand right to include all target characters, then shrink left to find the minimum window.
Time: O(n) | Space: O(m)
For a complete reference on when to use each data structure, consult our data structures interview cheat sheet.
Linked List Problems
10. Reverse Linked List
Difficulty: Easy | Pattern: Iterative
Use three pointers (previous, current, next) to reverse links one node at a time.
Time: O(n) | Space: O(1)
11. Merge Two Sorted Lists
Difficulty: Easy | Pattern: Two Pointers
Compare heads of both lists and attach the smaller node to the merged list.
Time: O(n + m) | Space: O(1)
12. Linked List Cycle Detection
Difficulty: Easy | Pattern: Fast and Slow Pointers
Use Floyd's cycle detection with one pointer moving by one step and another by two.
Time: O(n) | Space: O(1)
13. Remove Nth Node From End
Difficulty: Medium | Pattern: Two Pointers
Use two pointers separated by n nodes. When the fast pointer reaches the end, the slow pointer is at the target.
Time: O(n) | Space: O(1)
14. Merge K Sorted Lists
Difficulty: Hard | Pattern: Heap / Divide and Conquer
Use a min-heap to always pick the smallest head across all lists.
Time: O(N log k) | Space: O(k)
Tree Problems
15. Maximum Depth of Binary Tree
Difficulty: Easy | Pattern: DFS Recursion
Recursively compute the depth of left and right subtrees and return the maximum plus one.
Time: O(n) | Space: O(h)
16. Invert Binary Tree
Difficulty: Easy | Pattern: DFS Recursion
Swap left and right children at each node recursively.
Time: O(n) | Space: O(h)
17. Validate Binary Search Tree
Difficulty: Medium | Pattern: DFS with Range
Pass valid value ranges down the recursion. Track min and max bounds at each node.
Time: O(n) | Space: O(h)
18. Binary Tree Level Order Traversal
Difficulty: Medium | Pattern: BFS
Use a queue to process nodes level by level.
Time: O(n) | Space: O(n)
19. Lowest Common Ancestor
Difficulty: Medium | Pattern: DFS Recursion
If the current node matches either target, return it. If both subtrees return non-null, the current node is the LCA.
Time: O(n) | Space: O(h)
20. Serialize and Deserialize Binary Tree
Difficulty: Hard | Pattern: BFS or Preorder DFS
Use preorder traversal with null markers to serialize. Deserialize by reading values in the same order.
Time: O(n) | Space: O(n)
Graph Problems
21. Number of Islands
Difficulty: Medium | Pattern: BFS/DFS Grid Traversal
When you find land, increment the count and use DFS/BFS to mark all connected land as visited.
Time: O(m * n) | Space: O(m * n)
22. Clone Graph
Difficulty: Medium | Pattern: BFS/DFS with Hash Map
Use a hash map to track original-to-clone mappings during traversal.
Time: O(V + E) | Space: O(V)
23. Course Schedule
Difficulty: Medium | Pattern: Topological Sort / DFS
Model courses as a directed graph. Detect cycles using DFS with three states or Kahn's algorithm.
Time: O(V + E) | Space: O(V + E)
24. Word Ladder
Difficulty: Hard | Pattern: BFS
Treat each word as a node with edges to words differing by one character. BFS gives the shortest transformation.
Time: O(M^2 * N) | Space: O(M^2 * N)
25. Alien Dictionary
Difficulty: Hard | Pattern: Topological Sort
Compare adjacent words to extract ordering rules, build a graph, and perform topological sort.
Time: O(C) total characters | Space: O(1) for fixed alphabet
Dynamic Programming Problems
26. Climbing Stairs
Difficulty: Easy | Pattern: Fibonacci-style DP
Ways to reach step n equals sum of ways to reach n-1 and n-2. Use O(1) space with two variables.
Time: O(n) | Space: O(1)
27. House Robber
Difficulty: Medium | Pattern: Linear DP
At each house, choose max of robbing it plus two houses back, or skipping it.
Time: O(n) | Space: O(1)
28. Coin Change
Difficulty: Medium | Pattern: Unbounded Knapsack
Build up solutions for each amount from 1 to target. For each amount, try every denomination.
Time: O(amount * coins) | Space: O(amount)
29. Longest Increasing Subsequence
Difficulty: Medium | Pattern: Patience Sorting / DP
Maintain a tails array and use binary search to place each element for O(n log n).
Time: O(n log n) | Space: O(n)
30. Word Break
Difficulty: Medium | Pattern: DP with Hash Set
Use a boolean DP array where dp[i] indicates whether substring 0 to i can be segmented.
Time: O(n^2 * m) | Space: O(n)
31. Edit Distance
Difficulty: Medium | Pattern: 2D DP
Build a matrix comparing both strings. At each cell, choose minimum of insert, delete, or replace.
Time: O(m * n) | Space: O(m * n)
Stack and Queue Problems
32. Valid Parentheses
Difficulty: Easy | Pattern: Stack
Push opening brackets, check top for matching pair on closing brackets.
Time: O(n) | Space: O(n)
33. Min Stack
Difficulty: Medium | Pattern: Auxiliary Stack
Maintain a secondary stack tracking the current minimum.
Time: O(1) all operations | Space: O(n)
34. Daily Temperatures
Difficulty: Medium | Pattern: Monotonic Stack
Use a decreasing monotonic stack storing indices. Pop and calculate distance when warmer temperature found.
Time: O(n) | Space: O(n)
35. Largest Rectangle in Histogram
Difficulty: Hard | Pattern: Monotonic Stack
Maintain an increasing stack of bar indices. Calculate areas when a shorter bar is encountered.
Time: O(n) | Space: O(n)
Binary Search Problems
36. Search in Rotated Sorted Array
Difficulty: Medium | Pattern: Modified Binary Search
Determine which half is sorted, check if target falls in sorted range, adjust boundaries.
Time: O(log n) | Space: O(1)
37. Find Minimum in Rotated Sorted Array
Difficulty: Medium | Pattern: Binary Search
Compare middle with rightmost element to determine which half contains the minimum.
Time: O(log n) | Space: O(1)
38. Median of Two Sorted Arrays
Difficulty: Hard | Pattern: Binary Search on Partition
Binary search on the smaller array to find the correct partition point.
Time: O(log(min(m, n))) | Space: O(1)
Heap and Priority Queue Problems
39. Kth Largest Element
Difficulty: Medium | Pattern: Min Heap / Quickselect
Maintain a min heap of size k. After processing all elements, the root is the kth largest.
Time: O(n log k) | Space: O(k)
40. Top K Frequent Elements
Difficulty: Medium | Pattern: Heap / Bucket Sort
Count frequencies with hash map, then use min heap of size k or bucket sort.
Time: O(n log k) | Space: O(n)
41. Find Median from Data Stream
Difficulty: Hard | Pattern: Two Heaps
Max heap for lower half, min heap for upper half. Balance sizes so median is always accessible.
Time: O(log n) per insert | Space: O(n)
Backtracking Problems
42. Subsets
Difficulty: Medium | Pattern: Backtracking
At each element, choose to include or exclude it. Recursively build all combinations.
Time: O(n * 2^n) | Space: O(n)
43. Permutations
Difficulty: Medium | Pattern: Backtracking
Swap elements into position and recurse to generate all orderings.
Time: O(n * n!) | Space: O(n)
44. Combination Sum
Difficulty: Medium | Pattern: Backtracking with Pruning
Sort candidates and use backtracking, allowing repeated use of the same element. Prune negative branches.
Time: O(N^(T/M)) | Space: O(T/M)
45. N-Queens
Difficulty: Hard | Pattern: Backtracking with Constraint Checking
Place queens row by row. Use sets to track occupied columns and diagonals.
Time: O(n!) | Space: O(n)
Trie and Advanced Problems
46. Implement Trie
Difficulty: Medium | Pattern: Trie Construction
Build a tree where each node has up to 26 children. Mark end-of-word nodes.
Time: O(m) per operation | Space: O(alphabet * total characters)
47. Word Search II
Difficulty: Hard | Pattern: Trie + Backtracking
Build a trie from word list, then DFS from each grid cell using trie for pruning.
Time: O(m * n * 4^L) | Space: O(total characters)
48. LRU Cache
Difficulty: Medium | Pattern: Hash Map + Doubly Linked List
Combine hash map for O(1) lookup with doubly linked list for O(1) insertion and removal.
Time: O(1) for get and put | Space: O(capacity)
49. Trapping Rain Water
Difficulty: Hard | Pattern: Two Pointers / Stack
Two pointers from both ends, tracking max height from each side. Water equals min of two maxes minus current height.
Time: O(n) | Space: O(1)
50. Longest Valid Parentheses
Difficulty: Hard | Pattern: Stack / DP
Stack storing indices of unmatched brackets. Calculate lengths from index differences.
Time: O(n) | Space: O(n)
Pattern Recognition Strategy
- Sorted array or search space: Think binary search
- Finding pairs or triplets: Think two pointers after sorting
- Substring or subarray with constraint: Think sliding window
- Making optimal choices at each step: Think greedy or dynamic programming
- Exploring all possibilities: Think backtracking
- Processing in order: Think stack or queue
- Finding shortest path: Think BFS
- Detecting cycles or connected components: Think DFS or Union-Find
- Top-K or streaming data: Think heap
- Prefix matching or autocomplete: Think trie
For structured preparation using these patterns, follow our LeetCode preparation guide. Ready to land interviews? Build a standout software engineer resume with EasyResume.