Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Problem 3: Row With Maximum Ones(easy)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a binary matrix that has dimensions m * n, consisting of ones and zeros, determine the row that contains the highest number of ones and return two values: the zero-based index of this row and the actual count of ones it possesses.

If there is a tie, i.e., multiple rows contain the same maximum number of ones, we must select the row with the lowest index.

Examples

Example 1:

  • Input: [[1, 0], [1, 1], [0, 1]]
  • Expected Output: [1, 2]
  • Justification: The second row [1, 1] contains the most ones, so the output is [1, 2].

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible