HackerRank in a String!

  • + 0 comments

    C++ Solution

    string hackerrankInString(string s) {
      string refS = "hackerrank";
      size_t preIt = 0;
      for(size_t i = 0; i < refS.length(); i++) {
        size_t it = s.find_first_of(refS[i], preIt);
        if(it == string::npos)
          return "NO";
        preIt = s.find_last_of(refS[i], it) + 1;
      }
      return "YES";
    }