You are viewing a single comment's thread. Return to all comments →
function reduceString(s){ let p1 = 0; let p2 = 1; const getReducedChar = (st)=>{ let counter = {a:0, b:0, c:0}; for(let x of st){ counter[x]+=1 } for(let x in counter){ if(counter[x] == 0){ return x } } } while(s[p2]){ let char; if(s[p1] !== s[p2]){ char = s[p1]+s[p2]; let reducedChar = getReducedChar(char); s = s.substr(0, p1)+ reducedChar + s.substr(p2+1); p1=0; p2=1; }else{ p1+=1; p2+=1 } return s.length } **I am of the opinion that the above code should work, not sure why it's not passing all hackerrank tests, it honestly seem to me hackerrank written test cases for this problem is flawed. Anyone thinking I am wrong somewhere? Please correct me** return str.length; }
String Reduction
You are viewing a single comment's thread. Return to all comments →