How experts approach any problem

How to Think · Start Here · Basics · 14 min

The thinking loop strong engineers use on every problem, from DSA rounds to system design and AI, walked through on one example.

Solving is a skill, not a talent

Watch a nervous candidate get a new problem: they read it once, start typing, get stuck on line six, and go silent. Watch a strong one: they slow down, ask questions, solve a tiny case by hand, say the slow idea out loud, then improve it.

The second person isn't smarter. They have a process, and they trust it. The good news: a process can be learned, practised and repeated under pressure.

This course teaches that process for DSA, system design and GenAI, and for the interview room itself. This first lesson shows the whole loop on one problem.

The loop: seven steps, every time

Every strong solution goes through the same seven steps, even when the expert does some of them in a few seconds:

  1. Understand: restate it, name the input and output, ask about the edges.
  2. Examples: solve a tiny case by hand. Your hand-steps are your first algorithm.
  3. Size it: read the constraints. How big is n, and how fast must you be?
  4. Brute force: the simplest correct idea, with its Big-O.
  5. Find the waste: what does brute force repeat or recompute?
  6. Pattern and optimise: pick the technique that removes the waste.
  7. Code, test, explain: write it, dry-run it, state the complexity.

Let's run the loop on a classic: Two Sum.

Step 1-2: understand it, then solve it by hand

Problem: given a list of numbers and a target, return the positions of two numbers that add up to the target.

Before any code, restate it and ask about the edges. Each answer changes the solution:

  • Is there always exactly one answer? (If not, what do I return?)
  • Can I use the same element twice?
  • Can numbers be negative? Is the list sorted?
  • Do you want positions or the values?

Then a tiny example by hand: [2, 7, 11, 15], target 9. I look at 2, I need 7... 7 is there. Answer: positions 0 and 1. Notice how you did it: "I need 7, is 7 there?" That thought is the optimal solution in disguise.

Step 3: the constraints tell you the algorithm

Problems come with limits like 2 ≤ n ≤ 10⁵. That number is a huge hint.

A computer does roughly 10⁸ simple steps a second. With n = 10⁵, an O(n²) idea needs 10¹⁰ steps: about 100 seconds, far too slow. O(n log n) or O(n) needs well under a millisecond.

So before you've written anything, you already know: the final answer must be O(n log n) or better. Slide n in the picture and watch which rows turn red.

Step 4: brute force first, out loud

Say the simplest correct idea, even though you know it's too slow: try every pair.

It proves you understand the problem, gives you something correct to fall back on, and it's the thing you'll improve. State its cost: two nested loops over n items is O(n²) time, O(1) extra space.

In an interview, say: "The brute force checks every pair, O(n²). With n up to 10⁵ that's too slow, so let me look for repeated work." That sentence alone shows the interviewer you think like an engineer.

Step 5-6: find the waste, pick the pattern

Ask the magic question: what does brute force do again and again?

For every number, the inner loop searches the whole list for target - x. That search is the waste. What makes "is this value here?" instant? A hash map (a set or dictionary): O(1) lookups.

The Pattern Finder on the right reads the same three signals you just did: the input is an array, the ask is a pair with a sum, n is large. Its first pick is the hash map, for exactly that reason. Click around: change the ask to "Longest contiguous part" and watch the answer switch to sliding window.

Step 7: code it, test it, explain it

One pass: for each number, check whether its partner was already seen; if not, remember this number.

Then dry-run your tiny example line by line (2: need 7, not seen, store 2. 7: need 2, seen at 0, return [0, 1]), and try the edges: negatives, the answer at the very end, duplicates like [3, 3] with target 6.

Finish by stating the result: "O(n) time, O(n) extra space for the map. I traded memory for speed." Naming the trade-off is what separates a good answer from a great one.

The same loop works beyond DSA

The steps change names, but the thinking is the same everywhere:

  • System design: understand = requirements; size it = estimate users, QPS and storage; brute force = the simplest architecture; find the waste = the bottleneck; optimise = cache, queue, shard; explain = trade-offs.
  • GenAI: understand = the task and success metric; size it = cost and latency budgets; brute force = a plain prompt baseline; find the waste = where it fails on your eval set; optimise = RAG, tools, fine-tuning; explain = evals and risks.

Once the loop is a habit, new problems stop feeling new.

What's in this course

This lesson is free. The rest of How to Think is part of Pro:

  • DSA: How to Think: reading problems, constraints to complexity, brute force first, pattern recognition, optimising wasted work, edge cases and testing.
  • DSA: Worked Approaches: 12 classic problems solved with the full thinking, not just the answer.
  • System Design: How to Think: the framework, estimation, trade-offs and a complete worked design.
  • GenAI & ML: How to Think: framing AI problems, RAG vs fine-tuning, a complete worked design.
  • In the Interview: thinking out loud, what to do when stuck, debugging under pressure.

More in Start Here

Next: Read the problem like an engineer