using System;
public class Program
{
private static int FindRowWithMaximumOnes(int[][] matrix) {
if (matrix.Length == 0) {
return -1;
}
int rows = matrix.Length;
int cols = matrix[0].Length;
int row_index = -1;
int i = 0;
int j = cols - 1;
while (i <= rows - 1 && j >= 0) {
if (matrix[i][j] != 0) {
j--;
row_index = i;
}
else {
i++; // next row
}
}
return row_index;
}
public static void Main(string[] args)
{
int[][] matrix = new int[][]
{
new int[] {0, 0, 0, 0, 1, 1},
new int[] {0, 0, 1, 1, 1, 1},
new int[] {0, 0, 0, 0, 0, 0},
new int[] {0, 1, 1, 1, 1, 1},
new int[] {0, 0, 0, 1, 1, 1}
};
Console.Write("Row index = " + FindRowWithMaximumOnes(matrix));
}
}
/*
run:
Row index = 3
*/