Frage im Vorstellungsgespräch bei Meta

Coding round: split array in such a way that their sum is same

Antwort im Vorstellungsgespräch

Anonym

30. Mai 2020

def findTwoEqualSub(array): # Find sum of whole array total = 0 for x in array: total += x print(total) # check if current position is pivot leftTotal = 0 pivot = None for i in range(len(array)): leftTotal += array[i] if leftTotal == total - leftTotal: pivot = i break if pivot is None: print('No pivot found') else: print('array 1 : {} & array 2 : {}'.format( array[:i+1], array[i+1:]))

2