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