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.
Here is my solution with comments. There are additional variables declared for ease of understanding.
// number of times string can be repeated within limit nconstnumOfRepeats=Math.floor(n/s.length);// additional number of strings to get to the limit nconstremainderString=n%s.length;// find number of matches in a stringletmatches=(s.match(/a/g)||[]).length;// multiply number of matches in a string with number of repeatationsmatches=matches*numOfRepeats;// find number of matches in remainder stringconstremainderMatches=(s.substring(0,remainderString).match(/a/g)||[]).length;// add it upreturnmatches+remainderMatches;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
Here is my solution with comments. There are additional variables declared for ease of understanding.