A phased approach to coding interviews
Writing Code
Goals
Code should be performant, easy to read, easy to change, and easy to test.
Work through the problem in phases; there might be some overlap or circularity, but the only hard rule is that you shouldn’t write code till Understand and Plan are complete.
Understand
don’t code what you don’t understand
- Clarify the Problem - What exactly needs to be solved?
- Work Through Examples - Concrete inputs and expected outputs
- Identify the Brute Force Solution - What’s the obvious approach?
- Edge Cases
- Zero: Empty arrays, null inputs, zero values
- One: Single elements, first/last indices
- Many: Typical multi-element scenarios
- Boundaries: Min/max values, array bounds, overflow
- Interfaces: Interfaces of valid and invalid input types
- Exceptions: Invalid inputs, error conditions
- Systems: Integration between components, objects, and systems
Plan
design before you code
- Choose Data Structures
- Array, LinkedList, Stack, Queue
- Tree (Binary, Binary Search, NAry), Graph,
- HashMap, HashSet
- Trie
- Design Algorithm
- Estimate Complexity
- Time
- Space
- Output Size
Write
produce the simplest solution that works
Review
are the goals met?
- Style
- Tradeoffs
- Scale
- Production