Leetcode Problem 1198. Find Smallest Common Element in All Rows

1198. Find Smallest Common Element in All Rows

Leetcode Solutions

Approach: Count Elements

  1. Initialize an array count of size 10001 with all elements set to 0.
  2. Iterate through each row of the matrix.
    • For each element in the row, increment the corresponding index in the count array.
  3. Iterate through the count array starting from index 1.
    • If count[i] equals the number of rows, return i as the smallest common element.
  4. If no common element is found, return -1.
UML Thumbnail

Approach: Row Positions

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...