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.
import math
import os
import random
import re
import sys
#
Complete the 'equalStacks' function below.
#
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER_ARRAY h1
2. INTEGER_ARRAY h2
3. INTEGER_ARRAY h3
#
def equalStacks(h1, h2, h3):
sum1, sum2, sum3 = sum(h1), sum(h2), sum(h3)
i, j, k = 0, 0, 0
while not (sum1 == sum2 == sum3):
if sum1 > sum2 or sum1 > sum3:
sum1 -= h1[i]
i += 1
elif sum2 > sum1 or sum2 > sum3:
sum2 -= h2[j]
j += 1
elif sum3 > sum1 or sum3 > sum2:
sum3 -= h3[k]
k += 1
if i == len(h1) or j == len(h2) or k == len(h3):
return 0
return sum1
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
!/bin/python3
import math import os import random import re import sys
#
Complete the 'equalStacks' function below.
#
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER_ARRAY h1
2. INTEGER_ARRAY h2
3. INTEGER_ARRAY h3
#
def equalStacks(h1, h2, h3): sum1, sum2, sum3 = sum(h1), sum(h2), sum(h3) i, j, k = 0, 0, 0
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')