We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defequalStacks(h1,h2,h3):# Write your code here# FIRST APPROACHs1,s2,s3=sum(h1),sum(h2),sum(h3)ptr_1,ptr_2,ptr_3=0,0,0whilenots1==s2==s3:ifs1>=s2ands1>=s3:s1-=h1[ptr_1]ptr_1+=1elifs2>=s1ands2>=s3:s2-=h2[ptr_2]ptr_2+=1elifs3>=s1ands3>=s2:s3-=h3[ptr_3]ptr_3+=1returns1# SECOND APPROACHd1,d2,d3=deque(h1),deque(h2),deque(h3)s1,s2,s3=sum(h1),sum(h2),sum(h3)whilenots1==s2==s3:ifs1>=s2ands1>=s3:s1-=d1.popleft()elifs2>=s1ands2>=s3:s2-=d2.popleft()elifs3>=s1ands3>=s2:s3-=d3.popleft()returns1
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
EASY SOLUTION IN PYTHON3 WITH TWO APPROACHES