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

  1. Clarify the Problem - What exactly needs to be solved?
  2. Work Through Examples - Concrete inputs and expected outputs
  3. Identify the Brute Force Solution - What’s the obvious approach?
  4. 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

  1. Choose Data Structures
    • Array, LinkedList, Stack, Queue
    • Tree (Binary, Binary Search, NAry), Graph,
    • HashMap, HashSet
    • Trie
  2. Design Algorithm
  3. Estimate Complexity
    • Time
    • Space
    • Output Size

Write

produce the simplest solution that works

Review

are the goals met?

  • Style
  • Tradeoffs
  • Scale
  • Production