-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHackerRankInAString.java
More file actions
30 lines (25 loc) · 897 Bytes
/
HackerRankInAString.java
File metadata and controls
30 lines (25 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// https://www.hackerrank.com/challenges/hackerrank-in-a-string/problem
package strings;
import java.util.*;
public class HackerRankInAString {
private static final String HACKERRANK = "hackerrank";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int queries = scanner.nextInt();
while (queries-- > 0) {
String string = scanner.next();
System.out.println(containsHackerRank(string) ? "YES" : "NO");
}
}
private static boolean containsHackerRank(String string) {
for (int index = 0, pointer = 0 ; index < string.length() ; index++) {
if (string.charAt(index) == HACKERRANK.charAt(pointer)) {
pointer++;
}
if (pointer == HACKERRANK.length()) {
return true;
}
}
return false;
}
}