File tree Expand file tree Collapse file tree
CodeForces/Contests/CodeforceContestes/src/contests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package contests ;
2+
3+ import java .util .Arrays ;
4+ import java .util .Scanner ;
5+
6+ /**
7+ * @author rohithvazhathody 08-Aug-2025
8+ */
9+ public class BogoSort {
10+
11+ /**
12+ * @param args
13+ */
14+ public static void main (String [] args ) {
15+ Scanner sc = new Scanner (System .in );
16+ int test = sc .nextInt ();
17+ while (test -- > 0 ) {
18+ int n = sc .nextInt ();
19+ int [] nums = new int [n ];
20+ for (int index = 0 ; index < n ; index ++) {
21+ nums [index ] = sc .nextInt ();
22+ }
23+ int [] shuffled = findShuffled (nums , n );
24+ for (int index = n - 1 ; index >= 0 ; index --) {
25+ System .out .print (shuffled [index ] + " " );
26+ }
27+ System .out .println ();
28+ }
29+ sc .close ();
30+ }
31+
32+ private static int [] findShuffled (int [] nums , int n ) {
33+ if (n == 1 ) {
34+ return nums ;
35+ }
36+ Arrays .sort (nums );
37+ return nums ;
38+ }
39+
40+ }
Original file line number Diff line number Diff line change 1+ package contests ;
2+
3+ import java .util .Scanner ;
4+
5+ /**
6+ * @author rohithvazhathody 06-Aug-2025
7+ */
8+ public class FairNumbers {
9+
10+ /**
11+ * @param args
12+ */
13+ public static void main (String [] args ) {
14+ Scanner sc = new Scanner (System .in );
15+ int test = sc .nextInt ();
16+ while (test -- > 0 ) {
17+ long num = sc .nextLong ();
18+ System .out .println (findMinNumber (num ));
19+ }
20+ sc .close ();
21+ }
22+
23+ private static long findMinNumber (long num ) {
24+ if (num == 1 ) {
25+ return num ;
26+ }
27+ while (true ) {
28+ if (isDivisible (num )) {
29+ return num ;
30+ }
31+ num ++;
32+ }
33+ }
34+
35+ private static boolean isDivisible (long num ) {
36+ long store = num ;
37+ while (num > 0 ) {
38+ long digit = num % 10 ;
39+ if (digit != 0 && store % digit != 0 ) {
40+ return false ;
41+ }
42+ num /= 10 ;
43+ }
44+ return true ;
45+ }
46+
47+ }
Original file line number Diff line number Diff line change 1+ package contests ;
2+
3+ import java .util .Scanner ;
4+
5+ /**
6+ * @author rohithvazhathody 08-Aug-2025
7+ */
8+ public class JohnnyAndAncientComputer {
9+
10+ /**
11+ * @param args
12+ */
13+ public static void main (String [] args ) {
14+ Scanner sc = new Scanner (System .in );
15+ int test = sc .nextInt ();
16+ while (test -- > 0 ) {
17+ long num1 = sc .nextLong ();
18+ long num2 = sc .nextLong ();
19+ int minOperations = findMinimumOperation (num1 , num2 );
20+ System .out .println (minOperations );
21+ }
22+ sc .close ();
23+ }
24+
25+ private static int findMinimumOperation (long num1 , long num2 ) {
26+ if (num1 == num2 ) {
27+ return 0 ;
28+ }
29+ long firstNum = num1 ;
30+ long secondNum = num2 ;
31+ while (firstNum % 2 == 0 ) {
32+ firstNum /= 2 ;
33+ }
34+ while (secondNum % 2 == 0 ) {
35+ secondNum /= 2 ;
36+ }
37+ if (firstNum != secondNum ) {
38+ return -1 ;
39+ }
40+ num1 /= firstNum ;
41+ num2 /= secondNum ;
42+ int power1 = (int ) (Math .log (num1 ) / Math .log (2 ));
43+ int power2 = (int ) (Math .log (num2 ) / Math .log (2 ));
44+ int operation = findCeil (Math .abs (power2 - power1 ), 3 );
45+ return operation ;
46+ }
47+
48+ private static int findCeil (int a , int b ) {
49+ return (a + b - 1 ) / (b );
50+ }
51+
52+ }
Original file line number Diff line number Diff line change 1+ package contests ;
2+
3+ import java .util .Scanner ;
4+ import java .util .Stack ;
5+
6+ /**
7+ * @author rohithvazhathody 07-Aug-2025
8+ */
9+ public class MoveBrackets {
10+
11+ /**
12+ * @param args
13+ */
14+ public static void main (String [] args ) {
15+ Scanner sc = new Scanner (System .in );
16+ int test = sc .nextInt ();
17+ while (test -- > 0 ) {
18+ int n = sc .nextInt ();
19+ String s = sc .next ();
20+ int findMinMove = findMinMove (s , n );
21+ System .out .println (findMinMove );
22+ }
23+ sc .close ();
24+ }
25+
26+ private static int findMinMove (String s , int n ) {
27+ Stack <Character > stack = new Stack <>();
28+ for (char ch : s .toCharArray ()) {
29+ if (ch == '(' ) {
30+ stack .push (')' );
31+ } else {
32+ if (!stack .isEmpty () && stack .peek () == ')' ) {
33+ stack .pop ();
34+ }
35+ }
36+ }
37+ return stack .size ();
38+ }
39+
40+ }
Original file line number Diff line number Diff line change 1+ package contests ;
2+
3+ import java .util .Scanner ;
4+
5+ /**
6+ * @author rohithvazhathody 08-Aug-2025
7+ */
8+ public class ReverseASubstring {
9+
10+ /**
11+ * @param args
12+ */
13+ public static void main (String [] args ) {
14+ Scanner sc = new Scanner (System .in );
15+ int n = sc .nextInt ();
16+ String s = sc .next ();
17+ int [] pos = findSubstring (s , n );
18+ if (pos == null ) {
19+ System .out .println ("NO" );
20+ } else {
21+ System .out .println ("YES" );
22+ System .out .println (pos [0 ] + " " + pos [1 ]);
23+ }
24+ sc .close ();
25+ }
26+
27+ private static int [] findSubstring (String s , int n ) {
28+ char currentChar = s .charAt (0 );
29+ int currentIndex = 0 ;
30+ for (int index = 1 ; index < n ; index ++) {
31+ char nextChar = s .charAt (index );
32+ if (currentChar > nextChar ) {
33+ return new int [] { currentIndex + 1 , index + 1 };
34+ } else {
35+ currentChar = nextChar ;
36+ currentIndex = index ;
37+ }
38+ }
39+ return null ;
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments