Back to Blog

Top 100 Coding Interview Questions with Solutions (2026)

Master the most frequently asked coding interview questions with clear explanations, optimized solutions, and step-by-step approaches. Perfect for placement prep, coding rounds, and TEC- interview

Priyanshu Mishra
Priyanshu Mishra
9 July 202614 min read38 views
Top 100 Coding Interview Questions with Solutions (2026)

Introduction

Landing a software engineering job at a top tech company — whether it's a FAANG giant or a fast-growing startup — almost always means clearing a coding interview round. These interviews test your grasp of data structures, algorithms, problem-solving speed, and code quality under pressure.

This guide compiles the top 100 coding interview questions, organised into 10 core topics that recruiters and hiring managers consistently test. For each category, you'll find detailed, worked solutions for the most frequently asked problems, plus a full checklist of the remaining questions so you can practice systematically.

Whether you're preparing for interviews at Google, Amazon, Microsoft, or a product-based startup, this list covers everything from arrays and strings to dynamic programming and system-level coding problems.


Table of Contents

  1. Arrays & Strings (Q1–15)
  2. Linked Lists (Q16–25)
  3. Stacks & Queues (Q26–33)
  4. Trees & Binary Search Trees (Q34–45)
  5. Graphs (Q46–55)
  6. Dynamic Programming (Q56–68)
  7. Sorting & Searching (Q69–78)
  8. Recursion & Backtracking (Q79–87)
  9. Hashing & Two Pointers (Q88–95)
  10. Miscellaneous / System-Level (Q96–100)

Why These Questions Matter

Coding interviews aren't just about memorizing solutions — interviewers want to see how you think, communicate, and optimize. That said, pattern recognition is 80% of the battle. Once you've solved a "two-pointer" or "sliding window" problem a few times, you'll recognize the pattern instantly in a new context. That's exactly what this list is built to train.


1. Arrays & Strings

Q1. Two Sum

Problem: Given an array of integers and a target, return indices of two numbers that add up to the target.

python

python
def two_sum(nums, target):
    seen = {}
    for i, num in enumerate(nums):
        complement = target - num
        if complement in seen:
            return [seen[complement], i]
        seen[num] = i
    return []

Time Complexity: O(n) | Space: O(n)


Q2. Best Time to Buy and Sell Stock

Problem: Find the maximum profit from a single buy/sell transaction.

python

python
def max_profit(prices):
    min_price = float('inf')
    max_profit = 0
    for price in prices:
        min_price = min(min_price, price)
        max_profit = max(max_profit, price - min_price)
    return max_profit

Time Complexity: O(n) | Space: O(1)


Q3. Maximum Subarray (Kadane's Algorithm)

python

python
def max_subarray(nums):
    max_sum = current_sum = nums[0]
    for num in nums[1:]:
        current_sum = max(num, current_sum + num)
        max_sum = max(max_sum, current_sum)
    return max_sum

Time Complexity: O(n) | Space: O(1)


Q4. Valid Anagram

python

python
def is_anagram(s, t):
    if len(s) != len(t):
        return False
    return sorted(s) == sorted(t)

Time Complexity: O(n log n)


Q5. Longest Substring Without Repeating Characters

python

python
def length_of_longest_substring(s):
    seen = {}
    left = max_len = 0
    for right, char in enumerate(s):
        if char in seen and seen[char] >= left:
            left = seen[char] + 1
        seen[char] = right
        max_len = max(max_len, right - left + 1)
    return max_len

Time Complexity: O(n)


Q6. Product of Array Except Self

python

python
def product_except_self(nums):
    n = len(nums)
    res = [1] * n
    left = 1
    for i in range(n):
        res[i] = left
        left *= nums[i]
    right = 1
    for i in range(n - 1, -1, -1):
        res[i] *= right
        right *= nums[i]
    return res

Time Complexity: O(n) | Space: O(1) excluding output


Q7. Container With Most Water

python

python
def max_area(height):
    left, right = 0, len(height) - 1
    max_water = 0
    while left < right:
        h = min(height[left], height[right])
        max_water = max(max_water, h * (right - left))
        if height[left] < height[right]:
            left += 1
        else:
            right -= 1
    return max_water

Time Complexity: O(n)


Q8–Q15 (Practice List)

  • Q8. Merge Intervals
  • Q9. Rotate Array
  • Q10. Group Anagrams
  • Q11. Longest Palindromic Substring
  • Q12. Trapping Rain Water
  • Q13. Move Zeroes
  • Q14. Find the Duplicate Number
  • Q15. String to Integer (atoi)

2. Linked Lists

Q16. Reverse a Linked List

python

python
def reverse_list(head):
    prev = None
    while head:
        next_node = head.next
        head.next = prev
        prev = head
        head = next_node
    return prev

Time Complexity: O(n)


Q17. Detect Cycle in a Linked List (Floyd's Algorithm)

python

python
def has_cycle(head):
    slow = fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
        if slow == fast:
            return True
    return False

Time Complexity: O(n) | Space: O(1)


Q18. Merge Two Sorted Lists

python

python
def merge_two_lists(l1, l2):
    dummy = curr = ListNode()
    while l1 and l2:
        if l1.val <= l2.val:
            curr.next, l1 = l1, l1.next
        else:
            curr.next, l2 = l2, l2.next
        curr = curr.next
    curr.next = l1 or l2
    return dummy.next

Q19–Q25 (Practice List)

  • Q19. Remove Nth Node From End of List
  • Q20. Add Two Numbers (Linked List Representation)
  • Q21. Palindrome Linked List
  • Q22. Intersection of Two Linked Lists
  • Q23. Flatten a Multilevel Doubly Linked List
  • Q24. Copy List with Random Pointer
  • Q25. Reorder List

3. Stacks & Queues

Q26. Valid Parentheses

python

python
def is_valid(s):
    stack = []
    pairs = {')': '(', ']': '[', '}': '{'}
    for char in s:
        if char in pairs:
            if not stack or stack.pop() != pairs[char]:
                return False
        else:
            stack.append(char)
    return not stack

Time Complexity: O(n)


Q27. Implement Queue Using Stacks

python

python
class MyQueue:
    def __init__(self):
        self.in_stack, self.out_stack = [], []

    def push(self, x):
        self.in_stack.append(x)

    def pop(self):
        self.peek()
        return self.out_stack.pop()

    def peek(self):
        if not self.out_stack:
            while self.in_stack:
                self.out_stack.append(self.in_stack.pop())
        return self.out_stack[-1]

Q28–Q33 (Practice List)

  • Q28. Min Stack
  • Q29. Daily Temperatures
  • Q30. Next Greater Element
  • Q31. Sliding Window Maximum
  • Q32. Evaluate Reverse Polish Notation
  • Q33. Implement Stack Using Queues

4. Trees & Binary Search Trees

Q34. Maximum Depth of Binary Tree

python

python
def max_depth(root):
    if not root:
        return 0
    return 1 + max(max_depth(root.left), max_depth(root.right))

Q35. Validate Binary Search Tree

python

python
def is_valid_bst(root, low=float('-inf'), high=float('inf')):
    if not root:
        return True
    if not (low < root.val < high):
        return False
    return (is_valid_bst(root.left, low, root.val) and
            is_valid_bst(root.right, root.val, high))

Q36. Lowest Common Ancestor of a BST

python

python
def lowest_common_ancestor(root, p, q):
    while root:
        if p.val < root.val and q.val < root.val:
            root = root.left
        elif p.val > root.val and q.val > root.val:
            root = root.right
        else:
            return root

Q37. Level Order Traversal (BFS)

python

python
from collections import deque

def level_order(root):
    if not root:
        return []
    result, queue = [], deque([root])
    while queue:
        level = []
        for _ in range(len(queue)):
            node = queue.popleft()
            level.append(node.val)
            if node.left: queue.append(node.left)
            if node.right: queue.append(node.right)
        result.append(level)
    return result

Q38–Q45 (Practice List)

  • Q38. Invert a Binary Tree
  • Q39. Diameter of Binary Tree
  • Q40. Serialize and Deserialize a Binary Tree
  • Q41. Binary Tree Right Side View
  • Q42. Construct Binary Tree from Preorder and Inorder Traversal
  • Q43. Kth Smallest Element in a BST
  • Q44. Balanced Binary Tree Check
  • Q45. Path Sum II

5. Graphs

Q46. Number of Islands

python

python
def num_islands(grid):
    if not grid:
        return 0
    rows, cols = len(grid), len(grid[0])

    def dfs(r, c):
        if r < 0 or c < 0 or r >= rows or c >= cols or grid[r][c] != '1':
            return
        grid[r][c] = '0'
        dfs(r+1, c); dfs(r-1, c); dfs(r, c+1); dfs(r, c-1)

    count = 0
    for r in range(rows):
        for c in range(cols):
            if grid[r][c] == '1':
                dfs(r, c)
                count += 1
    return count

Time Complexity: O(rows × cols)


Q47. Clone Graph

python

python
def clone_graph(node, visited={}):
    if not node:
        return None
    if node in visited:
        return visited[node]
    copy = Node(node.val)
    visited[node] = copy
    for neighbor in node.neighbors:
        copy.neighbors.append(clone_graph(neighbor, visited))
    return copy

Q48. Course Schedule (Topological Sort / Cycle Detection)

python

python
def can_finish(num_courses, prerequisites):
    graph = {i: [] for i in range(num_courses)}
    for course, pre in prerequisites:
        graph[course].append(pre)

    visited = [0] * num_courses  # 0=unvisited, 1=visiting, 2=visited

    def has_cycle(course):
        if visited[course] == 1:
            return True
        if visited[course] == 2:
            return False
        visited[course] = 1
        for pre in graph[course]:
            if has_cycle(pre):
                return True
        visited[course] = 2
        return False

    return not any(has_cycle(c) for c in range(num_courses))

Q49–Q55 (Practice List)

  • Q49. Word Ladder
  • Q50. Pacific Atlantic Water Flow
  • Q51. Dijkstra's Shortest Path
  • Q52. Union-Find / Number of Connected Components
  • Q53. Graph Valid Tree
  • Q54. Minimum Spanning Tree (Kruskal's / Prim's)
  • Q55. Rotting Oranges

6. Dynamic Programming

Q56. Climbing Stairs

python

python
def climb_stairs(n):
    if n <= 2:
        return n
    a, b = 1, 2
    for _ in range(3, n + 1):
        a, b = b, a + b
    return b

Time Complexity: O(n) | Space: O(1)


Q57. Coin Change (Minimum Coins)

python

python
def coin_change(coins, amount):
    dp = [float('inf')] * (amount + 1)
    dp[0] = 0
    for coin in coins:
        for x in range(coin, amount + 1):
            dp[x] = min(dp[x], dp[x - coin] + 1)
    return dp[amount] if dp[amount] != float('inf') else -1

Time Complexity: O(amount × coins)


Q58. Longest Common Subsequence

python

python
def longest_common_subsequence(text1, text2):
    m, n = len(text1), len(text2)
    dp = [[0] * (n + 1) for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if text1[i-1] == text2[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    return dp[m][n]

Q59. 0/1 Knapsack

python

python
def knapsack(weights, values, capacity):
    n = len(weights)
    dp = [[0] * (capacity + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for w in range(capacity + 1):
            if weights[i-1] <= w:
                dp[i][w] = max(dp[i-1][w], values[i-1] + dp[i-1][w - weights[i-1]])
            else:
                dp[i][w] = dp[i-1][w]
    return dp[n][capacity]

Q60. House Robber

python

python
def rob(nums):
    prev, curr = 0, 0
    for num in nums:
        prev, curr = curr, max(curr, prev + num)
    return curr

Q61–Q68 (Practice List)

  • Q61. Longest Increasing Subsequence
  • Q62. Edit Distance
  • Q63. Word Break
  • Q64. Unique Paths (Grid DP)
  • Q65. Partition Equal Subset Sum
  • Q66. Maximum Product Subarray
  • Q67. Decode Ways
  • Q68. Target Sum

7. Sorting & Searching

Q69. Binary Search

python

python
def binary_search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

Time Complexity: O(log n)


Q70. Search in Rotated Sorted Array

python

python
def search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            return mid
        if nums[left] <= nums[mid]:
            if nums[left] <= target < nums[mid]:
                right = mid - 1
            else:
                left = mid + 1
        else:
            if nums[mid] < target <= nums[right]:
                left = mid + 1
            else:
                right = mid - 1
    return -1

Time Complexity: O(log n)


Q71. Merge Sort

python

python
def merge_sort(arr):
    if len(arr) <= 1:
        return arr
    mid = len(arr) // 2
    left, right = merge_sort(arr[:mid]), merge_sort(arr[mid:])
    result, i, j = [], 0, 0
    while i < len(left) and j < len(right):
        if left[i] <= right[j]:
            result.append(left[i]); i += 1
        else:
            result.append(right[j]); j += 1
    return result + left[i:] + right[j:]

Time Complexity: O(n log n)


Q72–Q78 (Practice List)

  • Q72. Quick Sort
  • Q73. Find Kth Largest Element
  • Q74. Median of Two Sorted Arrays
  • Q75. Search a 2D Matrix
  • Q76. Find Minimum in Rotated Sorted Array
  • Q77. Meeting Rooms II
  • Q78. Top K Frequent Elements

8. Recursion & Backtracking

Q79. Generate Parentheses

python

python
def generate_parenthesis(n):
    result = []
    def backtrack(s, open_n, close_n):
        if len(s) == 2 * n:
            result.append(s)
            return
        if open_n < n:
            backtrack(s + '(', open_n + 1, close_n)
        if close_n < open_n:
            backtrack(s + ')', open_n, close_n + 1)
    backtrack('', 0, 0)
    return result

Q80. Subsets

python

python
def subsets(nums):
    result = []
    def backtrack(start, path):
        result.append(path[:])
        for i in range(start, len(nums)):
            path.append(nums[i])
            backtrack(i + 1, path)
            path.pop()
    backtrack(0, [])
    return result

Q81. Permutations

python

python
def permute(nums):
    result = []
    def backtrack(path, remaining):
        if not remaining:
            result.append(path[:])
            return
        for i in range(len(remaining)):
            backtrack(path + [remaining[i]], remaining[:i] + remaining[i+1:])
    backtrack([], nums)
    return result

Q82–Q87 (Practice List)

  • Q82. N-Queens
  • Q83. Word Search
  • Q84. Combination Sum
  • Q85. Palindrome Partitioning
  • Q86. Sudoku Solver
  • Q87. Letter Combinations of a Phone Number

9. Hashing & Two Pointers

Q88. Contains Duplicate

python

python
def contains_duplicate(nums):
    return len(nums) != len(set(nums))

Q89. 3Sum

python

python
def three_sum(nums):
    nums.sort()
    result = []
    for i in range(len(nums) - 2):
        if i > 0 and nums[i] == nums[i-1]:
            continue
        left, right = i + 1, len(nums) - 1
        while left < right:
            total = nums[i] + nums[left] + nums[right]
            if total == 0:
                result.append([nums[i], nums[left], nums[right]])
                while left < right and nums[left] == nums[left+1]:
                    left += 1
                while left < right and nums[right] == nums[right-1]:
                    right -= 1
                left += 1; right -= 1
            elif total < 0:
                left += 1
            else:
                right -= 1
    return result

Time Complexity: O(n²)


Q90–Q95 (Practice List)

  • Q90. Longest Consecutive Sequence
  • Q91. Valid Sudoku
  • Q92. Subarray Sum Equals K
  • Q93. Two Sum II (Sorted Array)
  • Q94. Remove Duplicates from Sorted Array
  • Q95. Sort Colors (Dutch National Flag)

10. Miscellaneous / System-Level

Q96. LRU Cache

python

python
from collections import OrderedDict

class LRUCache:
    def __init__(self, capacity):
        self.cache = OrderedDict()
        self.capacity = capacity

    def get(self, key):
        if key not in self.cache:
            return -1
        self.cache.move_to_end(key)
        return self.cache[key]

    def put(self, key, value):
        if key in self.cache:
            self.cache.move_to_end(key)
        self.cache[key] = value
        if len(self.cache) > self.capacity:
            self.cache.popitem(last=False)

Time Complexity: O(1) for get and put


Q97–Q100 (Practice List)

  • Q97. Design a Rate Limiter
  • Q98. Implement a Trie (Prefix Tree)
  • Q99. Design Twitter (Feed System)
  • Q100. Find Median from a Data Stream

How to Practice This List Effectively

  1. Don't jump straight to code. Say the approach out loud first — interviewers evaluate reasoning, not just syntax.
  2. Track time complexity for every solution. It's often asked as a follow-up.
  3. Group by pattern, not by problem. Notice how "two pointers" or "sliding window" reappears across dozens of questions.
  4. Redo problems after a week. Spaced repetition cements patterns far better than solving 100 problems once.
  5. Practice on a whiteboard or plain text editor occasionally, since many onsite interviews don't offer autocomplete.

Frequently Asked Questions

Q: How many coding questions should I practice before an interview? Most candidates see solid results after solving 150–250 problems across all major patterns, with this list of 100 as the foundation.

Q: Which language is best for coding interviews? Python is popular for its concise syntax, but Java and C++ are equally accepted at most companies. Pick the language you're fastest and most accurate in.

Q: Are these questions enough for FAANG interviews? This list covers the core patterns tested at nearly all major tech companies. Supplement it with company-specific practice (e.g., via Blind, Glassdoor reviews) as you get closer to your interview date.


Conclusion

Mastering these 100 coding interview questions gives you a strong, pattern-based foundation across arrays, trees, graphs, dynamic programming, and system-level design. Focus on understanding the why behind each solution, not just memorizing code — that's what will carry you through the follow-up questions interviewers love to ask.

Good luck with your prep — and happy coding!

Did you find this helpful?

Priyanshu Mishra
Priyanshu Mishra

Founder of Helloengineers

5 articles21 followers
View Profile

Comments (0)

Sign in to leave a comment

Related Articles

Join HelloEngineers

Connect with engineering students across India. Share your knowledge, build your reputation.