You're given an m x n matrix where each row is sorted in strictly increasing order. Your task is to find the smallest element that appears in every single row of the matrix.
Think of it like finding a common favorite among different groups - you need an element that shows up in all rows, and if there are multiple such elements, you want the smallest one.
Example: If you have a matrix like [[1,2,3,4],[2,3,4,5],[3,4,5,6]], the elements that appear in all rows are [3,4], so you should return 3 since it's the smallest.
If no element appears in all rows, return -1.
The key insight here is leveraging the fact that each row is already sorted - this gives us multiple optimization opportunities!
Input & Output
Constraints
-
m == mat.length -
n == mat[i].length -
1 โค m, n โค 1000 -
1 โค mat[i][j] โค 104 - Each row is sorted in strictly increasing order