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 herelen_h1=len(h1)len_h2=len(h2)len_h3=len(h3)index_counter=0index_shifter=-1running_sum_h1=0running_sum_h2=0running_sum_h3=0master_dict={}whileindex_counter<=max(len_h1,len_h2,len_h3):ifabs(index_shifter)<=len_h1:running_sum_h1+=h1[index_shifter]ifrunning_sum_h1inmaster_dict:master_dict[running_sum_h1]+=1else:master_dict[running_sum_h1]=1ifabs(index_shifter)<=len_h2:running_sum_h2+=h2[index_shifter]ifrunning_sum_h2inmaster_dict:master_dict[running_sum_h2]+=1else:master_dict[running_sum_h2]=1ifabs(index_shifter)<=len_h3:running_sum_h3+=h3[index_shifter]ifrunning_sum_h3inmaster_dict:master_dict[running_sum_h3]+=1else:master_dict[running_sum_h3]=1index_shifter-=1index_counter+=1index_counter=0match_list=[heightforheightinmaster_dictifmaster_dict[height]==3]ifnotmatch_list:return0else:returnmatch_list[-1]
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 →
A python solution: