What is an efficient way of searching if hello
has two l
?
I am aware we can just iterate through string like:
var numberOfLs = 0;
for(var j = 0; j < curString.length; j++){
if(curString[j] == 'l'){numberOfLs += 1;}
}
if(numberOfLs >= 2){return 0;}
But this is O(n) and it is causing me maximum stack errors later on with my code. What is a faster way in javascript where I can search if a string has two letters?
Here is the exact question I am trying to work through: https://jsfiddle.net/Lvkqpak0/
I am trying to count all possible combinations of 3 given letters, up to 30 char strings, and it is giving me an error. When I do 15 char strings it works fine. I've tried memoizing the solution but it doesn't help, that is why I removed the memo parameter in the function.