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]]
Output:1
Input:[[1],[2]]
Output:-1
Hints
Since all rows are sorted, use a pointer-based approach similar to merging k sorted lists.
Use a hash map to count occurrences across rows.
Since values can be up to 10^5, use an array of size 10^5+1 for O(m*n) counting.