We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank
. Remeber that a subsequence maintains the order of characters selected from a sequence.
More formally, let p[0], p[1], … , p[9] be the respective indices of h
, a
, c
, k
, e
, r
, r
, a
, n
, k
in string s. If p[0] < p[1] < p[2] < … < p[9] is true, then s contains hackerrank
.
For each query, print YES
on a new line if the string contains hackerrank
, otherwise, print NO
.
Example
s = haacckkerrannkk
This contains a subsequence of all of the characters in the proper order. Answer YES
s = haacckkerannk
This is missing the second ‘r’. Answer NO
.
s = hccaakkerrannkk
There is no ‘c’ after the first occurrence of an ‘a’, so answer NO
.
Function Description
Complete the hackerrankInString function in the editor below.
hackerrankInString has the following parameter(s):
- string s: a string
Returns
- string:
YES
orNO
Input Format
The first line contains an integer q, the number of queries.
Each of the next q lines contains a single query string s.
Constraints
2 <= q <= 102
10 <= length of s <= 104
Sample Input 0
1 | 2 |
Sample Output 0
1 | YES |
Explanation 0
We perform the following q = 2 queries:
s = hereiamstackerrank
The characters ofhackerrank
are bolded in the string above. Because the string contains all the characters inhackerrank
in the same exact order as they appear inhackerrank
, we returnYES
.s = hackerworld does not contain the last three characters of
hackerrank
, so we returnNO
.
Sample Input 1
1 | 2 |
Sample Output 1
1 | YES |
Solution
Solution 1 with JS
1 | /* |
Solution 2 with TS
1 | /* |