Problem 268064 · easy · Level 02 Linear Data Structures

Saddle Points on the Survey Grid

2d-lists · min · max · sets

A surveyor's grid grid holds spot heights, all distinct. A cell is a saddle point (a lucky value, as the function calls it) when it is the lowest reading in its own row and the highest reading in its own column, like the lowest point of a mountain pass seen along one direction and the highest seen along the other. Return the values of all saddle points in increasing order, or an empty list if the grid has none.

Examples

Input:  grid = [[4, 9, 6],
                [12, 14, 13],
                [2, 5, 1]]
Output: [12]
Explanation: 12 is the minimum of its row and the maximum of its column.

Input:  grid = [[2, 4],
                [7, 9]]
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…