
Asked in Publicis Sapient
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...
Top Software Developer Interview Questions Asked at Publicis Sapient
Q. What are the SOLID principles?
Q. What are extension methods?
Q. What is the difference between a List and a Tuple?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Publicis Sapient Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

