← General Motors Interview Insights

General Motors·Machine Learning Engineer·Technical Phone Screen·Intermediate

IntermediateRejected
Apr 2026

Summary

Did a coding round for an ML Engineer role at General Motors. Got a graph traversal problem, there was a deliberate bug in the starter code, and I had to write my own test cases to track it down. Found it, thought it went okay, then got a rejection a week later.

Questions Asked (1)

Q1

Given a 2D grid, count the number of islands using only horizontal and vertical movement (no diagonals). The provided code had a bug in it; write your own test cases to find and fix it.

Algorithms & Data StructuresRoot Cause Analysis
Author's notes

The base problem is basically number of islands, BFS or DFS, nothing surprising.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, explain the standard algorithm for counting islands using BFS/DFS with a visited set, then describe how you would systematically test the provided buggy code with edge cases to identify the bug. Finally, explain the fix and how you would verify it with additional tests.

Pro tip: Demonstrate a methodical debugging process: start with simple cases (e.g., empty grid, single cell) and gradually increase complexity, using print statements or a debugger to trace the code's behavior. This shows you can not only solve the problem but also diagnose and fix real-world code.

1. Understand the problem and constraints

Clarify the definition of an island (connected component of 1s using 4-directional adjacency) and any constraints (grid size, input format). Confirm that diagonal connections are not considered.

2. Outline the standard solution

Describe the BFS/DFS approach: iterate through each cell; when a '1' is found and not visited, increment island count and traverse all connected '1's, marking them visited.

3. Design test cases to expose bugs

Create a set of test cases covering edge cases: empty grid, all water, all land, single row/column, multiple islands, islands touching diagonally, and larger grids. Run the provided code on these tests to observe incorrect outputs.

4. Identify and fix the bug

Based on test failures, trace the code to locate the bug (e.g., incorrect boundary checks, missing visited marking, wrong traversal order). Explain the fix and why it resolves the issue.

5. Verify the fix with additional tests

Re-run all test cases to ensure the fix works and doesn't introduce new issues. Optionally, discuss time/space complexity and potential optimizations.

Key Points to Mention

  • Definition of an island: connected component of 1s using 4-directional adjacency (up, down, left, right).
  • Standard algorithm: BFS/DFS with a visited set or in-place modification to avoid revisiting cells.
  • Edge cases to test: empty grid, all 0s, all 1s, single row/column, multiple islands, diagonal-only connections.
  • Debugging techniques: unit tests, print statements, debugger, and comparing expected vs. actual outputs.
  • Common bugs: off-by-one errors in boundary checks, forgetting to mark visited cells, incorrect traversal directions.
  • Complexity analysis: O(rows * cols) time and space (for visited set or recursion stack).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.