using
System;
class
GFG
{
static
int
R = 4;
static
int
C = 4;
static
int
first(
int
[]arr,
int
low,
int
high)
{
if
(high >= low)
{
int
mid = low + (high - low) / 2;
if
((mid == 0 || arr[mid - 1] == 0) && arr[mid] == 1)
return
mid;
else
if
(arr[mid] == 0)
return
first(arr, (mid + 1), high);
else
return
first(arr, low, (mid - 1));
}
return
-1;
}
static
void
rowWith0s(
int
[,]mat)
{
int
max_row_index = 0, max =
int
.MinValue;
int
min_row_index = 0, min =
int
.MaxValue;
int
i, index;
for
(i = 0; i < R; i++)
{
index = first(GetRow(mat,i), 0, C - 1);
int
cntZeroes = 0;
if
(index == -1)
{
cntZeroes = C;
}
else
{
cntZeroes = index;
}
if
(max < cntZeroes)
{
max = cntZeroes;
max_row_index = i;
}
if
(min > cntZeroes)
{
min = cntZeroes;
min_row_index = i;
}
}
Console.WriteLine (
"Row with min 0s: "
+ (min_row_index + 1));
Console.WriteLine (
"Row with max 0s: "
+ (max_row_index + 1));
}
public
static
int
[] GetRow(
int
[,] matrix,
int
row)
{
var
rowLength = matrix.GetLength(1);
var
rowVector =
new
int
[rowLength];
for
(
var
i = 0; i < rowLength; i++)
rowVector[i] = matrix[row, i];
return
rowVector;
}
public
static
void
Main (String[] args)
{
int
[,]mat = { { 0, 0, 0, 1 },
{ 0, 1, 1, 1 },
{ 1, 1, 1, 1 },
{ 0, 0, 0, 0 } };
rowWith0s(mat);
}
}