Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,709 questions

55,473 answers

573 users

How to find the equilibrium index of an array (sum arr[0 to index - 1] == sum arr[index + 1 to size]) in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Private Shared Function getEquilibriumIndex(ByVal arr As Integer()) As Integer
        Dim sum_arr As Integer = 0
        Dim left_part_sum As Integer = 0
        Dim size As Integer = arr.Length

        For i As Integer = 0 To size - 1
            sum_arr += arr(i)
        Next

        For i As Integer = 0 To size - 1
            sum_arr -= arr(i)

            If left_part_sum = sum_arr Then
                Return i
            End If

            left_part_sum += arr(i)
        Next

        Return -1
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = New Integer() {-9, 2, 5, 8, -7, 4, 1}

        Console.Write("equilibrium index = " & getEquilibriumIndex(arr))
    End Sub
End Class




' run:
'
' equilibrium index = 3
'

 



answered Apr 26, 2023 by avibootz
...