Given a matrix where every row is sorted in increasing order, return the smallest common element in all rows. If there is no common element return -1.
Input: mat = [[1,2,3,4,5,8], [2,4,5,8,10], [3,5,7,8,9,11], [1,3,5,7,8,9]] Output: 5
Hints
How will you keep track of elements common to all rows? How many elements are common to all rows? How will you find the smallest value? As shown, there are a number of possibilities to track. Could the use of a specialized data structure be used to streamline your solution?