Search⌘ K
AI Features

Solution: Lucky Numbers in a Matrix

Explore how to determine lucky numbers in a matrix, defined as values that are the smallest in their row and largest in their column. This lesson guides you through implementing a greedy algorithm with O(m × n) time complexity and minimal space usage, helping you solve this unique problem using clear, step-by-step logic.

Statement

Given an m×nm \times n matrix of distinct numbers, return the lucky number in the matrix.

lucky number is an element of the matrix such that it is the smallest element in its row and largest in its column.

Constraints:

  • m=m = matrix.length

  • n=n = ...