Deloitte | COGNIZANT | IBM | CAPGEMINI
import java.util.*;
class SolutionClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int K = sc.nextInt();
String s = sc.next();
Set<Integer>set= new HashSet<>();
for (int i = 0; i < K; i++) set.add(sc.nextInt());
StringBuilder sb = new StringBuilder();
int i = 0;
while (i < n) {
int j = i + 1;
while (j < n && s.charAt(j) == s.charAt(i)) j++;
int len = j - i;
if (!set.contains(len)) {
sb.append(s, i, j);
}
i = j;
}
System.out.println(sb.length() == 0 ? "ERROR" : sb.toString());
}
}
//consecutive characters✅
CAPGEMINI✅
961 ·