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.
5 days later and family concerned for my mental health.... Third times a charm.
// Write your code hereletshuffledStringCount={}letreversedStringCount={}letrs=[...s].reverse().join("")for(letindexinrs){letchar=rs[index]shuffledStringCount[char]=(shuffledStringCount[char]||0)+1;reversedStringCount[char]=(reversedStringCount[char]||0)+1;}for(letcharinshuffledStringCount){shuffledStringCount[char]=shuffledStringCount[char]/2reversedStringCount[char]=reversedStringCount[char]/2}functionremoveFromFinal(fs,index){letchar=fs[index]shuffledStringCount[char]--reversedStringCount[char]++returnfs.substring(0,index)+fs.slice(index+1)}functionoptimiseString(fs){letoptimised=fsletlast=fs.length-1letsecondLast=fs.length-2if(fs[last]<fs[secondLast]){if(shuffledStringCount[fs[secondLast]]!=0){optimised=removeFromFinal(optimised,secondLast)returnoptimiseString(optimised)}}returnoptimised}letfinal=''for(letindexinrs){letchar=rs[index]if(reversedStringCount[char]===0){shuffledStringCount[char]--continue}final=final+charreversedStringCount[char]--final=optimiseString(final)}returnfinal
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 →
Solution with Javascript
5 days later and family concerned for my mental health.... Third times a charm.