Leetcode 1380: Lucky Numbers in a Matrix

grid47
grid47
Exploring patterns and algorithms
Jun 22, 2024 6 min read

You are given a matrix of distinct numbers with dimensions m x n. A lucky number in the matrix is an element that is the minimum value in its row and the maximum value in its column. Your task is to find and return all such lucky numbers.
Problem
Approach
Steps
Complexity
Input: The input consists of a 2D matrix of distinct integers.
Example: matrix = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
Constraints:
• The matrix will have dimensions m x n where 1 <= m, n <= 50.
• All elements in the matrix are distinct.
Output: Return a list of all lucky numbers in the matrix.
Example: [70]
Constraints:
• The output should include all lucky numbers.
Goal: The goal is to identify and return all lucky numbers in the matrix, where each lucky number is the minimum in its row and maximum in its column.
Steps:
• Find the minimum value in each row.
• Find the maximum value in each column.
• Identify the values that are both the minimum in their row and the maximum in their column.
Goal: The solution should efficiently handle matrices with sizes up to 50 x 50.
Steps:
• The matrix will have at least one element.
• The elements of the matrix are distinct.
Assumptions:
• Each element in the matrix is distinct.
Input: matrix = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
Explanation: In this example, 70 is the only lucky number because it is the minimum in its row and the maximum in its column.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus