This is my solution in javascript to remove all occurrences of 'b' and 'ac' in a string but I am able to come up with time complexity esp. when removing all occurences for 'ac'. Could someone explain ?
function removeChars(input) {
let result = input;
result = result.replaceAll('b', ''); // tc = O(n) where n is length of string. string of all b's
while(result.indexOf('ac') !== -1) { // number of ac ? what if aacacacc
result = result.replaceAll('ac', ''); // replaceAll has time complexity of O(n)
}
return result; // space ~ O(n)
}