Coding Round Simulations

0/3 in this phase0/52 across the roadmap

📖 Concept

Coding round simulation — practice exactly like the real interview. Use a plain text editor, set a 45-minute timer, and solve 2 problems.

Google coding interview format:

  • 45 minutes, 2 problems (sometimes 1 hard problem)
  • Typically: 1 medium + 1 medium, or 1 medium + 1 hard
  • Language: Kotlin preferred for Android candidates
  • Environment: Google Docs or simple code editor (no autocomplete!)

Evaluation rubric (how Google scores):

1. Problem Solving (40%):
   - Correctly identifies the approach
   - Handles edge cases
   - Optimizes when prompted
   
2. Coding (30%):
   - Clean, readable code
   - Proper variable names
   - Idiomatic Kotlin/language usage
   
3. Communication (20%):
   - Explains thought process
   - Responds well to hints
   - Discusses trade-offs
   
4. Verification (10%):
   - Tests with examples
   - Identifies edge cases
   - Catches bugs before prompted

Simulated practice rounds:

Round 1 (Medium + Medium):

  • Problem A: Given a list of transactions with amounts and categories, find the top K categories by total spending
  • Problem B: Given a binary tree, find all paths that sum to a target value

Round 2 (Medium + Hard):

  • Problem A: Implement a class that schedules delayed tasks with cancellation support
  • Problem B: Given a grid of characters and a dictionary, find all words that can be formed by adjacent cells

💻 Code Example

codeTap to expand ⛶
1// SIMULATION: Round 1, Problem A
2// "Find top K categories by total spending"
3// Input: transactions = [("food", 50), ("transport", 30), ("food", 20),
4// ("entertainment", 100), ("transport", 40)], K = 2
5// Output: ["entertainment", "transport"]
6
7// Step 1: Think aloud — "I need to group by category, sum amounts,
8// then find top K. I'll use a HashMap + heap."
9
10// Step 2: State complexity — O(n + m log k) where n=transactions, m=categories
11
12// Step 3: Code
13fun topKCategories(transactions: List<Pair<String, Int>>, k: Int): List<String> {
14 // Group by category and sum
15 val categoryTotals = transactions
16 .groupBy { it.first }
17 .mapValues { (_, txns) -> txns.sumOf { it.second } }
18
19 // Use min-heap of size k for top-K
20 val minHeap = PriorityQueue<Pair<String, Int>>(compareBy { it.second })
21 for ((category, total) in categoryTotals) {
22 minHeap.offer(category to total)
23 if (minHeap.size > k) minHeap.poll()
24 }
25
26 // Extract results in descending order
27 return minHeap.sortedByDescending { it.second }.map { it.first }
28}
29
30// Step 4: Test
31// transactions = [("food",50), ("transport",30), ("food",20),
32// ("entertainment",100), ("transport",40)]
33// categoryTotals = {food:70, transport:70, entertainment:100}
34// After heap with k=2: [transport:70, entertainment:100]
35// Result: ["entertainment", "transport"] ✓
36
37// Step 5: Edge cases
38// - Empty list → return empty
39// - K > number of categories → return all categories
40// - Tie in amounts → either is acceptable
41
42// SIMULATION: Round 1, Problem B
43// "Find all paths in binary tree that sum to target"
44fun pathSum(root: TreeNode?, target: Int): List<List<Int>> {
45 val result = mutableListOf<List<Int>>()
46
47 fun dfs(node: TreeNode?, remaining: Int, path: MutableList<Int>) {
48 if (node == null) return
49 path.add(node.value)
50 if (node.left == null && node.right == null && remaining == node.value) {
51 result.add(path.toList())
52 }
53 dfs(node.left, remaining - node.value, path)
54 dfs(node.right, remaining - node.value, path)
55 path.removeAt(path.lastIndex) // Backtrack
56 }
57
58 dfs(root, target, mutableListOf())
59 return result
60}
61// Time: O(n), Space: O(h) where h = tree height

🏋️ Practice Exercise

Timed Simulation Rounds (do these with a timer!):

Simulation 1 (45 min): A. Merge two sorted arrays in-place (the first array has enough space) B. Find the longest palindromic substring in a string

Simulation 2 (45 min): A. Group anagrams from a list of strings B. Find the minimum window substring containing all characters of another string

Simulation 3 (45 min): A. Implement a stack that supports push, pop, and getMin in O(1) B. Serialize and deserialize a binary tree

Simulation 4 (45 min): A. Find all unique combinations that sum to a target (each number used once) B. Implement LRU Cache with O(1) get and put

Self-evaluation after each simulation: □ Identified the pattern within 3 minutes □ Discussed approach before coding □ Code compiles and runs correctly □ Handled at least 2 edge cases □ Stayed within 45 minutes □ Communicated clearly throughout

⚠️ Common Mistakes

  • Using an IDE with autocomplete — Google interviews use simple editors without help

  • Not timing yourself strictly — if you go over 45 min, it's a failed simulation

  • Skipping the think-aloud step — in real interviews, silence is a negative signal

  • Not testing your code — always walk through at least one example after coding

💼 Interview Questions

🎤 Mock Interview

Mock interview is powered by AI for Coding Round Simulations. Login to unlock this feature.