Skip to main content

🎯 Coding Interview Best Practices

The meta-game of interviews. Technical skill + communication = success.

TL;DR: The 45-Minute Framework​

PhaseTimeWhat to DoRed Flags
Understand5 minClarify, examples, edge casesJumping to code
Plan5 minPattern, approach, complexityNo plan stated
Code20-25 minClean, modular, talkingSilent coding
Test8-10 minWalk through, edge cases"I think it works"
Optimize2 minTime/space, trade-offsForgot complexity

The UMPIRE Method​

A battle-tested framework used by Google engineers.

U - Understand the Problem​

Before anything else, make sure you understand WHAT to solve.

βœ… DO:
- Repeat the problem in your own words
- Ask about input/output format
- Clarify constraints (size, range, types)
- Ask for examples
- Identify edge cases

❌ DON'T:
- Assume anything
- Start coding immediately
- Say "I've seen this before"

Questions to ask:

  • "What's the input format?"
  • "What should I return if the input is empty?"
  • "Are there duplicates? How should I handle them?"
  • "Can I modify the input array?"
  • "What's the expected size of the input?"

M - Match to Patterns​

What type of problem is this?

Say it out loud:

"This looks like a sliding window problem because we're looking for a subarray with a certain property."

P - Plan the Approach​

Before coding, state your plan clearly.

βœ… Good Planning:
"I'll use a HashMap to track character frequencies.
I'll iterate through the string once, updating counts.
Time: O(n), Space: O(k) where k is unique characters."

❌ Bad Planning:
"Let me just start coding and see..."

Get buy-in from interviewer:

"Does this approach sound reasonable before I start coding?"

I - Implement​

Now write clean, modular code.

Best Practices:

# βœ… GOOD: Clear variable names, comments
def find_longest_substring(s: str) -> int:
char_index = {} # Store last seen index of each char
max_length = 0
start = 0

for end, char in enumerate(s):
# If char seen and within current window
if char in char_index and char_index[char] >= start:
start = char_index[char] + 1

char_index[char] = end
max_length = max(max_length, end - start + 1)

return max_length

# ❌ BAD: Unclear names, no structure
def f(s):
d = {}
m = 0
st = 0
for i, c in enumerate(s):
if c in d and d[c] >= st:
st = d[c] + 1
d[c] = i
m = max(m, i - st + 1)
return m

While coding:

  • Talk through your logic
  • Write helper functions for complex parts
  • Don't worry about perfect syntax
  • If unsure about API, say so: "I think the syntax is X, let me know if I'm wrong"

R - Review and Test​

Never say "I think it works." PROVE IT.

Testing Strategy:

  1. Walk through with given example

    Input: [1, 2, 3], target = 5
    Step 1: i=0, current=1, complement=4, not in map
    Step 2: i=1, current=2, complement=3, not in map
    Step 3: i=2, current=3, complement=2, FOUND at index 1
    Return: [1, 2] βœ“
  2. Test edge cases

    • Empty input: []
    • Single element: [5]
    • No solution exists
    • All same elements: [1, 1, 1, 1]
  3. Test boundaries

    • Maximum values
    • Negative numbers
    • Very long strings

E - Evaluate Complexity​

Always state time and space complexity.

βœ… GOOD:
"Time complexity is O(n) because we iterate once.
Space is O(k) for the HashMap, where k is unique characters.
In the worst case, k = n, so O(n) space."

❌ BAD:
"It's pretty efficient."

Communication: The Hidden Skill​

Talk Out Loud (Always)​

Interviewers assess your thinking, not just the code.

Instead of...Say...
Silent thinking"I'm thinking about whether to use DFS or BFS here..."
"Let me think""Let me trace through an example to verify my logic..."
Getting stuck silently"I'm stuck on X, let me try approach Y..."

How to Handle Being Stuck​

Script for being stuck:

"I'm stuck on the optimal solution. Let me start with a brute force approachβ€”that would be O(nΒ²) by checking every pair. Now let me think about how to optimize...

Actually, if I sort the array first, I could use two pointers... that would be O(n log n) for sort plus O(n) for the search."

Handling Hints Gracefully​

βœ… Good response to hints:

"Ah, that's a great hint! So if I use a HashMap here, I can reduce the lookup from O(n) to O(1). Let me refactor..."

❌ Bad response:

"Oh, I knew that already, I was just about to do that."


Code Quality Checklist​

Before You Start​

  • Understood the problem?
  • Clarified edge cases?
  • Stated approach and complexity?
  • Got interviewer's buy-in?

While Coding​

  • Clear variable names?
  • Talking through logic?
  • Handling edge cases?
  • Modular (helper functions)?

After Coding​

  • Walked through with example?
  • Tested edge cases?
  • Stated time complexity?
  • Stated space complexity?
  • Discussed trade-offs?

Common Mistakes (And How to Avoid Them)​

❌ Mistake 1: Jumping Into Code​

Problem: You start coding without understanding the problem.

Fix: Force yourself to repeat the problem and ask at least 3 clarifying questions.

❌ Mistake 2: Going Silent​

Problem: You think quietly for 2+ minutes.

Fix: Narrate your thinking: "I'm considering using a hash map because..."

❌ Mistake 3: Not Testing​

Problem: "I think it works" without verification.

Fix: Always trace through your code with at least one example.

❌ Mistake 4: Over-Engineering​

Problem: Adding fancy optimizations before basic solution works.

Fix: Get a working solution first, then optimize.

❌ Mistake 5: Getting Defensive​

Problem: Arguing when interviewer points out bugs.

Fix: "Good catch! Let me fix that." Then debug systematically.


Real Interview Walkthrough​

Problem: Find two numbers that add to target.

Phase 1: Understand (2 min)​

Me: "So I need to find two numbers in the array that sum to target. Should I return indices or values?"

Interviewer: "Indices."

Me: "Is the array sorted? Are there duplicates?"

Interviewer: "Not sorted, can have duplicates."

Me: "And exactly one solution exists?"

Interviewer: "Yes, assume valid input."

Phase 2: Plan (2 min)​

Me: "Brute force would check every pairβ€”O(nΒ²). But I can use a HashMap to store complements. For each number, check if target - num exists. That's O(n) time, O(n) space. Should I proceed?"

Interviewer: "Sounds good."

Phase 3: Code (8 min)​

def two_sum(nums: list[int], target: int) -> list[int]:
# Map: value -> index
seen = {}

for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i

return [] # No solution (shouldn't happen per constraints)

Phase 4: Test (3 min)​

Me: "Let me trace through: nums = [2, 7, 11], target = 9

  • i=0, num=2, complement=7, not in seen, add {2: 0}
  • i=1, num=7, complement=2, 2 is in seen! Return [0, 1]

Let me also check empty array: returns [] which is correct."

Phase 5: Complexity (1 min)​

Me: "Time O(n) - single pass. Space O(n) - HashMap in worst case stores n elements."


Interview Day Tips​

Before the Interview​

  • Get 7+ hours of sleep
  • Eat a light meal (not hungry, not sluggish)
  • Review your top 5 patterns
  • Test your setup (camera, mic, IDE)
  • Have water nearby

During the Interview​

  • Take a breath before answering
  • It's OK to ask for a moment to think
  • Ask clarifying questions
  • Start with brute force if stuck
  • Test your solution

After Mistakes​

❌ "Oh no, I'm so dumb"
❌ "This is easy, I can't believe I missed that"
❌ Arguing with interviewer

βœ… "Good catch, let me fix that"
βœ… "I see the bugβ€”it's in the loop condition"
βœ… "Thanks for the hint, that helps"

Key Takeaways​

  1. Never code without a plan
  2. Talk out loud the entire time
  3. Start simple, then optimize
  4. Test with real examples
  5. Handle mistakes gracefully
  6. State complexity at the end


Next: Two Pointers Pattern β†’ - Your first pattern.