Imports System
Public Class Program
Public Shared Function maxSubArray(ByVal arr As Integer()) As Integer
Dim maxSum As Integer = Integer.MinValue
Dim currentSum As Integer = 0
Dim size As Integer = arr.Length
For i As Integer = 0 To size - 1
currentSum = Math.Max(arr(i), currentSum + arr(i))
maxSum = Math.Max(currentSum, maxSum)
Next
Return maxSum
End Function
Public Shared Sub Main(ByVal args As String())
' 4 + -1 + -1 + 2 + 3 = 7
Dim arr As Integer() = New Integer() {1, -2, 2, -3, 4, -1, -1, 2, 3, -5, 4}
Console.WriteLine(maxSubArray(arr))
End Sub
End Class
' run:
'
' 7
'