HackerRank in a String!

  • + 0 comments

    Went this way around with Javascript:

    const HRS = "hackerrank";
    function hackerrankInString(s: string): string {
        let matching = 0;
        for (let i = 0; i < s.length && matching < HRS.length; i++) {
            if (s[i] === HRS[matching]) matching++;
        }
        return matching === HRS.length ? "YES" : "NO";
    }