forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightedUniformStrings.java
More file actions
34 lines (32 loc) · 962 Bytes
/
WeightedUniformStrings.java
File metadata and controls
34 lines (32 loc) · 962 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
31
32
33
34
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
char c[] = s.toCharArray();
int l = c.length;
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
char prev = c[0], curr = c[0], subs=1;
map.put(curr-96, 1);
for(int i=1;i<l;i++) {
curr = c[i];
if(curr==prev){
subs++;
map.put(subs*(curr-96), 1);
} else {
subs = 1;
map.put(curr-96, 1);
}
prev = curr;
}
int n = in.nextInt();
for(int a0 = 0; a0 < n; a0++){
int x = in.nextInt();
System.out.println((map.containsKey(x) ? (map.get(x)==1) : false) ? "Yes" : "No");
}
}
}