• + 0 comments

    10 lines in Python, 100%

    Cool kid solution, have fun with it!

    cum = []
    l = {}
    
    def rec(i,j):
        m = cum[i-1]+((cum[j]-cum[i-1])/2)
        return 0 if m not in l else 1+max(rec(i,l[m]),rec(l[m]+1,j))
            
    def arraySplitting(arr):
        global cum, l
        cum = list(accumulate(arr)) + [0]
        l = {cum[i]:i for i in range(len(cum)-1)} # lookup
        return len(arr)-1 if cum[-2]==0 else rec(0,len(arr)-1)
    

    Using accumulate() from itertools