CHAPTER 18
Beginner
Mock Coding Interviews
Updated: May 18, 2026
5 min read
# CHAPTER 18
Mock Coding Interviews
1. Chapter Introduction
Solving LeetCode problems alone in your dark bedroom with unlimited time and a working compiler is vastly different from writing code on a whiteboard while a senior Google engineer stares at you. The technical interview is a performance. If you write the perfect O(N) solution but do so in complete silence, you will likely fail. This chapter bridges the gap between algorithmic theory and interview execution, teaching you how to communicate, structure your 45 minutes, and recover from mistakes.2. The 45-Minute Timeline
Manage the clock rigidly. Do not jump straight into code.- Minutes 0-5: Understand and Clarify. (Ask questions, define edge cases).
- Minutes 5-10: Brainstorm and Plan. (State the Brute Force, propose the optimal approach).
- Minutes 10-30: Implementation. (Write the code cleanly, talking out loud).
- Minutes 30-40: Testing and Review. (Dry-run the code with a test case, find bugs).
- Minutes 40-45: Complexity Analysis & Questions. (State Big-O, ask them about the company).
3. Step 1: Clarification (The Defensive Opening)
Interviewers intentionally give vague prompts to see if you will rush blindly. *Prompt:* "Given an array, return two numbers that add up to target." *Your Questions:*- 1. "Are the numbers sorted?" (Dictates Two Pointers vs Hash Map).
- 2. "Can there be negative numbers?"
- 3. "Will there always be exactly one valid answer?"
- 4. "Can I use the exact same element twice?"
- 5. "What should I return if the array is empty?"
4. Step 2: Brainstorming (The Brute Force Rule)
ALWAYS state the naive brute-force solution first. *Candidate:* "The simplest approach is a nested for-loop comparing every pair. This would be O(N^2) time and O(1) space. However, we can optimize the time complexity. Since we are doing repeated lookups, I can trade space for time by using a Hash Map to store elements as I iterate, dropping the time to O(N)." *Why this works:* If you blank out on the optimal solution 15 minutes later, the interviewer still knows you can solve the problem at a basic level.5. Step 3: Implementation (Thinking Out Loud)
Treat the interviewer as your co-worker in a pair-programming session.- Narrate your typing: "I'm initializing a Hash Set here to keep track of the visited nodes so we don't hit an infinite loop."
-
Modularize: If a piece of logic is messy (like checking if a coordinate is valid on a grid), don't write 5 lines of messy
ifstatements. Write:if isValid(row, col):and tell the interviewer, "I will implement this helper function later to keep the main logic clean."
6. Handling Hints Gracefully
Getting a hint does NOT mean you failed. Getting a hint and *ignoring* it means you failed. If the interviewer says: "What happens if the input is all zeroes?" *Do not say:* "I'll fix that later." *Do say:* "That's a great catch. My current loop would divide by zero. Let me add anif num == 0: guard clause right here."
They are testing how well you take feedback and collaborate.
7. Step 4: The Dry Run (Self-Debugging)
You finish the code. The interviewer asks, "Does it work?" Do NOT just say "Yes." You must prove it. Pick a small, non-trivial test case. Trace your variables line-by-line using comments.
python
Catching your own bug during a dry-run shows extreme engineering maturity. If the interviewer points out the bug before you do, you lose points.
8. Whiteboard vs. Shared Editor
- Whiteboard (In-person): Start writing on the far left edge of the board. Leave massive spaces between lines of code so you can insert lines later without erasing everything.
- Shared Editor (CoderPad/HackerRank): Rely heavily on your IDE structure. Write a comprehensive comment block at the top outlining your algorithm before typing syntax.
9. Common Mistakes
- The Silent Panic: You freeze. You stare at the board for 3 minutes in silence. *The Fix:* Talk. Say, "I am trying to decide between a BFS and a DFS. BFS would guarantee the shortest path, but..." The interviewer will often gently guide you if you think out loud.
- Premature Optimization: Trying to write the perfect, one-line, clever O(1) space solution, getting confused, and writing nothing. A working Brute Force is better than a broken optimal solution.
10. Best Practices
- Define Big-O Unprompted: At the end of the dry-run, do not wait to be asked. "So, this algorithm iterates through the array once, giving us O(N) Time complexity, and uses a Hash Map storing at most N elements, giving us O(N) Space."
11. Exercises
- 1. Perform a Solo Mock Interview. Write down the prompt for "Two Sum". Record yourself on video for 20 minutes solving it on a piece of paper while speaking out loud. Watch the video. Did you explain the Time Complexity clearly?
- 2. Write down 3 clarifying questions you would ask for the prompt: "Find the longest substring."
12. MCQs
Question 1
What is the most common reason technically competent engineers fail coding interviews?
Question 2
During the first 5 minutes of the interview (Clarification Phase), what must you do immediately after receiving the prompt?
Question 3
Why should you verbally state the "Brute Force" (naive) solution before attempting the optimal solution?
Question 4
If you realize your logic requires a messy, 10-line mathematical validation check in the middle of your main algorithm, what is the best whiteboard strategy?
Question 5
How should you react if the interviewer interrupts you to give a hint or point out a flaw?
Question 6
What does "Dry Running" the code mean?
Question 7
Is catching a bug in your own code during the Dry-Run phase a bad thing?
Question 8
When drawing on a physical whiteboard, what is a crucial space management tactic?
Question 9
When should you state the Big-O Time and Space complexity of your solution?
Question 10
What should you do if you completely freeze and have no idea how to solve the problem?
14. Interview Questions
- Q: "You have 5 minutes left. Your code works, but the interviewer asks: 'Can you do this in O(1) Space instead of O(N)?' You don't have time to rewrite it. How do you respond?"
15. FAQs
- Q: Should I ask the interviewer how the code will be tested?