1198. Find Smallest Common Element in All Rows

Problem

Find the smallest common element in all rows of a sorted integer matrix, or -1 if none.

Given a matrix mat with n rows where each row is sorted in ascending order, find the smallest element that appears in all rows. If no such element exists, return -1.

Each row contains unique elements within that row (sorted ascending), but the same element can appear in multiple rows.

Examples
Input: [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]
Output: 5
Hints
Related Problems

1198. Find Smallest Common Element in All Rows

Find the smallest common element in all rows of a sorted integer matrix, or -1 if none.