Find Smallest Common Row Value
SoFiSoftware Engineer · Technical ScreenLast updated
This question evaluates algorithmic problem-solving skills focused on array processing, intersection across multiple sorted sequences, and time/space complexity analysis.
You are given a 2D integer matrix where each row is sorted in strictly increasing order. Return the smallest integer that appears in every row. If no such integer exists, return -1.
Assumptions:
- The matrix contains at least 1 row and 1 column.
- All rows have the same length.
- Values can be negative or positive.
Example: Input: [ [1, 2, 3, 4, 5], [2, 4, 5, 8, 10], [3, 5, 7, 9, 11], [1, 3, 5, 7, 9] ] Output: 5
During the interview, you may also be asked to clarify edge cases and write test methods or unit test cases for your solution.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.