Problem 268064 · easy · Phase 02 Linear Data Structures

Lucky Cells

2d-lists · min · max · sets

A value in a grid is lucky when it is the smallest value in its row and the largest value in its column. Given a grid of distinct integers grid, return all lucky values in increasing order (an empty list if there are none).

Examples

Input:  grid = [[3, 7, 8],
                [9, 11, 13],
                [15, 16, 17]]
Output: [15]
Explanation: 15 is the minimum of its row and the maximum of its column.

Input:  grid = [[7, 8],
                [1, 2]]
Output: [7]

Constraints

  • 1 <= rows, cols <= 100
  • All values are distinct.

Goals

  • Compute per-row minima and per-column maxima
  • Intersect two collections of candidates
Starting Python…