Problem 337244 · easy · Phase 03 Linear Management & Searching

Row With the Most Filled Seats

matrix · binary search · sorted rows

A cinema seating chart is an m x n grid seats of 0 (free) and 1 (taken). Because seats are sold from the aisle inwards, every row consists of some zeros followed by some ones. Return [row, count] for the row with the most taken seats; when several rows tie, choose the smallest row index.

Examples

Input:  seats = [[0, 0, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]]
Output: [1, 3]

Input:  seats = [[0, 0], [0, 0]]
Output: [0, 0]

Constraints

  • 1 <= m, n <= 500
  • Target: O(m * log n) or O(m + n) time.

Goals

  • Count the ones in a sorted binary row without scanning it
  • Break ties towards the smaller row index
  • Return a two-element result
Starting Python…