File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // https://www.facebook.com/abhi.sensharma/posts/1241788872853419
2+ // Subscribed by Abhishek Sharma
3+
4+ // Here I have added the Check Algorithm program using Java
5+
6+ import java .util .Scanner ;
7+
8+ public class Main {
9+ public static void main (String [] args ) {
10+ Scanner sc = new Scanner (System .in );
11+
12+ int T = sc .nextInt ();
13+ for (int tc = 0 ; tc < T ; ++tc ) {
14+ String S = sc .next ();
15+
16+ System .out .println (solve (S ) ? "YES" : "NO" );
17+ }
18+
19+ sc .close ();
20+ }
21+
22+ static boolean solve (String S ) {
23+ StringBuilder compressed = new StringBuilder ();
24+ char current = 0 ;
25+ int count = -1 ;
26+ for (int i = 0 ; i <= S .length (); ++i ) {
27+ if (i != S .length () && S .charAt (i ) == current ) {
28+ count ++;
29+ } else {
30+ if (count > 0 ) {
31+ compressed .append (current ).append (count );
32+ }
33+
34+ if (i != S .length ()) {
35+ current = S .charAt (i );
36+ count = 1 ;
37+ }
38+ }
39+ }
40+
41+ return compressed .length () < S .length ();
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments