# A Repeatable Problem-Solving Method — DSA Interview Patterns

Source: https://www.skillbyai.com/en/dsa-interview-patterns/p-method

> Do not start typing immediately.

## Clarify, examples, brute force, optimise, code, test

Strong candidates follow a rhythm: **clarify** the problem (input sizes, duplicates, negatives, empty input, expected output format), work through **examples** including edge cases, state a **brute-force** solution and its complexity, **optimise** by spotting repeated work, then **code** cleanly and **test** by tracing an example and edge cases aloud. Interviewers score communication, problem solving, code quality and testing, not just a correct answer.

## Understand, plan, code, test

A calm, repeatable method and a sense of complexity matter as much as knowing algorithms.

![Three ideas: the method, complexity, pattern recognition.](assets/figures/dsa-interview-patterns/section-1-map.svg) — Figure 1.1 — Method, complexity and patterns.

## A script for the first five minutes

What to say before coding.

```text
1. Restate: "So I need to return indices of two numbers that add up to target."
2. Clarify: "Can there be duplicates? Exactly one answer? Can I use an element twice?"
3. Example + edge cases: [2,7,11,15], 9 -> [0,1];  empty list;  negative numbers
4. Brute force: "Check every pair: O(n^2) time, O(1) space."
5. Optimise: "For each x I need target - x; a hash map gives O(1) lookups -> O(n)."
6. Confirm: "Shall I code the O(n) hash map version?"
```

## Say the brute force out loud

Even if you know the optimal solution, stating the naive one first shows structured thinking and gives you a fallback.

**Quiz:** What should you do before writing code?

- [ ] Ask for the answer
- [ ] Start typing the optimal solution immediately
- [x] Clarify constraints and work through examples
- [ ] Write tests for every possible input

*Answer:* Clarify constraints and work through examples. Understanding first.
