How would you review a coding solution for correctness, complexity and testability?
Answer
Start from the stated contract and identify the loop, recursion or data-structure invariants that make the result correct. Check termination, overflow, mutation, error handling and behavior at size limits; then derive time and space complexity from actual operations. Finally, separate pure logic from I/O or time, name adversarial examples, and confirm failures are observable rather than swallowed.
Strong answer includes
- uses invariants instead of intuition alone
- derives complexity from the implementation
- reviews dependency control and failure observability
Practical example
Reviewing a recursive tree-traversal solution, the reviewer asks what happens with a tree ten thousand levels deep; the candidate realizes their recursive approach will blow the call stack, which the happy-path test on a five-node tree never revealed.