You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// First Approach - Iterating over word counting the actual char and it's count, and whenever actual char is different than the iteration char, record count and actual char into answer string. (37ms - Beats 55.56%)
function compressedString(word: string): string {
let ans = '';
let counter = 0, actualChar: string = word[0];
for(let i = 0; i <= word.length; i++) {
if(counter === 9 || word[i] !== actualChar) {
ans += counter + actualChar;
counter = 0;
actualChar = word[i];
}
counter++;
}
return ans;
};
// Second Approach - Same logic of first approach but comparing numbers with their successors, and if it's different record into answer string. (34ms - Beats 55.56%)