Meta·Machine Learning Engineer·Technical Phone Screen
- Given an m x n integer matrix, check whether every top-left to bottom-right diagonal contains identical values (the Toeplitz property). Return true or false, analyze time and space complexity, and explain how you'd handle the case where rows arrive one at a time as a stream.
- Design a data structure that tracks the moving average of the last k values from a real-time number stream. It should support push and query operations in amortized O(1) time and O(k) space. Also address numerical precision, potential overflow, and what happens when fewer than k elements have been pushed.
- Given an array and a window size k, return the median of each sliding window as it moves across the array. Aim for O(n log k) time or better. Walk through your data structure choices, how you handle duplicates and even-length windows, and discuss any memory trade-offs.
“The base matrix check was fine, just compare each cell to its upper-left neighbor and you're done in O(m*n) time.”