Problem 299267 · medium · Level 02 Linear Data Structures

Book Adjacent Seats

2d-lists · runs · search

A cinema hall is a grid seats where 0 is a free seat and 1 is taken. A group wants k seats next to each other in the same row. Return [row, col] for the leftmost seat of the first suitable run, scanning rows from top to bottom and, within a row, from left to right. Return None if no row has k consecutive free seats.

Examples

Input:  seats = [[1, 0, 0, 1],
                 [0, 0, 0, 0]], k = 2
Output: [0, 1]

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

Input:  seats = [[1, 0, 0, 1],
                 [0, 0, 0, 0]], k = 5
Output: None

Constraints

  • 1 <= rows, cols <= 100, 1 <= k <= 100

Goals

  • Find a run of consecutive free cells within a row
  • Return the first match in row-major order or None
Starting Python…