HackerRank in a String!

  • + 0 comments

    My easy c++ solution, here is the explanation : https://youtu.be/N3lhtXtqIoU

    string hackerrankInString(string s) {
        string target ="hackerrank";
        int currentIndex = 0;    
        for(int i = 0; i < s.size(); i++){
            if(s[i] == target[currentIndex]){
                currentIndex++;
                if(currentIndex == target.size()) return "YES";
            }
        }
        return "NO";
    }