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.
Hi guys, I copied all the test cases and paste on the custom test input section accurately, all the result where the same expected result outputted by hackerrank. but don't know why my submission always failed, anyone experience something like this
function stringReduction(s) {
let counter = {a:0, b:0, c:0}
let p1 = 0;
let p2 = 1;
let exemptChar = '';
const getReducedChar = (counter)=>{
for(let x in counter){
if(counter[x] == 0){
return x
}
}
}
while(p2< s.length){
if(s[p1] == s[p2]){
exemptChar = exemptChar + s[p1];
p1+=1;
p2+=1
s = exemptChar + s.substr(p1)
}else{
counter[s[p1]] +=1;
counter[s[p2]] +=1
let reducedChar = getReducedChar(counter);
s = exemptChar + reducedChar + s.substr(p2+1)
exemptChar = ''
p1 = 0;
p2 = 1;
counter = {a:0, b:0, c:0}
}
}
return s.length
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Reduction
You are viewing a single comment's thread. Return to all comments →
Hi guys, I copied all the test cases and paste on the custom test input section accurately, all the result where the same expected result outputted by hackerrank. but don't know why my submission always failed, anyone experience something like this
}