LC: 1198. Find Smallest Common Element in All Rows - spiralgo/algorithms GitHub Wiki

1198. Find Smallest Common Element in All Rows:

The Essence:

The first row of this matrix must contain the smallest value. We need to incrementally search this elements starting from the smallest one at the first index. Thus we should search if all other sorted rows of the matrix contains this value.

Details:

Since all the rows are sorted, we can apply binary searching to check if the element is present in a row. Finding the first number satisfying the needed conditions is enough, since its going to be the smallest.