A Framework for Any Problem

Beginner · 15 min read · DSA Without Fear, Mindset & Method

Understand, brute force, spot the pattern, optimise, code, test — and a playbook for when you are stuck.

The blank-page feeling usually comes from trying to jump straight from the problem to the perfect solution. Nobody does that. Strong problem solvers follow a sequence of small, safe steps — and each step gives them something to say and something to build on.

The six steps

Write down the most obvious correct solution, however slow, and its cost. Try every pair, every subarray, every subset. This isn't wasted time:

Worked example: best time to buy and sell a stock

1. Understand. Prices like [7, 1, 5, 3, 6, 4]. Buy at 1, sell at 6 → profit 5. Edge case: prices only fall, like [7, 6, 4] → 0. Constraints: up to 100,000 prices.

The edge-case checklist

Run through this before you say "done":

When you're stuck

Being stuck is a normal part of solving. These moves get you unstuck, roughly in order:

Interview questions

  • Should I mention the brute-force solution if I already know the optimal one?
  • How do I know whether my solution is fast enough?

Further reading

Key takeaways

  • Follow the steps: understand → brute force → find the bottleneck → optimise → code → test.
  • A brute force is a safety net and the place where the pattern hides: look at what it repeats.
  • Check complexity against the constraints before coding.
  • Trace your code by hand and run the edge-case checklist before saying "done".
  • When stuck: tiny cases by hand, simplify, look for repetition, try each data structure — and keep talking.

Previous: How to Practise So It Sticks · Next: Big-O the Easy Way