' check adjacent array elements to determine if the array is monotone increasing (or decreasing)
Imports System
Public Class Program
Public Shared Function isMonotonic(ByVal array As Integer()) As Boolean
Dim increase As Integer = 0, decrease As Integer = 0
Dim size As Integer = array.Length
For i As Integer = 0 To size - 1 - 1
If array(i) > array(i + 1) Then
increase = 1
End If
If array(i) < array(i + 1) Then
decrease = 1
End If
If increase = 1 AndAlso decrease = 1 Then
Return False
End If
Next
Return True
End Function
Public Shared Sub Main(ByVal args As String())
Dim array As Integer() = New Integer() {1, 3, 4, 6, 8, 9, 11, 17, 18}
Console.WriteLine(isMonotonic(array))
End Sub
End Class
' run:
'
' True
'