Coding interview questions

Common coding interview questions and the patterns behind them

Most coding interview problems are variations on a few patterns. Recognise the pattern and you are halfway there - then talk through the approach, the complexity and the edge cases.

  1. 1.Two Sum: find two numbers in an array that add up to a target.

    What they're checking
    Whether you go past the O(n²) brute force.
    How to answer
    Hash map: for each number, check whether target minus it has been seen. O(n) time, O(n) space.
  2. 2.Reverse a linked list.

    What they're checking
    Comfort with pointers.
    How to answer
    Walk the list with three pointers - previous, current, next - and flip each link. Mention the recursive version too.
  3. 3.Find the longest substring without repeating characters.

    What they're checking
    The sliding window pattern.
    How to answer
    Move a right pointer forward; when a character repeats, move the left pointer past its last position. Track the best length. O(n).
  4. 4.Check whether a string of brackets is balanced.

    What they're checking
    Using a stack.
    How to answer
    Push opening brackets; on a closing bracket, the top of the stack must match. The stack must be empty at the end.
  5. 5.Find the maximum depth of a binary tree.

    What they're checking
    Recursion on trees.
    How to answer
    Depth is 1 plus the larger depth of the two subtrees; an empty tree has depth 0. Mention the level-order (BFS) version.
  6. 6.Merge overlapping intervals.

    What they're checking
    Sorting as a first step.
    How to answer
    Sort by start; extend the last merged interval if the next one overlaps, otherwise start a new one. O(n log n).
  7. 7.Climbing stairs: how many ways to climb n steps, one or two at a time?

    What they're checking
    Spotting dynamic programming.
    How to answer
    Ways(n) = ways(n-1) + ways(n-2) - it's Fibonacci. Keep only the last two values for O(1) space.
  8. 8.Find the kth largest element in an array.

    What they're checking
    Heaps, and choosing between approaches.
    How to answer
    Keep a min-heap of size k: O(n log k). Mention quickselect for O(n) on average.
  9. 9.Count the islands in a grid of land and water.

    What they're checking
    Graph traversal on a grid.
    How to answer
    For each unvisited land cell, start a DFS or BFS that marks the whole island visited, and count the starts. O(rows × columns).
  10. 10.Design an LRU cache.

    What they're checking
    Combining data structures.
    How to answer
    A hash map for O(1) lookup plus a doubly linked list for recency order; move an item to the front on use and evict from the back.

On a live call, Cuelyte AI hears questions like these and has an answer ready in about a second, built from your resume and notes. Coding interviews: how Cuelyte AI helps

More interview questions

Get help with the question you didn't prepare for

Cuelyte AI hears the question on the call and has an answer ready in about a second, on a window hidden from screen sharing.