What they're testing
Whether you can work without knowing the answer — which the actual job requires daily.
The short answer~30 seconds
Restate the problem in your own words to confirm you've understood it. Ask about constraints: how large is n, is the input sorted, can there be duplicates, can it be empty. Work one small example by hand. State a brute-force approach with its complexity — this matters because it anchors you and shows the interviewer you aren't stuck. Only then look for improvements, and only write code once the approach is agreed.
The long answer
Stating the brute force is skipped by many for fear of sounding weak. The opposite is true: it proves you understood the problem, gives you a fallback if time runs out, and turns the conversation into "improving on O(n²)" rather than silent thinking. Three minutes of silence is the worst signal in this round, because there's nothing for the interviewer to assess.
Constraint questions aren't ceremony — they prune the solution space hard. n ≤ 1,000 means O(n²) is acceptable and you needn't optimise further. A sorted input opens up two pointers and binary search. Lowercase letters only means a 26-element array instead of a hash map. Each question can save ten minutes of going the wrong way.
On being stuck: naming where you're stuck is legitimate and usually earns a hint. "I think I need to memoise, but I haven't worked out what the key should be" is far better than sitting quietly — the interviewer wants to see you collaborate under difficulty, because that's precisely what working with you will be like.
What they'll ask next
?What do you do once it's written?
Trace one small example line by line, even if you're confident. Then check the edges: empty array, one element, all elements identical. Finding your own bug before the interviewer points at it scores considerably higher than getting it right first time.
These lose points
- Coding as soon as the problem is stated. You're solving the problem you imagined rather than the one asked.
- Thinking in silence. Nothing said is nothing to score, and the clock keeps running.
Elsewhere on this site
Sources
- Polya — How to Solve It (understand, plan, carry out, look back)