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.
defreverseShuffleMerge(s):# Write your code herestashed_dic=Counter(s)# the intial requirments for each charrequired_dic={c:math.ceil(v/2)forc,vinstashed_dic.items()}result=[]forcinreversed(s):stashed_dic[c]-=1ifrequired_dic[c]<=0:continue# deal with the pop whileresult:last_c=result[-1]if(c<last_c)and(stashed_dic[last_c]>=required_dic[last_c]+1):result.pop()required_dic[last_c]+=1else:breakresult.append(c)required_dic[c]-=1return"".join(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse Shuffle Merge
You are viewing a single comment's thread. Return to all comments →