Given an array Arr of length N. Determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its right. If there are no elements to the left/right, then the sum is considered to be zero. 
Formally, find an i, such that, Arr_{1 }+ Arr_{2 }... Arr_{i-1} = Arr_{i+1 }+ Arr_{i+2 }... Arr_{N}.
Example 1:
Input:
N = 4
Arr[] = {1, 2, 3, 3}
Output: YES
Explanation: Consider i = 3, for [1, 2] 
sum is 3 and for [3] sum is also 3.
Example 2:
Input:
N = 2
Arr[] = {1, 5}
Output: NO
Explanation: No such index present.
Your Task:
Complete the function equilibrium() which takes array arr and size n, as input parameters and returns a string representing the answer(YES or NO). You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5} 
1 ≤ Arr[i] ≤ 10^{6}

Difficulty: MEDIUM
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3
class Solution:

	def equilibrium(self,arr, n): 
    	# code here

Solutions:
class Solution:

	def equilibrium(self, arr, n):
		s = sum(arr)
		pre_sum = 0
		for i in range(n):
			if pre_sum == s - pre_sum - arr[i]:
				return 'YES'
			pre_sum += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		left_arr = [0] * n
		left_arr[0] = arr[0]
		right_arr = [0] * n
		right_arr[n - 1] = arr[n - 1]
		for i in range(1, n):
			left_arr[i] = arr[i] + left_arr[i - 1]
		for i in range(n - 2, -1, -1):
			right_arr[i] = right_arr[i + 1] + arr[i]
		for i in range(n):
			if left_arr[i] == right_arr[i]:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		leftArr = [0] * n
		leftArr[0] = arr[0]
		for i in range(1, n):
			leftArr[i] = arr[i] + leftArr[i - 1]
		rightArr = [0] * n
		rightArr[n - 1] = arr[n - 1]
		for i in range(n - 2, -1, -1):
			rightArr[i] = arr[i] + rightArr[i + 1]
		for i in range(n):
			if leftArr[i] == rightArr[i]:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		s = sum(arr)
		ls = 0
		for i in arr:
			s = s - i
			if ls == s:
				return 'YES'
				break
			ls = ls + i
		else:
			return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		left = 0
		right = sum(arr)
		for i in arr:
			right -= i
			if left != right:
				left += i
			else:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		leftsum = 0
		rightsum = sum(arr)
		for i in range(n):
			rightsum -= arr[i]
			if leftsum == rightsum:
				return 'YES'
			leftsum += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		left = [0] * n
		right = [0] * n
		left[0] = arr[0]
		for i in range(1, n):
			left[i] = left[i - 1] + arr[i]
		right[n - 1] = arr[n - 1]
		for i in range(n - 2, -1, -1):
			right[i] = right[i + 1] + arr[i]
		for i in range(n):
			if left[i] == right[i]:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		s = 0
		leftsum = 0
		for i in range(n):
			s += arr[i]
		for j in range(n):
			if s - leftsum - arr[j] == leftsum:
				return 'YES'
			leftsum += arr[j]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		summ = 0
		for i in range(n):
			summ += arr[i]
		lsumm = 0
		for i in range(n):
			lsumm += arr[i]
			if lsumm - arr[i] == summ - lsumm:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		l = sum(arr)
		r = 0
		i = n - 1
		while i >= 0:
			l -= arr[i]
			if l == r:
				return 'YES'
			else:
				i -= 1
				r += arr[i + 1]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		f_sum = 0
		l_sum = 0
		for i in range(n):
			f_sum += arr[i]
		for i in range(n):
			l_sum += arr[i]
			if l_sum == f_sum:
				return 'YES'
			f_sum -= arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		k = sum(arr)
		p = 0
		for i in arr:
			k = k - i
			if k == p:
				return 'YES'
			p = p + i
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		before = 0
		after = sum(arr)
		for i in arr:
			after -= i
			if before == after:
				return 'YES'
			before += i
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		ts = sum(arr)
		ls = 0
		for i in arr:
			ts = ts - i
			if ts == ls:
				return 'YES'
			ls = ls + i
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		for i in range(n):
			li = []
			su = 0
			ls = 0
			s1 = 'YES'
			s2 = 'NO'
			rs = 0
			for i in range(len(arr)):
				su = su + arr[i]
				li.append(su)
			for i in range(n):
				ls = li[i] - arr[i]
				rs = li[n - 1] - li[i]
				if ls == rs:
					return s1
			return s2


class Solution:

	def equilibrium(self, arr, n):
		total = sum(arr)
		left = 0
		for (i, num) in enumerate(arr):
			total -= num
			if left == total:
				return 'YES'
			left += num
		return 'NO'


class Solution:

	def equilibrium(self, a, n):
		total = sum(a)
		s = 0
		for i in range(n - 1):
			s += a[i]
			if s == (total - a[i + 1]) / 2:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		sumVal = sum(arr)
		ans = 0
		prev = 0
		for i in range(1, n):
			ans += arr[i - 1]
			sumVal -= arr[i - 1]
			sumVal -= arr[i]
			if ans == sumVal:
				return 'YES'
			sumVal += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, A, n):
		(S, L) = (sum(A), 0)
		for i in range(n):
			if L == S - (L + A[i]):
				return 'YES'
			L += A[i]
		return 'NO'


class Solution:

	def equilibrium(self, A, n):
		from itertools import accumulate
		F = [0] * (n + 1)
		F[1:] = accumulate(A)
		for i in range(n):
			(L, R) = (F[i], F[n] - F[i + 1])
			if L == R:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, a, n):
		s = sum(a)
		x = 0
		for i in a:
			s -= i
			if x == s:
				return 'YES'
			x += i
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		pre = 0
		ls = 0
		for i in range(n):
			pre += arr[i]
		for j in range(n):
			pre = pre - arr[j]
			if ls == pre:
				return 'YES'
			ls += arr[j]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		sumi = sum(arr)
		left = 0
		for i in range(n):
			sumi -= arr[i]
			if sumi == left:
				return 'YES'
			left += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		(suml, sumr) = (0, 0)
		for no in arr:
			sumr += no
		for (i, n) in enumerate(arr):
			sumr -= n
			if suml == sumr:
				return 'YES'
			suml += n
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		for i in range(1, len(arr)):
			arr[i] += arr[i - 1]
		s = arr[-1]
		for i in range(1, len(arr) - 1):
			if arr[i - 1] == s - arr[i]:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		x = sum(arr[1:n])
		y = sum(arr[0:n - 1])
		q = 0
		if x == 0 or y == 0:
			return 'YES'
		else:
			su = sum(arr)
			s = 0
			for i in range(1, n - 1):
				f = su - arr[i - 1] - s
				s = su - f
				k = su - s - arr[i]
				if s == k:
					q = 1
					return 'YES'
					break
			if q != 1:
				return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		(lsum, rsum) = (0, 0)
		for i in arr:
			rsum += i
		for i in arr:
			rsum = rsum - i
			if rsum == lsum:
				return 'YES'
			lsum = lsum + i
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		sum1 = 0
		sum2 = 0
		i = 0
		j = 0
		while i + j < n - 1:
			if arr[i] == 0:
				i += 1
			elif arr[-j - 1] == 0:
				j += 1
			elif sum1 <= sum2:
				sum1 += arr[i]
				i += 1
			else:
				sum2 += arr[-j - 1]
				j += 1
		return 'YES' if sum1 == sum2 else 'NO'


class Solution:

	def equilibrium(self, a, n):
		rs = sum(a)
		ls = 0
		for i in range(len(a)):
			rs = rs - a[i]
			if ls == rs:
				return 'YES'
			ls += a[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		sum1 = sum(arr)
		left_sum = 0
		for i in range(n):
			sum1 -= arr[i]
			if sum1 == left_sum:
				return 'YES'
			left_sum += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		d = dict()
		sum1 = 0
		sum2 = 0
		for i in range(n):
			sum2 = sum2 + arr[i]
		sum2 = sum2 - arr[0]
		d[0] = sum2
		for i in range(1, n):
			sum1 = sum1 + arr[i - 1]
			sum2 = sum2 - arr[i]
			d[i] = sum2 - sum1
		for key in d:
			if d[key] == 0:
				return 'YES'
				break
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		lftsum = 0
		rtsum = 0
		for i in range(1, n):
			rtsum += arr[i]
		i = 0
		j = 1
		while j < n:
			rtsum -= arr[j]
			lftsum += arr[i]
			if rtsum == lftsum:
				return 'YES'
			j += 1
			i += 1
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		size = n
		(right_sum, left_sum) = (0, 0)
		for i in range(1, size):
			right_sum += arr[i]
		(i, j) = (0, 1)
		while j < size:
			right_sum -= arr[j]
			left_sum += arr[i]
			if left_sum == right_sum:
				return 'YES'
			j += 1
			i += 1
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		arr1 = [arr[0]]
		arr2 = [arr[-1]]
		for i in range(1, n):
			arr1.append(arr[i] + arr1[-1])
		arr = arr[::-1]
		for i in range(1, n):
			arr2.append(arr[i] + arr2[-1])
		arr2 = arr2[::-1]
		for i in range(n):
			if arr1[i] == arr2[i]:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		if n == 1:
			return 'YES'
		tot_sum = sum(arr)
		left_sum = 0
		right_sum = tot_sum
		for i in range(n):
			if left_sum == right_sum - arr[i]:
				return 'YES'
			else:
				left_sum += arr[i]
				right_sum -= arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		sum = 0
		ls = 0
		ans = ''
		for i in range(n):
			sum += arr[i]
		for i in range(1, n):
			ls += arr[i - 1]
			rs = sum - ls - arr[i]
			if ls == rs:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		tsum = sum(arr)
		lsum = 0
		for (i, num) in enumerate(arr):
			tsum -= num
			if tsum == lsum:
				return 'YES'
			lsum += num
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		rsum = 0
		lsum = sum(arr) - arr[0]
		if len(arr) > 1:
			for i in range(len(arr) - 1):
				if rsum == lsum:
					return 'YES'
					break
				else:
					rsum += arr[i]
					lsum -= arr[i + 1]
			return 'NO'
		else:
			return 'YES'


class Solution:

	def equilibrium(self, arr, n):
		z = sum(arr)
		i = 1
		c = arr[0]
		while i < n:
			k = z - c - arr[i]
			if k == c:
				return 'YES'
			c += arr[i]
			i += 1
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		(x, y) = (sum(arr), 0)
		for i in range(n):
			x -= arr[i]
			if y == x:
				return 'YES'
			y += arr[i]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		if len(arr) == 0:
			return 'NO'
		s = sum(arr[1:])
		(sl, sr) = (0, s)
		for i in range(1, n):
			sl += arr[i - 1]
			sr -= arr[i]
			if sl == sr:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		half = sum(arr) / 2
		temp = arr[0]
		for i in range(1, n):
			temp += arr[i]
			if temp - arr[i] / 2 == half:
				return 'YES'
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		total_sum = sum(arr)
		prev_sum = 0
		for i in arr:
			if (total_sum - i) / 2 == prev_sum:
				return 'YES'
			prev_sum += i
		else:
			return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		s = sum(arr)
		(i, j) = (0, 0)
		while i < n:
			if j == s - arr[i] - j:
				return 'YES'
			else:
				j += arr[i]
				i += 1
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		tot = sum(arr)
		cur_sum = 0
		for idx in range(0, n):
			if cur_sum == tot - cur_sum - arr[idx]:
				return 'YES'
			if cur_sum > tot - cur_sum - arr[idx]:
				return 'NO'
			cur_sum += arr[idx]
		return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		hash_map = {}
		s = sum(arr)
		pref = 0
		k = 0
		flag = 'NO'
		for i in range(1, len(arr) - 1):
			pref = pref + arr[k]
			k += 1
			right_sum = s - pref - arr[i]
			if pref == right_sum:
				flag = 'YES'
				break
			else:
				flag = 'NO'
		return flag


class Solution:

	def equilibrium(self, arr, n):
		b = sum(arr) - arr[0]
		c = arr[0]
		for i in range(1, n):
			b -= a[i]
			if b == c:
				return 'YES'
			c += a[i]
		else:
			return 'NO'


class Solution:

	def equilibrium(self, arr, n):
		Sum = sum(arr)
		l_sum = 0
		for i in range(n):
			if Sum - arr[i] == l_sum:
				return 'YES'
			else:
				Sum -= arr[i]
				l_sum += arr[i]
		return 'NO'