Banana-Leopard/TASTY huggingface dataset:
# Python program to implement delete operation in a
# sorted array
 
# /* Function to delete an element */
 
 
def deleteElement(arr, n, key):
 
    # Find position of element to be deleted
    pos = binarySearch(arr, 0, n - 1, key)
 
    if (pos == -1):
        print("Element not found")
        return n
 
    # Deleting element
    for i in range(pos, n - 1):
        arr[i] = arr[i + 1]
 
    return n - 1
 
# To search a key to be deleted
 
 
def binarySearch(arr, low, high, key):
 
    if (high < low):
        return -1
    mid = (low + high) // 2
 
    if (key == arr[mid]):
        return mid
    if (key > arr[mid]):
        return binarySearch(arr, (mid + 1), high, key)
 
    return binarySearch(arr, low, (mid - 1), key)
 
 
# Driver code
if __name__ == "__main__":
    arr = [10, 20, 30, 40, 50]
 
    n = len(arr)
    key = 30
 
    print("Array before deletion")
 
    for i in range(n):
        print(arr[i], end=" ")
 
    # Function call
    n = deleteElement(arr, n, key)
    print("\n\nArray after deletion")
    for i in range(n):
        print(arr[i], end=" ")
 
# This code is contributed by shubhamsingh10

Time complexity: linear
Space complexity: logn
# This python program tells if there exists a pair in array whose sum results in x.
 
# Function to find and print pair
 
 
def chkPair(A, size, x):
    for i in range(0, size - 1):
        for j in range(i + 1, size):
            if (A[i] + A[j] == x):
                return 1
    return 0
 
 
if __name__ == "__main__":
    A = [0, -1, 2, -3, 1]
    x = -2
    size = len(A)
 
    if (chkPair(A, size, x)):
        print("Yes")
 
    else:
        print("No")
 
    # This code is contributed by rakeshsahni

Time complexity: quadratic
Space complexity: constant
# Python program to check for the sum
# condition to be satisfied
 
 
def hasArrayTwoCandidates(A, arr_size, sum):
 
    # sort the array
    quickSort(A, 0, arr_size-1)
    l = 0
    r = arr_size-1
 
    # traverse the array for the two elements
    while l < r:
        if (A[l] + A[r] == sum):
            return 1
        elif (A[l] + A[r] < sum):
            l += 1
        else:
            r -= 1
    return 0
 
# Implementation of Quick Sort
# A[] --> Array to be sorted
# si  --> Starting index
# ei  --> Ending index
 
 
def quickSort(A, si, ei):
    if si < ei:
        pi = partition(A, si, ei)
        quickSort(A, si, pi-1)
        quickSort(A, pi + 1, ei)
 
# Utility function for partitioning
# the array(used in quick sort)
 
 
def partition(A, si, ei):
    x = A[ei]
    i = (si-1)
    for j in range(si, ei):
        if A[j] <= x:
            i += 1
 
            # This operation is used to swap
            # two variables is python
            A[i], A[j] = A[j], A[i]
 
        A[i + 1], A[ei] = A[ei], A[i + 1]
 
    return i + 1
 
 
# Driver program to test the functions
A = [1, 4, 45, 6, 10, -8]
n = 16
if (hasArrayTwoCandidates(A, len(A), n)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by __Devesh Agrawal__

Time complexity: nlogn
Space complexity: constant
# Python program to check for the sum
# condition to be satisfied
 
 
def binarySearch(A, low, high, searchKey):
    m = 0
    while (low <= high):
        m = (high + low) // 2
        # Check if searchKey is present at mid
        if (A[m] == searchKey):
            return 1
        # If searchKey greater, ignore left half
        if (A[m] < searchKey):
            low = m + 1
        # If searchKey is smaller, ignore right half
        else:
            high = m - 1
    # if we reach here, then element was
    # not present
    return 0
 
 
def checkTwoSum(A, arr_size, sum):
 
    # sort the array
    A.sort()
    l = 0
    r = arr_size-1
 
    #  Traversing all element in an array search for searchKey
    i = 0
    while i < arr_size-1:
        searchKey = sum-A[i]
        # calling binarySearch function
        if(binarySearch(A, i+1, r, searchKey) == 1):
            return 1
        i = i+1
 
    return 0
 
 
# Driver program to test the functions
A = [1, 4, 45, 6, 10, -8]
n = 14
if (checkTwoSum(A, len(A), n)):
    print("Yes")
else:
    print("No")

Time complexity: nlogn
Space complexity: constant
# Python program to find if there are
# two elements with given sum
 
# function to check for the given sum
# in the array
 
 
def printPairs(arr, arr_size, sum):
 
    # Create an empty hash map
    # using an hashmap allows us to store the indices
    hashmap = {}
 
    for i in range(0, arr_size):
        temp = sum-arr[i]
        if (temp in hashmap):
            print('Yes')
            return
        hashmap[arr[i]] = i
    print("No")
 
 
# driver code
A = [1, 4, 45, 6, 10, 8]
n = 16
printPairs(A, len(A), n)
 
# This code will also work in case the array has the same number twice
# and target is the sum of those numbers
# Eg: Array = [4,6,4] Target = 8
 
# This code is contributed by __Achyut Upadhyay__

Time complexity: linear
Space complexity: linear
# Code in Python3 to tell if there
# exists a pair in array whose
# sum results in x.
 
# Function to print pairs
 
 
def printPairs(a, n, x):
 
    rem = []
 
    for i in range(x):
 
        # Initializing the rem
        # values with 0's.
        rem.append(0)
 
    for i in range(n):
        if (a[i] < x):
 
            # Perform the remainder operation
            # only if the element is x, as
            # numbers greater than x can't
            # be used to get a sum x.Updating
            # the count of remainders.
            rem[a[i] % x] += 1
 
    # Traversing the remainder list from
    # start to middle to find pairs
    for i in range(1, x // 2):
        if (rem[i] > 0 and rem[x - i] > 0):
 
            # The elements with remainders
            # i and x-i will result to a
            # sum of x. Once we get two
            # elements which add up to x,
            # we print x and break.
            print("Yes")
            break
 
    # Once we reach middle of
    # remainder array, we have to
    # do operations based on x.
    if (i >= x // 2):
        if (x % 2 == 0):
            if (rem[x // 2] > 1):
 
                # If x is even and we have more
                # than 1 elements with remainder
                # x/2, then we will have two
                # distinct elements which add up
                # to x. if we dont have than 1
                # element, print "No".
                print("Yes")
            else:
                print("No")
        else:
 
            # When x is odd we continue
            # the same process which we
            # did in previous loop.
            if (rem[x // 2] > 0 and
                    rem[x - x // 2] > 0):
                print("Yes")
            else:
                print("No")
 
 
# Driver Code
A = [1, 4, 45, 6, 10, 8]
n = 16
arr_size = len(A)
 
# Function calling
printPairs(A, arr_size, n)
 
# This code is contributed by subhammahato348

Time complexity: linear
Space complexity: constant
# Python 3 program to search an element in an array
# where difference between adjacent elements is atmost k
 
# x is the element to be searched in arr[0..n-1]
# such that all elements differ by at-most k.
def search(arr, n, x, k):
 
    # Traverse the given array starting from
    # leftmost element
    i = 0
    while (i < n):
     
        # If x is found at index i
        if (arr[i] == x):
            return i
 
        # Jump the difference between current
        # array element and x divided by k
        # We use max here to make sure that i
        # moves at-least one step ahead.
        i = i + max(1, int(abs(arr[i] - x) / k))
     
 
    print("number is not present!")
    return -1
 
 
# Driver program to test above function
arr = [2, 4, 5, 7, 7, 6]
x = 6
k = 2
n = len(arr)
print("Element", x, "is present at index",search(arr, n, x, k))
 
# This code is contributed
# by Smitha Dinesh Semwal

Time complexity: linear
Space complexity: constant
# Python 3 program for above approach
import sys
 
# This function prints
# common elements in ar1
 
 
def findCommon(ar1, ar2, ar3, n1,
               n2, n3):
 
    # Initialize starting indexes
    # for ar1[], ar2and
    # ar3[]
    i = 0
    j = 0
    k = 0
 
    # Declare three variables prev1,
    # prev2, prev3 to track
    # previous element
    # Initialize prev1, prev2,
    # prev3 with INT_MIN
    prev1 = prev2 = prev3 = -sys.maxsize - 1
 
    # Iterate through three arrays
    # while all arrays have
    # elements
    while (i < n1 and j < n2 and k < n3):
 
        # If ar1[i] = prev1 and i < n1,
        # keep incrementing i
        while (ar1[i] == prev1 and i < n1-1):
            i += 1
 
        # If ar2[j] = prev2 and j < n2,
        # keep incrementing j
        while (ar2[j] == prev2 and j < n2):
            j += 1
 
        # If ar3[k] = prev3 and k < n3,
        # keep incrementing k
        while (ar3[k] == prev3 and k < n3):
            k += 1
 
        # If x = y and y = z, pr
        # any of them, update
        # prev1 prev2, prev3 and move
        # ahead in each array
        if (ar1[i] == ar2[j] and ar2[j] == ar3[k]):
            print(ar1[i], end=" ")
            prev1 = ar1[i]
            prev2 = ar2[j]
            prev3 = ar3[k]
            i += 1
            j += 1
            k += 1
 
        # If x < y, update prev1
        # and increment i
        elif (ar1[i] < ar2[j]):
            prev1 = ar1[i]
            i += 1
 
        # If y < z, update prev2
        # and increment j
        elif (ar2[j] < ar3[k]):
            prev2 = ar2[j]
            j += 1
 
        # We reach here when x > y
        # and z < y, i.e., z is
        # smallest update prev3
        # and increment k
        else:
            prev3 = ar3[k]
            k += 1
 
 
# Driver code
ar1 = [1, 5, 10, 20, 40, 80, 80]
ar2 = [6, 7, 20, 80, 80, 100]
ar3 = [3, 4, 15, 20, 30, 70, 80, 80, 120]
n1 = len(ar1)
n2 = len(ar2)
n3 = len(ar3)
 
print("Common Elements are ")
findCommon(ar1, ar2, ar3, n1, n2, n3)
 
# This code is contributed by splevel62.

Time complexity: linear
Space complexity: constant
# Python implementation of the approach
def findCommon(a, b, c, n1, n2, n3):
 
    # three sets to maintain frequency of elements
    uset = set()
    uset2 = set()
    uset3 = set()
    for i in range(n1):
        uset.add(a[i])
 
    for i in range(n2):
        uset2.add(b[i])
 
    # checking if elements of 3rd array are present in first 2 sets
    for i in range(n3):
 
        if(c[i] in uset and c[i] in uset2):
 
            # using a 3rd set to prevent duplicates
            if c[i] not in uset3:
                print(c[i], end = " ")
            uset3.add(c[i])
 
# Driver code
ar1 = [ 1, 5, 10, 20, 40, 80 ]
ar2 = [ 6, 7, 20, 80, 100 ]
ar3 = [ 3, 4, 15, 20, 30, 70, 80, 120 ]
n1 = len(ar1)
n2 = len(ar2)
n3 = len(ar3)
 
print("Common Elements are ")
findCommon(ar1, ar2, ar3, n1, n2, n3)
 
# This code is contributed by shinjanpatra.

Time complexity: linear
Space complexity: linear
# Python3 program to find the only
# repeating element in an array where
# elements are from 1 to N-1.
 
 
def findRepeating(arr, N):
    for i in range(N):
        for j in range(i + 1, N):
            if (arr[i] == arr[j]):
                return arr[i]
 
 
# Driver's Code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
  N = len(arr)
 
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed by Arpit Jain

Time complexity: quadratic
Space complexity: constant
# Python3 program to find the only
# repeating element in an array where
# elements are from 1 to N-1.
 
 
def findRepeating(arr, N):
    arr.sort()
    for i in range(1, N):
        if(arr[i] != i+1):
            return arr[i]
 
 
# Driver's Code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
  N = len(arr)
 
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed by Arpit Jain

Time complexity: nlogn
Space complexity: constant
# Python3 program to find the only
# repeating element in an array
# where elements are from 1 to n-1.
 
 
def findRepeating(arr, N):
    s = set()
    for i in range(N):
        if arr[i] in s:
            return arr[i]
        s.add(arr[i])
 
    # If input is correct, we should
    # never reach here
    return -1
 
 
# Driver code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3]
  N = len(arr)
 
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed
# by Shrikant13

Time complexity: linear
Space complexity: linear
# Python3 program to find the only
# repeating element in an array where
# elements are from 1 to N-1.
 
 
def findRepeating(arr, N):
 
    # Find array sum and subtract sum
    # first n-1 natural numbers from it
    # to find the result.
    return sum(arr) - (((N - 1) * N) // 2)
 
 
# Driver's Code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
  N = len(arr)
 
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed
# by mohit kumar

Time complexity: linear
Space complexity: constant
# Python3 program to find the only
# repeating element in an array where
# elements are from 1 to N-1.
 
 
def findRepeating(arr, N):
 
    # res is going to store value of
    # 1 ^ 2 ^ 3 .. ^ (N-1) ^ arr[0] ^
    # arr[1] ^ .... arr[n-1]
    res = 0
    for i in range(0, N-1):
        res = res ^ (i+1) ^ arr[i]
    res = res ^ arr[N-1]
 
    return res
 
 
# Driver code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
  N = len(arr)
 
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed by Smitha Dinesh Semwal.

Time complexity: linear
Space complexity: constant
# Python3 program to find the only
# repeating element in an array
# where elements are from 1 to N-1.
 
# Function to find repeated element
 
 
def findRepeating(arr, N):
 
    missingElement = 0
 
    # indexing based
    for i in range(0, N):
 
        element = arr[abs(arr[i])]
 
        if(element < 0):
            missingElement = arr[i]
            break
 
        arr[abs(arr[i])] = -arr[abs(arr[i])]
 
    return abs(missingElement)
 
 
# Driver code
if __name__ == "__main__":
  arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
  N = len(arr)
   
  # Function call
  print(findRepeating(arr, N))
 
# This code is contributed by Smitha Dinesh Semwal.

Time complexity: linear
Space complexity: constant
class GFG :
    @staticmethod
    def  findDuplicate( nums) :
        slow = nums[0]
        fast = nums[0]
        while True :
            slow = nums[slow]
            fast = nums[nums[fast]]
            if((slow != fast) == False) :
                    break
        fast = nums[0]
        while (slow != fast) :
            slow = nums[slow]
            fast = nums[fast]
        return slow
    @staticmethod
    def main( args) :
        arr = [9, 8, 2, 6, 1, 8, 5, 3, 4, 7]
         
        # Function call
        ans = GFG.findDuplicate(arr)
        print(ans)
     
if __name__=="__main__":
    GFG.main([])
     
    # This code is contributed by aadityaburujwale.

Time complexity: linear
Space complexity: constant
# Python code to find the array element that appears only once
 
# Function to find the array
# element that appears only once
def findSingle(A, ar_size):
   
    # iterate over every element
    for i in range(ar_size):
       
        # Initialize count to 0
        count = 0
        for j in range(ar_size):
           
            # Count the frequency
            # of the element
            if(A[i] == A[j]):
                count += 1
 
        # If the frequency of
        # the element is one
        if(count == 1):
            return A[i]
           
    # If no element exist
    # at most once
    return -1
 
ar = [2, 3, 5, 4, 5, 3, 4]
n = len(ar)
# Function call
print("Element occurring once is", findSingle(ar, n))
 
# This code is contributed by lokesh

Time complexity: quadratic
Space complexity: constant
# function to find the once
# appearing element in array
def findSingle( ar, n):
     
    res = ar[0]
     
    # Do XOR of all elements and return
    for i in range(1,n):
        res = res ^ ar[i]
     
    return res
 
# Driver code
ar = [2, 3, 5, 4, 5, 3, 4]
print "Element occurring once is", findSingle(ar, len(ar))
 
# This code is contributed by __Devesh Agrawal__

Time complexity: linear
Space complexity: constant
# Python3 program to find
# element that appears once
 
# function which find number
def singleNumber(nums):
 
# applying the formula.
    return 2 * sum(set(nums)) - sum(nums)
 
# driver code
a = [2, 3, 5, 4, 5, 3, 4]
print (int(singleNumber(a)))
 
a = [15, 18, 16, 18, 16, 15, 89]
print (int(singleNumber(a)))
 
# This code is contributed by "Abhishek Sharma 44"

Time complexity: nlogn
Space complexity: linear
def singleelement(arr, n):
    low = 0
    high = n - 2
    mid = 0
    while (low <= high):
        mid = (low + high) // 2
        if (arr[mid] == arr[mid ^ 1]):
            low = mid + 1
        else:
            high = mid - 1
     
    return arr[low]
     
# Driver code
arr = [2, 3, 5, 4, 5, 3, 4]
size = len(arr)
arr.sort()
print(singleelement(arr, size))
 
# This code is contributed by shivanisingh

Time complexity: nlogn
Space complexity: constant
# Python Program to find max
# subarray sum excluding some
# elements
 
# Function to check the element
# present in array B
INT_MIN = -2147483648
 
 
def isPresent(B, m, x):
    for i in range(0, m):
        if B[i] == x:
            return True
    return False
 
# Utility function for findMaxSubarraySum()
# with the following parameters
# A => Array A,
# B => Array B,
# n => Number of elements in Array A,
# m => Number of elements in Array B
 
 
def findMaxSubarraySumUtil(A, B, n, m):
 
    # set max_so_far to INT_MIN
    max_so_far = INT_MIN
    curr_max = 0
    for i in range(0, n):
        if isPresent(B, m, A[i]) == True:
            curr_max = 0
            continue
 
        # Proceed as in Kadane's Algorithm
        curr_max = max(A[i], curr_max + A[i])
        max_so_far = max(max_so_far, curr_max)
    return max_so_far
 
# Wrapper for findMaxSubarraySumUtil()
 
 
def findMaxSubarraySum(A, B, n, m):
 
    maxSubarraySum = findMaxSubarraySumUtil(A, B, n, m)
 
    # This case will occur when all
    # elements of A are present
    # in B, thus no subarray can be
    # formed
    if maxSubarraySum == INT_MIN:
        print('Maximum Subarray Sum cant be found')
    else:
        print('The Maximum Subarray Sum =',
              maxSubarraySum)
 
 
# Driver code
A = [3, 4, 5, -4, 6]
B = [1, 8, 5]
n = len(A)
m = len(B)
 
# Function call
findMaxSubarraySum(A, B, n, m)
 
# This code is contributed
# by sahil shelangia

Time complexity: quadratic
Space complexity: constant
# Python Program to find max subarray
# sum excluding some elements
 
# Utility function for findMaxSubarraySum()
# with the following parameters
# A => Array A,
# B => Array B,
# n => Number of elements in Array A,
# m => Number of elements in Array B
import sys
 
 
def binary_search(B, m, target):
 
    start,end = 0,m - 1
             
    # Iterate while start not meets end
    while (start <= end):
 
        # Find the mid index
        mid = (start + end) // 2
 
        # If element is present at mid, return True
        if (B[mid] == target):
            return True
 
        # Else look in left or right half accordingly
        elif (B[mid] < target):
            start = mid + 1
        else:
            end = mid - 1
 
    return False
 
def findMaxSubarraySumUtil(A, B, n, m):
 
    # set max_so_far to INT_MIN
    max_so_far,curr_max = -sys.maxsize - 1,0
 
    for i in range(n):
 
        # if the element is present in B,
        # set current max to 0 and move to
        # the next element
        if (binary_search(B, m, A[i])):
            curr_max = 0
            continue
 
        # Proceed as in Kadane's Algorithm
        curr_max = max(A[i], curr_max + A[i])
        max_so_far = max(max_so_far, curr_max)
 
    return max_so_far
 
# Wrapper for findMaxSubarraySumUtil()
def findMaxSubarraySum(A,B,n,m):
 
    # sort array B to apply Binary Search
    B.sort()
 
    maxSubarraySum = findMaxSubarraySumUtil(A, B, n, m)
 
    # This case will occur when all elements
    # of A are present in B, thus no subarray
    # can be formed
    if (maxSubarraySum == -sys.maxsize - 1):
        print("Maximum subarray sum cant be found")
    else:
        print(f"The Maximum subarray sum = {maxSubarraySum}")
 
# Driver Code
A = [ 3, 4, 5, -4, 6 ]
B = [ 1, 8, 5 ]
 
n = len(A)
m = len(B)
 
# Function call
findMaxSubarraySum(A, B, n, m)
 
# This code is contributed by shinjanpatra

Time complexity: nlogn
Space complexity: constant
# Python3 program implementation of the
# above idea
import sys
 
# Function to calculate the max sum of
# contiguous subarray of B whose elements
# are not present in A
def findMaxSubarraySum(A, B):
     
    m = dict()
   
    # Mark all the elements present in B
    for i in range(len(B)):
        if B[i] not in m:
            m[B[i]] = 0
             
        m[B[i]] = 1
     
    # Initialize max_so_far with INT_MIN
    max_so_far = -sys.maxsize - 1
    currmax = 0
    
    # Traverse the array A
    for i in range(len(A)):
        if (currmax < 0 or (A[i] in m and m[A[i]] == 1)):
            currmax = 0
            continue
         
        currmax = max(A[i], A[i] + currmax)
       
        # If current max is greater than
        # max so far then update max so far
        if (max_so_far<currmax):
            max_so_far = currmax
      
    return max_so_far
 
# Driver Code
if __name__=='__main__':
 
    a = [ 3, 4, 5, -4, 6 ]
    b = [ 1, 8, 5 ]
  
    # Function call
    print(findMaxSubarraySum(a, b))
     
# This code is contributed by rutvik_56

Time complexity: linear
Space complexity: linear
# Python 3 program to find maximum
# equilibrium sum.
import sys
 
# Function to find maximum equilibrium sum.
def findMaxSum(arr, n):
    res = -sys.maxsize - 1
    for i in range(n):
        prefix_sum = arr[i]
        for j in range(i):
            prefix_sum += arr[j]
 
        suffix_sum = arr[i]
        j = n - 1
        while(j > i):
            suffix_sum += arr[j]
            j -= 1
        if (prefix_sum == suffix_sum):
            res = max(res, prefix_sum)
 
    return res
 
# Driver Code
if __name__ == '__main__':
    arr = [-2, 5, 3, 1, 2, 6, -4, 2]
    n = len(arr)
    print(findMaxSum(arr, n))
 
# This code is contributed by
# Surendra_Gangwar

Time complexity: quadratic
Space complexity: linear
# Python3 program to find
# maximum equilibrium sum.
 
# Function to find maximum
# equilibrium sum.
def findMaxSum(arr, n):
 
    # Array to store prefix sum.
    preSum = [0 for i in range(n)]
 
    # Array to store suffix sum.
    suffSum = [0 for i in range(n)]
 
    # Variable to store maximum sum.
    ans = -10000000
 
    # Calculate prefix sum.
    preSum[0] = arr[0]
     
    for i in range(1, n):
     
        preSum[i] = preSum[i - 1] + arr[i]
 
    # Calculate suffix sum and compare
    # it with prefix sum. Update ans
    # accordingly.
    suffSum[n - 1] = arr[n - 1]
    if (preSum[n - 1] == suffSum[n - 1]):
        ans = max(ans, preSum[n - 1])
      
    for i in range(n - 2, -1, -1):
        suffSum[i] = suffSum[i + 1] + arr[i]
        if (suffSum[i] == preSum[i]):
            ans = max(ans, preSum[i])
     
    return ans
 
# Driver Code
if __name__=='__main__':
 
    arr = [-2, 5, 3, 1,2, 6, -4, 2]
    n = len(arr)
    print(findMaxSum(arr, n))
     
# This code is contributed by pratham76

Time complexity: linear
Space complexity: linear
# Python3 program to find
# maximum equilibrium sum.
import sys
 
# Function to find
# maximum equilibrium sum.
def findMaxSum(arr,n):
     
    ss = sum(arr)
    prefix_sum = 0
    res = -sys.maxsize
     
    for i in range(n):
        prefix_sum += arr[i]
         
        if prefix_sum == ss:
            res = max(res, prefix_sum);
             
        ss -= arr[i];
         
    return res
  
# Driver code  
if __name__=="__main__":
     
    arr = [ -2, 5, 3, 1,
             2, 6, -4, 2 ]
    n = len(arr)
     
    print(findMaxSum(arr, n))
 
# This code is contributed by rutvik_56

Time complexity: linear
Space complexity: constant