Row With Maximum Ones

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.
In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.
Return an array containing the index of the row, and the number of ones in it.
LeetCode Problem - 2643
class Solution {
// Method to find the row with the maximum number of ones and the count of ones in that row
public int[] rowAndMaximumOnes(int[][] mat) {
int rowNum = 0; // To store the row number with the maximum ones
int count = 0; // To store the maximum count of ones
// Iterate through each row of the matrix
for(int i = 0; i < mat.length; i++){
int tempCount = 0; // Temporary count of ones for the current row
// Iterate through each element in the row
for(int j = 0; j < mat[0].length; j++){
// Increment the count if the element is 1
if(mat[i][j] == 1){
tempCount++;
}
}
// Update the maximum count and row number if the current row has more ones
if(tempCount > count){
count = tempCount;
rowNum = i;
}
}
// Create an array to store the result
int[] ans = new int[2];
ans[0] = rowNum; // The row number with the maximum ones
ans[1] = count; // The count of ones in that row
// Return the result
return ans;
}
}




