How to count the number of times sorted array with distinct integers are circularly rotated in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function countRotations(ByVal arr As Integer()) As Integer
        Dim min As Integer = arr(0), min_index As Integer = 0
        Dim size As Integer = arr.Length

        For i As Integer = 0 To size - 1
            If min > arr(i) Then
                min = arr(i)
                min_index = i
            End If
        Next

        Return min_index
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = New Integer() {23, 19, 15, 4, 6, 8, 9, 11}
	
        Console.Write(countRotations(arr))
    End Sub
End Class



' run:
'
' 3
'

 



answered Nov 21, 2023 by avibootz
...