Mock Coding Interview Simulation

📖 Concept

Mock interviews are the most effective preparation method. Simulating real interview conditions builds comfort, timing, and communication skills.

How to run an effective mock:

  1. Set the environment: Plain text editor (no autocomplete), 45-minute timer, webcam on
  2. Think aloud: Narrate your entire thought process. Don't go silent.
  3. Follow the framework: Understand → Plan → Code → Test → Optimize
  4. Get feedback: After the mock, review: communication clarity, time management, code quality, edge cases

Timing breakdown for a 45-min round:

0-3 min:   Read problem, ask clarifying questions
3-8 min:   Discuss approach, state complexity
8-30 min:  Code the solution
30-38 min: Test with examples and edge cases
38-45 min: Discuss optimizations, follow-up questions

Common follow-up questions:

  • "Can you do this in O(1) space?"
  • "What if the input doesn't fit in memory?"
  • "How would you parallelize this?"
  • "What if the input is streaming (online algorithm)?"

Communication tips for senior candidates:

  • Lead the conversation — don't wait for prompts
  • State trade-offs — "I can do O(n) time with O(n) space, or O(n log n) with O(1) space"
  • Acknowledge complexity — "This is an NP-hard problem, so I'll use an approximation"
  • Discuss alternatives — "Another approach would be X, but I chose Y because..."

💻 Code Example

codeTap to expand ⛶
1// Mock interview example: Design an iterator for a 2D matrix
2// that traverses in spiral order
3
4// Step 1: Understand — I need to traverse a matrix in spiral order
5// and return elements one at a time via next() and hasNext()
6
7// Step 2: Plan — Pre-compute the spiral order in the constructor,
8// then iterate through the precomputed list. Alternative: maintain
9// boundaries and compute on-the-fly (more complex but O(1) space).
10
11// Step 3: Code
12class SpiralIterator(matrix: Array<IntArray>) : Iterator<Int> {
13 private val elements = mutableListOf<Int>()
14 private var index = 0
15
16 init {
17 if (matrix.isNotEmpty() && matrix[0].isNotEmpty()) {
18 var top = 0
19 var bottom = matrix.size - 1
20 var left = 0
21 var right = matrix[0].size - 1
22
23 while (top <= bottom && left <= right) {
24 // Right
25 for (col in left..right) elements.add(matrix[top][col])
26 top++
27 // Down
28 for (row in top..bottom) elements.add(matrix[row][right])
29 right--
30 // Left
31 if (top <= bottom) {
32 for (col in right downTo left) elements.add(matrix[bottom][col])
33 bottom--
34 }
35 // Up
36 if (left <= right) {
37 for (row in bottom downTo top) elements.add(matrix[row][left])
38 left++
39 }
40 }
41 }
42 }
43
44 override fun hasNext(): Boolean = index < elements.size
45 override fun next(): Int {
46 if (!hasNext()) throw NoSuchElementException()
47 return elements[index++]
48 }
49}
50
51// Step 4: Test
52// Input: [[1,2,3],[4,5,6],[7,8,9]]
53// Expected: 1,2,3,6,9,8,7,4,5
54// Edge: empty matrix → hasNext() = false
55// Edge: single row → 1,2,3
56// Edge: single column → 1,4,7
57
58// Step 5: Discuss
59// Time: O(m*n) constructor, O(1) next/hasNext
60// Space: O(m*n) for stored elements
61// Trade-off: Could compute on-the-fly with O(1) space but more complex

🏋️ Practice Exercise

Mock Interview Schedule (Weekly):

  • Monday: Solve 2 medium problems with timer (35 min each)
  • Tuesday: Solve 1 hard problem (45 min)
  • Wednesday: System design practice (45 min)
  • Thursday: Solve 2 medium problems from different categories
  • Friday: Full mock interview with a partner
  • Weekend: Review all solutions from the week, identify weak patterns

Self-assessment after each mock:

  1. Did I identify the pattern within 3 minutes?
  2. Did I discuss my approach before coding?
  3. Was my code clean and idiomatic Kotlin?
  4. Did I handle edge cases without prompting?
  5. Did I stay within the time limit?
  6. Did I communicate clearly throughout?

⚠️ Common Mistakes

  • Practicing with autocomplete and syntax highlighting — Google interviews use Google Docs or a simple editor

  • Not timing yourself — without time pressure, you can't assess if your pace is interview-ready

  • Practicing solo only — pair mock interviews are 10x more effective because they test communication

  • Only practicing easy problems — Google asks medium to hard problems, practice at that level

💼 Interview Questions

🎤 Mock Interview

Mock interview is powered by AI for Mock Coding Interview Simulation. Login to unlock this feature.