Maximum 1s in a Row Problem
Given a matrix ARR
with dimensions N
* M
, consisting only of 0s and 1s where each row is sorted, determine the index of the row that contains the highest number of 1s. If multiple rows contain the same number of 1s, return the index of the first such row.
Input:
The first line of input includes an integer ‘T’, representing the number of test cases.
For each test case, the first line consists of two space-separated integers ‘N’ and ‘M’, indicating the number of rows and columns respectively.
The following N lines each contain M elements representing the rows of the matrix.
Output:
For each test case, output the index of the row with the maximum number of 1's. In case of a tie, return the smallest index.
Each result should be on a separate line.
Example:
Suppose we have 1 test case
Input:
3 4
0 1 1 1
0 0 1 1
1 1 1 1
Output:
2
Explanation:
The third row (zero-indexed) has the maximum number of 1s (4 ones).
Constraints:
1 <= T <= 1000
1 <= N, M <= 500
- Each row in the matrix is sorted
- Time Limit: 1 sec

AnswerBot
4mo
Find the row with the maximum number of 1s in a sorted matrix.
Iterate through each row of the matrix and count the number of 1s in each row
Keep track of the row index with the maximum number of 1s
Retu...read more
Help your peers!
Add answer anonymously...
Publicis Sapient Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. What are the SOLID principles?
A Software Developer was asked Q. What is the difference between a List and a Tuple?
A Software Developer was asked Q. What are extension methods?
Popular interview questions of Software Developer
A Software Developer was asked 10mo agoQ1. What are the SOLID principles?
A Software Developer was asked Q2. What are extension methods?
A Software Developer was asked Q3. Given the head of a singly linked list, reverse the list, and return the reverse...read more
Top HR questions asked in Publicis Sapient Software Developer
A Software Developer was asked 9mo agoQ1. When can you join the department?
A Software Developer was asked 9mo agoQ2. How do you handle pressure?
A Software Developer was asked Q3. What are your weaknesses?
>
Publicis Sapient Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

