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.
getting timeout error because the time complexity is O(n*m*k), help me to reduce the complexity:
functioncountSubstrings(s,queries){// Write your code hereletleft;letright;queries.forEach((query,index)=>{letmainSubString=[];left=query[0];right=query[1];constsubString=s.slice(left,right+1);constsstrLength=subString.length;for(leti=0;i<sstrLength;i++){for(letj=i+1;j<=sstrLength;j++){if(!mainSubString.includes(subString.slice(i,j))){mainSubString.push(subString.slice(i,j))}}}console.log(mainSubString.length)})}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
How Many Substrings?
You are viewing a single comment's thread. Return to all comments →
solution in JS:
getting timeout error because the time complexity is O(n*m*k), help me to reduce the complexity: