Debug Tensor Conversion Bugs
Company: Waymo
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates debugging and implementation-level skills in tensor and array manipulation, focusing on aliasing behavior, conversion between column lists and ndarrays, correct handling of non-divisible chunking, and writing tests for these issues.
Constraints
- 0 <= rows, cols <= 200
- 0 <= len(updates) <= rows * cols
- All update indices are valid for the created matrix
- All lists in `columns` have the same length
- 1 <= chunk_size
- `arr` is a rectangular 2D list
Examples
Input: (2, 3, [(0, 1, 7)], [[1, 2], [3, 4], [5, 6]], [[1, 2], [3, 4], [5, 6]], 2)
Expected Output: [[[0, 7, 0], [0, 0, 0]], [[1, 3, 5], [2, 4, 6]], [[1, 2], [3, 4]], [[5, 6]]]
Explanation: Updating row 0 must not affect row 1. The three input lists become columns of a 2x3 array, and the 3-row array is split into chunks of sizes 2 and 1.
Input: (3, 2, [(1, 0, 5)], [[9], [8]], [[10, 11], [12, 13], [14, 15], [16, 17]], 3)
Expected Output: [[[0, 0], [5, 0], [0, 0]], [[9, 8]], [[10, 11], [12, 13], [14, 15]], [[16, 17]]]
Explanation: Only the middle row should change, which catches the shared-row aliasing bug. The converted array has shape 1x2, and the last row remains in its own chunk.
Input: (1, 1, [(0, 0, 1)], [], [], 4)
Expected Output: [[[1]], []]
Explanation: This edge case has no columns and an empty array to chunk. The converted 2D array is empty, and no chunks are produced.
Input: (2, 2, [(0, 0, -1), (1, 1, 3)], [[-1, 0, 1], [2, 2, 2]], [[7], [8]], 1)
Expected Output: [[[-1, 0], [0, 3]], [[-1, 2], [0, 2], [1, 2]], [[7]], [[8]]]
Explanation: Negative values are allowed in updates. Chunk size 1 means every row of `arr` becomes its own chunk.
Hints
- Using `[[0] * cols] * rows` creates multiple references to the same inner list. Build each row separately.
- If the inputs are columns, build the converted array row by row using the same index from each column. For chunking, iterate from 0 to `len(arr)` in steps of `chunk_size`.