An algorithmic interview does not test whether you "know the answer". It checks how you think: you clarify the statement, propose a solution, explain it, write clean code and check yourself. The good news is that the process can be trained like any other skill.

Six interview stages and a 45-minute time budget
Six interview stages and a 45-minute time budget

Six stages

  1. Clarify. Input size, value range, empty input, duplicates, one answer or all of them, what to return when there is no solution.
  2. Examples. One or two small examples and one edge case. Say the expected result aloud.
  3. Approach. Start simple (brute force) and state its complexity, then improve: which structure or technique (hash table, two pointers, sorting, heap) and why.
  4. Code. Write after the interviewer agrees with the approach. Clear names, small functions, comments only for the non-obvious.
  5. Test. Trace the examples by hand, then the edge cases: empty, one element, duplicates, negative numbers.
  6. Complexity. State time and memory and say what you pay for the speed-up.

Example: Two Sum