The Find Smallest Common Element in All Rows interview question asks you to find the smallest integer that appears in every single row of an matrix. If no such element exists, return -1. Each row is typically sorted in strictly increasing order.
Companies like Microsoft and Amazon ask this to evaluate your proficiency with Matrix interview patterns and Binary Search. It evaluations if you can leverage the "sorted rows" property to optimize the search from to something faster, or use a frequency map for a simple linear approach.
There are three common ways to solve this:
Matrix:
1 2 3 4
2 3 5 8
2 4 5 6
1. Is it in Row 1? No.2. Is it in Row 1? Yes. Is it in Row 2? Yes.
Result: 2.Whenever you have "multiple sorted lists" and need to find an intersection, think about the Pointers approach or Binary Search. This is a fundamental Array interview pattern that appears in many variations (like "Intersection of Three Sorted Arrays").
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Operations to Write the Letter Y on a Grid | Medium | Solve | |
| Intersection of Three Sorted Arrays | Easy | Solve | |
| Flip Columns For Maximum Number of Equal Rows | Medium | Solve | |
| Tuple with Same Product | Medium | Solve | |
| Check If Array Pairs Are Divisible by k | Medium | Solve |