Imports System
Module ShortestRunProgram
Function shortest_identical_consecutive_subarray(arr As Integer()) As Integer()
If arr.Length = 0 Then
Return Array.Empty(Of Integer)()
End If
Dim bestStart As Integer = 0
Dim bestLen As Integer = arr.Length
Dim currentStart As Integer = 0
Dim currentLen As Integer = 1
For i As Integer = 1 To arr.Length - 1
If arr(i) = arr(i - 1) Then
currentLen += 1
Else
If currentLen < bestLen Then
bestLen = currentLen
bestStart = currentStart
End If
currentStart = i
currentLen = 1
End If
Next
If currentLen < bestLen Then
bestLen = currentLen
bestStart = currentStart
End If
Dim resultArr(bestLen - 1) As Integer
Array.Copy(arr, bestStart, resultArr, 0, bestLen)
Return resultArr
End Function
' ------------------------------------------------------------
' MAIN PROGRAM
' ------------------------------------------------------------
Sub Main()
Dim arr As Integer() = {3, 3, 3,
7, 7, 7, 7, 7,
2, 2,
5, 5, 5, 5,
9, 9, 9, 9, 9, 9}
Dim resultArr = shortest_identical_consecutive_subarray(arr)
Console.Write("Array result: ")
For Each x In resultArr
Console.Write(x & " ")
Next
End Sub
End Module
' run:
'
' Array result: 2 2
'