All interview guides

Coding interview questions: the patterns behind them and how to answer

Invisipilot editorial team · Updated

Most coding interview questions are variations of about a dozen patterns. Recognising the pattern quickly is what lets you get to a working solution in 30–45 minutes. Below are the patterns that come up most, a classic question for each with the approach a strong answer uses, and how to talk through your solution so the interviewer can follow your thinking.

How to approach any coding question

  • →Restate the problem and confirm the input, output and edge cases (empty input, duplicates, very large values).
  • →Say a brute-force solution and its time complexity out loud first, so you have something correct.
  • →Look for the pattern that removes the repeated work, then explain the faster approach before you write code.
  • →Write clean code with clear names, then walk through a small example by hand.
  • →State the final time and space complexity and mention what you would test.

Before the interview comes the resume screen — check your resume's ATS score free against the job you're applying for.

The most common patterns, with a classic question each

  1. 1.Hash map: Two Sum

    Store each number's index in a map; for every number check whether target − number is already in the map. One pass, O(n) time and O(n) space.

  2. 2.Two pointers: Container With Most Water

    Start pointers at both ends, compute the area, then move the pointer at the shorter line inward, because only that can improve the area. O(n) time, O(1) space.

  3. 3.Sliding window: Longest Substring Without Repeating Characters

    Grow a window to the right while characters are unique; when a repeat appears, move the left edge past its last position (kept in a map). O(n) time.

  4. 4.Binary search: Search in Rotated Sorted Array

    At each step one half is sorted. Check whether the target lies in the sorted half and discard the other half. O(log n) time.

  5. 5.Stack: Valid Parentheses

    Push opening brackets; on a closing bracket the top of the stack must be its match. The string is valid when the stack ends empty. O(n) time.

  6. 6.Linked list: Reverse a Linked List

    Walk the list keeping prev, current and next pointers, pointing each node back to prev. O(n) time, O(1) space; mention the recursive version too.

  7. 7.Trees (DFS): Maximum Depth of a Binary Tree

    Depth = 1 + max(depth(left), depth(right)), with 0 for an empty node. O(n) time, O(h) stack space where h is the height.

  8. 8.Graphs (BFS): Number of Islands

    Scan the grid; for each unvisited land cell, count an island and flood-fill its neighbours with BFS or DFS. O(rows × cols) time.

  9. 9.Heap: Top K Frequent Elements

    Count frequencies with a map, then keep a min-heap of size k (or bucket-sort by frequency for O(n)). O(n log k) time with the heap.

  10. 10.Dynamic programming: Climbing Stairs / Coin Change

    Define what dp[i] means, write the recurrence (for coin change: dp[a] = min(dp[a − coin] + 1)), set the base case, and fill the table bottom-up. Mention the space optimisation.

  11. 11.Intervals: Merge Intervals

    Sort by start, then merge each interval into the last one when they overlap. O(n log n) time for the sort.

  12. 12.Backtracking: Subsets / Permutations

    Build the answer step by step, recurse, then undo the last choice. Explain how you avoid duplicates and the exponential output size.

How to talk while you code

  • →Narrate decisions, not keystrokes: “I'll use a map here so the lookup is constant time.”
  • →If you get stuck, say what you are trying and ask a focused question; interviewers often help when they can follow you.
  • →Test with your own small example before saying you are done, and fix bugs calmly out loud.

Blank on the day?

Invisipilot listens to your live interview and shows a structured answer on your screen in seconds — built from your own resume and the role you're applying for. Works with Zoom, Google Meet and Teams, in the Windows and Mac app (a private overlay) or in browser mode.

One-time hour packs, time never expires — see pricing.

Frequently asked questions

Which programming language should I use?
The one you write fastest and most correctly. Python, Java, C++ and JavaScript are all accepted almost everywhere; check the company's instructions for online assessments.
What if I can't find the optimal solution?
Deliver a correct brute-force solution, explain its complexity and where the repeated work is. A working, well-explained solution often scores better than an unfinished optimal one.
How important is time and space complexity?
Very. You will almost always be asked for it, so state it for both your first and your final solution.

More interview guides

Walk into your next interview with a Private Copilot

Start free — 30 minutes of live help, 1 ATS score and 1 ATS resume update on signup, no credit card required.

About Invisipilot
Real-time answers
Streamed live as they ask.
Private overlay (desktop app)
Only you see it — kept off your screen share.
Resume-aware answers
Matched to your real experience.