Problem 283911 · easy · Level 02 Linear Data Structures

Where Is the Row Maximum?

2d-lists · max · indexing

Given a grid of integers grid, return a list with one entry per row: the column index of the largest value in that row. If a row contains its maximum more than once, use the smallest such index.

Examples

Input:  grid = [[3, 9, 9],
                [5, 1, 2],
                [0, 0, 0]]
Output: [1, 0, 0]
Explanation: row 0 peaks first at column 1, row 1 at column 0, row 2 is all ties so column 0.

Input:  grid = [[4]]
Output: [0]

Constraints

  • 1 <= rows, cols <= 100
  • -10**6 <= grid[r][c] <= 10**6

Goals

  • Find the position of a maximum rather than its value
  • Break ties by the smallest index
Starting Python…