Imports System
Public Class Program
Public Shared Function FindRowWithMaximumOnes(ByVal matrix As Integer()()) As Integer
If matrix.Length = 0 Then
Return -1
End If
Dim rows As Integer = matrix.Length
Dim cols As Integer = matrix(0).Length
Dim row_index As Integer = -1
Dim i As Integer = 0
Dim j As Integer = cols - 1
While i <= rows - 1 AndAlso j >= 0
If matrix(i)(j) <> 0 Then
j -= 1
row_index = i
Else
i += 1
End If
End While
Return row_index
End Function
Public Shared Sub Main(ByVal args As String())
Dim matrix As Integer()() = New Integer()() {
New Integer() {0, 0, 0, 0, 1, 1},
New Integer() {0, 0, 1, 1, 1, 1},
New Integer() {0, 0, 0, 0, 0, 0},
New Integer() {0, 1, 1, 1, 1, 1},
New Integer() {0, 0, 0, 1, 1, 1}}
Console.Write("Row index = " & FindRowWithMaximumOnes(matrix))
End Sub
End Class
' run:
'
' Row index = 3
'