• + 0 comments

    Python

    def equalStacks(h1, h2, h3):
        # Write your code here
        sum1=sum(h1)
        sum2=sum(h2)
        sum3=sum(h3)
        if sum1==sum2==sum3:
            return sum1
        else:
            index1,index2,index3=0,0,0
            while not sum1==sum2==sum3:
                if sum1 > sum2 or sum1>sum3:
                    sum1-=h1[index1]
                    index1+=1
                elif sum2 > sum1 or sum2>sum3:
                    sum2-=h2[index2]
                    index2+=1
                elif sum3 > sum1 or sum3>sum2:
                    sum3-=h3[index3]
                    index3+=1
            if index1==len(h1) or index2==len(h2) or index3==len(h3):
                return 0
            else:
                return sum1