17. Parking Lot Busiest Row
Difficulty: easy · Matrix
Problem
A mall parking lot has `R` rows and `C` columns of parking spaces. Each space is either empty (`0`) or occupied (`1`), given as an `R x C` matrix. Find the row with the most occupied spaces and print its row number (rows are numbered from 1). If several rows tie for the maximum, print the smallest row number.
Input
- Line 1: the integer `R`. - Line 2: the integer `C`. - Next `R` lines: `C` space-separated values (each `0` or `1`) for that row.
Output
Print the 1-based index of the row with the most `1`s.
Example 1
Input: 3 3 0 1 0 1 1 0 1 1 1 Output: 3
Explanation: Row sums are 1, 2 and 3; row 3 has the most occupied spaces.
Example 2
Input: 4 3 0 1 0 1 1 0 1 0 1 1 1 1 Output: 4
Explanation: Row sums are 1, 2, 2, 3; row 4 is the busiest.
Example 3
Input: 2 2 1 1 1 1 Output: 1
Explanation: Both rows have 2 occupied spaces; the smaller row number, 1, is printed.
Constraints
- 1 <= R, C <= 500 - Every matrix element is 0 or 1
Solutions are judged against 3 sample and 10 hidden tests. Sign in to solve it · All problems