dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } static Node newNode ( int data ) { Node newnode = new Node ( ) ; newnode . data = data ; newnode . left = newnode . right = null ; return newnode ; } static boolean printKDistant ( Node root , int klevel ) { Queue < Node > q = new LinkedList < > ( ) ; int level = 1 ; boolean flag = false ; q . add ( root ) ; q . add ( null ) ; while ( q . size ( ) > 0 ) { Node temp = q . peek ( ) ; if ( level == klevel && temp != null ) { flag = true ; System . out . print ( temp . data + " ▁ " ) ; } q . remove ( ) ; if ( temp == null ) { if ( q . peek ( ) != null ) q . add ( null ) ; level += 1 ; if ( level > klevel ) break ; } else { if ( temp . left != null ) q . add ( temp . left ) ; if ( temp . right != null ) q . add ( temp . right ) ; } } System . out . println ( ) ; return flag ; } public static void main ( String srga [ ] ) { Node root = newNode ( 20 ) ; root . left = newNode ( 10 ) ; root . right = newNode ( 30 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 15 ) ; root . left . right . left = newNode ( 12 ) ; root . right . left = newNode ( 25 ) ; root . right . right = newNode ( 40 ) ; System . out . print ( " data ▁ at ▁ level ▁ 1 ▁ : ▁ " ) ; boolean ret = printKDistant ( root , 1 ) ; if ( ret == false ) System . out . print ( " Number ▁ exceeds ▁ total ▁ " + "number of levelsNEW_LINE"); System . out . print ( " data ▁ at ▁ level ▁ 2 ▁ : ▁ " ) ; ret = printKDistant ( root , 2 ) ; if ( ret == false ) System . out . print ( " Number ▁ exceeds ▁ total ▁ " + "number of levelsNEW_LINE"); System . out . print ( " data ▁ at ▁ level ▁ 3 ▁ : ▁ " ) ; ret = printKDistant ( root , 3 ) ; if ( ret == false ) System . out . print ( " Number ▁ exceeds ▁ total ▁ " + "number of levelsNEW_LINE"); System . out . print ( " data ▁ at ▁ level ▁ 6 ▁ : ▁ " ) ; ret = printKDistant ( root , 6 ) ; if ( ret == false ) System . out . print ( " Number ▁ exceeds ▁ total " + "number of levelsNEW_LINE"); } }

Accumulator variables: level
Boolean variables: flag
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { public int data ; public Node left , right ; } ; static void printLeafNodes ( Node root ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { System . out . print ( root . data + " ▁ " ) ; return ; } if ( root . left != null ) printLeafNodes ( root . left ) ; if ( root . right != null ) printLeafNodes ( root . right ) ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 8 ) ; root . right . left . left = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . left = newNode ( 9 ) ; root . right . right . right = newNode ( 10 ) ; printLeafNodes ( root ) ; } }

Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void printkdistanceNodeDown ( Node node , int k ) { if ( node == null k < 0 ) return ; if ( k == 0 ) { System . out . print ( node . data ) ; System . out . println ( " " ) ; return ; } printkdistanceNodeDown ( node . left , k - 1 ) ; printkdistanceNodeDown ( node . right , k - 1 ) ; } int printkdistanceNode ( Node node , Node target , int k ) { if ( node == null ) return - 1 ; if ( node == target ) { printkdistanceNodeDown ( node , k ) ; return 0 ; } int dl = printkdistanceNode ( node . left , target , k ) ; if ( dl != - 1 ) { if ( dl + 1 == k ) { System . out . print ( node . data ) ; System . out . println ( " " ) ; } else printkdistanceNodeDown ( node . right , k - dl - 2 ) ; return 1 + dl ; } int dr = printkdistanceNode ( node . right , target , k ) ; if ( dr != - 1 ) { if ( dr + 1 == k ) { System . out . print ( node . data ) ; System . out . println ( " " ) ; } else printkdistanceNodeDown ( node . left , k - dr - 2 ) ; return 1 + dr ; } return - 1 ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 20 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 22 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 12 ) ; tree . root . left . right . left = new Node ( 10 ) ; tree . root . left . right . right = new Node ( 14 ) ; Node target = tree . root . left . right ; tree . printkdistanceNode ( tree . root , target , 2 ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void printSingles ( Node node ) { if ( node == null ) return ; if ( node . left != null && node . right != null ) { printSingles ( node . left ) ; printSingles ( node . right ) ; } else if ( node . right != null ) { System . out . print ( node . right . data + " ▁ " ) ; printSingles ( node . right ) ; } else if ( node . left != null ) { System . out . print ( node . left . data + " ▁ " ) ; printSingles ( node . left ) ; } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . right = new Node ( 4 ) ; tree . root . right . left = new Node ( 5 ) ; tree . root . right . left . right = new Node ( 6 ) ; tree . printSingles ( tree . root ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void kDistantFromLeafUtil ( Node node , int path [ ] , boolean visited [ ] , int pathLen , int k ) { if ( node == null ) return ; path [ pathLen ] = node . data ; visited [ pathLen ] = false ; pathLen ++ ; if ( node . left == null && node . right == null && pathLen - k - 1 >= 0 && visited [ pathLen - k - 1 ] == false ) { System . out . print ( path [ pathLen - k - 1 ] + " ▁ " ) ; visited [ pathLen - k - 1 ] = true ; return ; } kDistantFromLeafUtil ( node . left , path , visited , pathLen , k ) ; kDistantFromLeafUtil ( node . right , path , visited , pathLen , k ) ; } void printKDistantfromLeaf ( Node node , int k ) { int path [ ] = new int [ 1000 ] ; boolean visited [ ] = new boolean [ 1000 ] ; kDistantFromLeafUtil ( node , path , visited , 0 , k ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . right . left . right = new Node ( 8 ) ; System . out . println ( " ▁ Nodes ▁ at ▁ distance ▁ 2 ▁ are ▁ : " ) ; tree . printKDistantfromLeaf ( tree . root , 2 ) ; } }

Index/key variables: pathLen
Accumulator variables: pathLen
Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; int printKDistantfromLeaf ( Node node , int k ) { if ( node == null ) return - 1 ; int lk = printKDistantfromLeaf ( node . left , k ) ; int rk = printKDistantfromLeaf ( node . right , k ) ; boolean isLeaf = lk == - 1 && lk == rk ; if ( lk == 0 || rk == 0 || ( isLeaf && k == 0 ) ) System . out . print ( " ▁ " + node . data ) ; if ( isLeaf && k > 0 ) return k - 1 ; if ( lk > 0 && lk < k ) return lk - 1 ; if ( rk > 0 && rk < k ) return rk - 1 ; return - 2 ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . right . left . right = new Node ( 8 ) ; System . out . println ( " ▁ Nodes ▁ at ▁ distance ▁ 2 ▁ are ▁ : " ) ; tree . printKDistantfromLeaf ( tree . root , 2 ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class Node { int key ; Node left , right ; public Node ( int key ) { this . key = key ; left = right = null ; } } class BinaryTree { Node root ; void printCorner ( Node root ) { Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; while ( ! q . isEmpty ( ) ) { int n = q . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Node temp = q . peek ( ) ; q . poll ( ) ; if ( i == 0 i == n - 1 ) System . out . print ( temp . key + " ▁ " ) ; if ( temp . left != null ) q . add ( temp . left ) ; if ( temp . right != null ) q . add ( temp . right ) ; } } } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 15 ) ; tree . root . left = new Node ( 10 ) ; tree . root . right = new Node ( 20 ) ; tree . root . left . left = new Node ( 8 ) ; tree . root . left . right = new Node ( 12 ) ; tree . root . right . left = new Node ( 16 ) ; tree . root . right . right = new Node ( 25 ) ; tree . printCorner ( tree . root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
class GFG { static final int COUNT = 10 ; static class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } ; static void print2DUtil ( Node root , int space ) { if ( root == null ) return ; space += COUNT ; print2DUtil ( root . right , space ) ; System . out . print ( "NEW_LINE"); for ( int i = COUNT ; i < space ; i ++ ) System . out . print ( " ▁ " ) ; System . out . print ( root . data + "NEW_LINE"); print2DUtil ( root . left , space ) ; } static void print2D ( Node root ) { print2DUtil ( root , 0 ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 11 ) ; root . right . left . left = new Node ( 12 ) ; root . right . left . right = new Node ( 13 ) ; root . right . right . left = new Node ( 14 ) ; root . right . right . right = new Node ( 15 ) ; print2D ( root ) ; } }

Accumulator variables: i, space
Iterator variables: i
Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; static int max_level = 0 ; void leftViewUtil ( Node node , int level ) { if ( node == null ) return ; if ( max_level < level ) { System . out . print ( " ▁ " + node . data ) ; max_level = level ; } leftViewUtil ( node . left , level + 1 ) ; leftViewUtil ( node . right , level + 1 ) ; } void leftView ( ) { leftViewUtil ( root , 1 ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 12 ) ; tree . root . left = new Node ( 10 ) ; tree . root . right = new Node ( 30 ) ; tree . root . right . left = new Node ( 25 ) ; tree . root . right . right = new Node ( 40 ) ; tree . leftView ( ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; public class PrintRightView { private static class Node { int data ; Node left , right ; public Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } private static void printLeftView ( Node root ) { if ( root == null ) return ; Queue < Node > queue = new LinkedList < > ( ) ; queue . add ( root ) ; while ( ! queue . isEmpty ( ) ) { int n = queue . size ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { Node temp = queue . poll ( ) ; if ( i == 1 ) System . out . print ( temp . data + " ▁ " ) ; if ( temp . left != null ) queue . add ( temp . left ) ; if ( temp . right != null ) queue . add ( temp . right ) ; } } } public static void main ( String [ ] args ) { Node root = new Node ( 10 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 7 ) ; root . left . right = new Node ( 8 ) ; root . right . right = new Node ( 15 ) ; root . right . left = new Node ( 12 ) ; root . right . right . left = new Node ( 14 ) ; printLeftView ( root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Node, PrintRightView
Java program:
import java . io . * ; class GFG { static int rotate ( int arr [ ] , int N , int X ) { long nextPower = 1 ; while ( nextPower <= N ) nextPower *= 2 ; if ( X == 1 ) return ( int ) nextPower - N ; long prevPower = nextPower / 2 ; return 2 * ( N - ( int ) prevPower ) + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int X = 1 ; int N = arr . length ; System . out . println ( rotate ( arr , N , X ) ) ; } }

Accumulator variables: nextPower
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMaximumZeros ( String str , int n ) { int c0 = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( str . charAt ( i ) == '0' ) c0 ++ ; } if ( c0 == n ) { System . out . print ( n ) ; return ; } String s = str + str ; int mx = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int cs = 0 ; int ce = 0 ; for ( int j = i ; j < i + n ; ++ j ) { if ( s . charAt ( j ) == '0' ) cs ++ ; else break ; } for ( int j = i + n - 1 ; j >= i ; -- j ) { if ( s . charAt ( j ) == '0' ) ce ++ ; else break ; } int val = cs + ce ; mx = Math . max ( val , mx ) ; } System . out . print ( mx ) ; } public static void main ( String [ ] args ) { String s = "1001" ; int n = s . length ( ) ; findMaximumZeros ( s , n ) ; } }

Accumulator variables: c0, ce, cs
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMaximumZeros ( String str , int n ) { int c0 = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( str . charAt ( i ) == '0' ) c0 ++ ; } if ( c0 == n ) { System . out . print ( n ) ; return ; } int mx = 0 ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '0' ) cnt ++ ; else { mx = Math . max ( mx , cnt ) ; cnt = 0 ; } } mx = Math . max ( mx , cnt ) ; int start = 0 , end = n - 1 ; cnt = 0 ; while ( str . charAt ( start ) != '1' && start < n ) { cnt ++ ; start ++ ; } while ( str . charAt ( end ) != '1' && end >= 0 ) { cnt ++ ; end -- ; } mx = Math . max ( mx , cnt ) ; System . out . println ( mx ) ; } public static void main ( String [ ] args ) { String s = "1001" ; int n = s . length ( ) ; findMaximumZeros ( s , n ) ; } }

Accumulator variables: c0, cnt, end, i, start
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void reverse ( int arr [ ] , int start , int end ) { while ( start < end ) { int temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; start ++ ; end -- ; } } static void rotateMatrix ( int mat [ ] [ ] ) { int i = 0 ; for ( int rows [ ] : mat ) { reverse ( rows , 0 , rows . length - 1 ) ; reverse ( rows , 0 , i - 1 ) ; reverse ( rows , i , rows . length - 1 ) ; i ++ ; } for ( int rows [ ] : mat ) { for ( int cols : rows ) { System . out . print ( cols + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; rotateMatrix ( mat ) ; } }

Index/key variables: end, start
Accumulator variables: end, i, start
Iterator variables: cols
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void stringShift ( String s , int [ ] [ ] shift ) { int val = 0 ; for ( int i = 0 ; i < shift . length ; ++ i ) if ( shift [ i ] [ 0 ] == 0 ) val -= shift [ i ] [ 1 ] ; else val += shift [ i ] [ 1 ] ; int len = s . length ( ) ; val = val % len ; String result = " " ; if ( val > 0 ) result = s . substring ( len - val , ( len - val ) + val ) + s . substring ( 0 , len - val ) ; else result = s . substring ( - val , len + val ) + s . substring ( 0 , - val ) ; System . out . println ( result ) ; } public static void main ( String [ ] args ) { String s = " abc " ; int [ ] [ ] shift = new int [ ] [ ] { { 0 , 1 } , { 1 , 2 } } ; stringShift ( s , shift ) ; } }

Index/key variables: i
Accumulator variables: val
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void rotateArray ( int [ ] arr , int N ) { int [ ] v = arr ; Arrays . sort ( v ) ; for ( int i = 1 ; i <= N ; ++ i ) { int x = arr [ N - 1 ] ; i = N - 1 ; while ( i > 0 ) { arr [ i ] = arr [ i - 1 ] ; arr [ 0 ] = x ; i -= 1 ; } if ( arr == v ) { System . out . print ( " YES " ) ; return ; } } System . out . print ( " NO " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 5 , 1 , 2 } ; int N = arr . length ; rotateArray ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findLargestRotation ( int num ) { int ans = num ; int len = ( int ) Math . floor ( ( ( int ) Math . log10 ( num ) ) + 1 ) ; int x = ( int ) Math . pow ( 10 , len - 1 ) ; for ( int i = 1 ; i < len ; i ++ ) { int lastDigit = num % 10 ; num = num / 10 ; num += ( lastDigit * x ) ; if ( num > ans ) { ans = num ; } } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int N = 657 ; findLargestRotation ( N ) ; } }

Accumulator variables: i, num
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int numberOfDigit ( int N ) { int digit = 0 ; while ( N > 0 ) { digit ++ ; N /= 10 ; } return digit ; } static void rotateNumberByK ( int N , int K ) { int X = numberOfDigit ( N ) ; K = ( ( K % X ) + X ) % X ; int left_no = N / ( int ) ( Math . pow ( 10 , X - K ) ) ; N = N % ( int ) ( Math . pow ( 10 , X - K ) ) ; int left_digit = numberOfDigit ( left_no ) ; N = ( N * ( int ) ( Math . pow ( 10 , left_digit ) ) ) + left_no ; System . out . println ( N ) ; } public static void main ( String args [ ] ) { int N = 12345 , K = 7 ; rotateNumberByK ( N , K ) ; } }

Accumulator variables: N, digit
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minMovesToSort ( int arr [ ] , int N ) { int count = 0 ; int index = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] < arr [ i + 1 ] ) { count ++ ; index = i ; } } if ( count == 0 ) { System . out . print ( "0" ) ; } else if ( count == N - 1 ) { System . out . print ( N - 1 ) ; } else if ( count == 1 && arr [ 0 ] <= arr [ N - 1 ] ) { System . out . print ( index + 1 ) ; } else { System . out . print ( " - 1" ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 5 , 4 , 2 } ; int N = arr . length ; minMovesToSort ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 3 ; static int findMaximumDiagonalSumOMatrixf ( int A [ ] [ ] ) { int maxDiagonalSum = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int curr = 0 ; for ( int j = 0 ; j < N ; j ++ ) { curr += A [ j ] [ ( i + j ) % N ] ; } maxDiagonalSum = Math . max ( maxDiagonalSum , curr ) ; } for ( int i = 0 ; i < N ; i ++ ) { int curr = 0 ; for ( int j = 0 ; j < N ; j ++ ) { curr += A [ ( i + j ) % N ] [ j ] ; } maxDiagonalSum = Math . max ( maxDiagonalSum , curr ) ; } return maxDiagonalSum ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 1 , 2 } , { 2 , 1 , 2 } , { 1 , 2 , 2 } } ; System . out . println ( findMaximumDiagonalSumOMatrixf ( mat ) ) ; } }

Index/key variables: j
Accumulator variables: curr, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void diagonalSumPerfectSquare ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { System . out . print ( arr [ ( j + i ) % 7 ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] srgs ) { int N = 7 ; int [ ] arr = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = i + 1 ; } diagonalSumPerfectSquare ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int MaxSum ( int [ ] arr , int n , int k ) { int i , max_sum = 0 , sum = 0 ; for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } max_sum = sum ; while ( i < n ) { sum = sum - arr [ i - k ] + arr [ i ] ; if ( max_sum < sum ) { max_sum = sum ; } i ++ ; } return max_sum ; } static int gcd ( int n1 , int n2 ) { if ( n2 == 0 ) { return n1 ; } else { return gcd ( n2 , n1 % n2 ) ; } } static int [ ] RotateArr ( int [ ] arr , int n , int d ) { int i = 0 , j = 0 ; d = d % n ; int no_of_sets = gcd ( d , n ) ; for ( i = 0 ; i < no_of_sets ; i ++ ) { int temp = arr [ i ] ; j = i ; while ( true ) { int k = j + d ; if ( k >= n ) k = k - n ; if ( k == i ) break ; arr [ j ] = arr [ k ] ; j = k ; } arr [ j ] = temp ; } return arr ; } static void performQuery ( int [ ] arr , int Q [ ] [ ] , int q ) { int N = arr . length ; for ( int i = 0 ; i < q ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { arr = RotateArr ( arr , N , Q [ i ] [ 1 ] ) ; for ( int t : arr ) { System . out . print ( t + " ▁ " ) ; } System . out . print ( "NEW_LINE"); } else { System . out . print ( MaxSum ( arr , N , Q [ i ] [ 1 ] ) + "NEW_LINE"); } } } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int q = 5 ; int Q [ ] [ ] = { { 1 , 2 } , { 2 , 3 } , { 1 , 3 } , { 1 , 1 } , { 2 , 4 } } ; performQuery ( arr , Q , q ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, sum
Iterator variables: i, t
Class/struct names: GFG
Java program:
class GFG { public static int getMinimumRemoval ( String str ) { int n = str . length ( ) ; int ans = n ; if ( n % 2 == 0 ) { int [ ] freqEven = new int [ 128 ] ; int [ ] freqOdd = new int [ 128 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { freqEven [ str . charAt ( i ) ] ++ ; } else { freqOdd [ str . charAt ( i ) ] ++ ; } } int evenMax = 0 , oddMax = 0 ; for ( char chr = ' a ' ; chr <= ' z ' ; chr ++ ) { evenMax = Math . max ( evenMax , freqEven [ chr ] ) ; oddMax = Math . max ( oddMax , freqOdd [ chr ] ) ; } ans = ans - evenMax - oddMax ; } else { int [ ] freq = new int [ 128 ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ str . charAt ( i ) ] ++ ; } int strMax = 0 ; for ( char chr = ' a ' ; chr <= ' z ' ; chr ++ ) { strMax = Math . max ( strMax , freq [ chr ] ) ; } ans = ans - strMax ; } return ans ; } public static void main ( String [ ] args ) { String str = " geeksgeeks " ; System . out . print ( getMinimumRemoval ( str ) ) ; } }

Index/key variables: chr
Accumulator variables: chr, i
Iterator variables: chr, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findAltSubSeq ( String s ) { int n = s . length ( ) , ans = Integer . MIN_VALUE ; for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { int cur = 0 , f = 0 ; for ( int k = 0 ; k < n ; k ++ ) { if ( f == 0 && s . charAt ( k ) - '0' == i ) { f = 1 ; cur ++ ; } else if ( f == 1 && s . charAt ( k ) - '0' == j ) { f = 0 ; cur ++ ; } } if ( i != j && cur % 2 == 1 ) cur -- ; ans = Math . max ( cur , ans ) ; } } return ans ; } public static void main ( String [ ] args ) { String s = "100210601" ; System . out . print ( findAltSubSeq ( s ) ) ; } }

Accumulator variables: cur, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG