less than 1 minute read

You are given a two-dimensional list of integers matrix where each row is sorted in ascending order. Return the smallest number that exists in every row. If there’s no solution, return -1.

Constraints

  • n, m ≤ 250 where n and m are the number of rows and columns in matrix

https://binarysearch.com/problems/Smallest-Intersecting-Element

Examples

Example 1

Input

  • matrix =
[[1,2,4],
 [4,9,9],
 [0,2,4]]

Output

  • answer = 4

Solution

Leave a comment