dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . Arrays ; public class GFG { static boolean isAlphabaticOrder ( String s ) { int n = s . length ( ) ; char c [ ] = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = s . charAt ( i ) ; } Arrays . sort ( c ) ; for ( int i = 0 ; i < n ; i ++ ) if ( c [ i ] != s . charAt ( i ) ) return false ; return true ; } public static void main ( String args [ ] ) { String s = " aabbbcc " ; if ( isAlphabaticOrder ( s ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class SortExample { static void printOrder ( Integer [ ] arr , int k ) { int n = arr . length ; Arrays . sort ( arr , 0 , k ) ; Arrays . sort ( arr , k , n , Collections . reverseOrder ( ) ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , - 1 } ; int k = 4 ; printOrder ( arr , k ) ; System . out . printf ( " % s " , Arrays . toString ( arr ) ) ; } }

Class/struct names: SortExample
Java program:
import java . util . LinkedList ; import java . util . Queue ; public class maxwidthusingqueue { static class node { int data ; node left , right ; public node ( int data ) { this . data = data ; } } static int maxwidth ( node root ) { if ( root == null ) return 0 ; int maxwidth = 0 ; Queue < node > q = new LinkedList < > ( ) ; q . add ( root ) ; while ( ! q . isEmpty ( ) ) { int count = q . size ( ) ; maxwidth = Math . max ( maxwidth , count ) ; while ( count -- > 0 ) { node temp = q . remove ( ) ; if ( temp . left != null ) { q . add ( temp . left ) ; } if ( temp . right != null ) { q . add ( temp . right ) ; } } } return maxwidth ; } 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 . right = new node ( 8 ) ; root . right . right . left = new node ( 6 ) ; root . right . right . right = new node ( 7 ) ; System . out . println ( " Maximum ▁ width ▁ = ▁ " + maxwidth ( root ) ) ; } }

Accumulator variables: count
Class/struct names: maxwidthusingqueue, node
Java program:
import java . io . * ; import java . util . * ; public class GFG { static Stack < Integer > res = new Stack < Integer > ( ) ; static Stack < Integer > tmpStack = new Stack < Integer > ( ) ; static void sortStack ( Stack < Integer > input ) { while ( input . size ( ) != 0 ) { int tmp = input . peek ( ) ; input . pop ( ) ; while ( tmpStack . size ( ) != 0 && tmpStack . peek ( ) > tmp ) { input . push ( tmpStack . peek ( ) ) ; tmpStack . pop ( ) ; } tmpStack . push ( tmp ) ; } } static void sortedMerge ( Stack < Integer > s1 , Stack < Integer > s2 ) { while ( s1 . size ( ) != 0 ) { res . push ( s1 . peek ( ) ) ; s1 . pop ( ) ; } while ( s2 . size ( ) != 0 ) { res . push ( s2 . peek ( ) ) ; s2 . pop ( ) ; } sortStack ( res ) ; } public static void main ( String args [ ] ) { Stack < Integer > s1 = new Stack < Integer > ( ) ; Stack < Integer > s2 = new Stack < Integer > ( ) ; s1 . push ( 34 ) ; s1 . push ( 3 ) ; s1 . push ( 31 ) ; s2 . push ( 1 ) ; s2 . push ( 12 ) ; s2 . push ( 23 ) ; sortedMerge ( s1 , s2 ) ; System . out . println ( " Sorted ▁ and ▁ merged ▁ stack ▁ : " ) ; while ( tmpStack . size ( ) != 0 ) { System . out . print ( tmpStack . peek ( ) + " ▁ " ) ; tmpStack . pop ( ) ; } } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String lexicographicSubConcat ( String s ) { int n = s . length ( ) ; int sub_count = n * ( n + 1 ) / 2 ; String [ ] arr = new String [ sub_count ] ; int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) { arr [ index ++ ] = s . substring ( i , i + len ) ; } Arrays . sort ( arr ) ; String res = " " ; for ( int i = 0 ; i < sub_count ; i ++ ) res += arr [ i ] ; return res ; } public static void main ( String [ ] args ) { String s = " abc " ; System . out . println ( lexicographicSubConcat ( s ) ) ; } }

Index/key variables: i, sub_count
Accumulator variables: i, index, len, res
Iterator variables: i, len
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void printVector ( Vector < Integer > V ) { for ( int i = 0 ; i < V . size ( ) ; i ++ ) { System . out . print ( V . get ( i ) + " ▁ " ) ; } System . out . println ( ) ; } static void insertionSort ( Vector < Integer > V ) { int N = V . size ( ) ; int i , j , key ; for ( i = 1 ; i < N ; i ++ ) { j = i ; while ( j > 0 && V . get ( j ) < V . get ( j - 1 ) ) { int temp = V . get ( j ) ; V . set ( j , V . get ( j - 1 ) ) ; V . set ( j - 1 , temp ) ; j -= 1 ; } } } public static void main ( String [ ] args ) { Vector < Integer > A = new Vector < Integer > ( ) ; A . add ( 0 , 9 ) ; A . add ( 1 , 8 ) ; A . add ( 2 , 7 ) ; A . add ( 3 , 5 ) ; A . add ( 4 , 2 ) ; A . add ( 5 , 1 ) ; A . add ( 6 , 2 ) ; A . add ( 7 , 3 ) ; System . out . print ( " Array : ▁ " ) ; printVector ( A ) ; System . out . print ( " After ▁ Sorting ▁ : " ) ; insertionSort ( A ) ; printVector ( A ) ; } }

Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void descOrder ( char [ ] s ) { Arrays . sort ( s ) ; reverse ( s ) ; } static void reverse ( char [ ] a ) { int i , n = a . length ; char t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } public static void main ( String [ ] args ) { char [ ] s = " geeksforgeeks " . toCharArray ( ) ; System . out . println ( String . valueOf ( s ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class SortString { static final int MAX_CHAR = 26 ; static void sortString ( String str ) { int letters [ ] = new int [ MAX_CHAR ] ; for ( char x : str . toCharArray ( ) ) { letters [ x - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { for ( int j = 0 ; j < letters [ i ] ; j ++ ) { System . out . print ( ( char ) ( i + ' a ' ) ) ; } } } public static void main ( String [ ] args ) { sortString ( " geeksforgeeks " ) ; } }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, j
Iterator variables: i, j, x
Class/struct names: SortString
Java program:
public class GFG { static final int MAX = 1000 ; static int findDuplicate ( int arr [ ] , int n , int k ) { int [ ] freq = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 1 && arr [ i ] > MAX ) { System . out . println ( " Out ▁ of ▁ range " ) ; return - 1 ; } freq [ arr [ i ] ] += 1 ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == k ) return i ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 3 , 1 } ; int k = 2 ; int n = arr . length ; System . out . println ( findDuplicate ( arr , n , k ) ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class Prefix { int sum , index ; } class Pair { int first , second ; Pair ( int a , int b ) { first = a ; second = b ; } } class GFG { static Pair findSubArray ( int arr [ ] , int n ) { int start = - 1 , end = - 1 , min_diff = Integer . MAX_VALUE ; Prefix pre_sum [ ] = new Prefix [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) pre_sum [ i ] = new Prefix ( ) ; pre_sum [ 0 ] . sum = 0 ; pre_sum [ 0 ] . index = - 1 ; for ( int i = 1 ; i <= n ; i ++ ) { pre_sum [ i ] . sum = pre_sum [ i - 1 ] . sum + arr [ i - 1 ] ; pre_sum [ i ] . index = i - 1 ; } Arrays . sort ( pre_sum , ( ( a , b ) -> a . sum - b . sum ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { int diff = pre_sum [ i ] . sum - pre_sum [ i - 1 ] . sum ; if ( min_diff > diff ) { min_diff = diff ; start = pre_sum [ i - 1 ] . index ; end = pre_sum [ i ] . index ; } } Pair p = new Pair ( start + 1 , end ) ; return p ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , - 4 , - 1 , 6 } ; int n = arr . length ; Pair point = findSubArray ( arr , n ) ; System . out . print ( " Subarray ▁ starting ▁ from ▁ " ) ; System . out . println ( point . first + " ▁ to ▁ " + point . second ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair, Prefix
Java program:
import java . util . Arrays ; class Test { static String isKSortedArray ( int arr [ ] , int n , int k ) { int aux [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) aux [ i ] = arr [ i ] ; Arrays . sort ( aux ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = Arrays . binarySearch ( aux , arr [ i ] ) ; if ( Math . abs ( i - j ) > k ) return " No " ; } return " Yes " ; } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 2 , 1 , 5 , 6 , 4 } ; int k = 2 ; System . out . println ( " Is ▁ it ▁ a ▁ k ▁ sorted ▁ array ▁ ? : ▁ " + isKSortedArray ( arr , arr . length , k ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: Test
Java program:
class GFG { static int MIN_MERGE = 32 ; public static int minRunLength ( int n ) { assert n >= 0 ; int r = 0 ; while ( n >= MIN_MERGE ) { r |= ( n & 1 ) ; n >>= 1 ; } return n + r ; } public static void insertionSort ( int [ ] arr , int left , int right ) { for ( int i = left + 1 ; i <= right ; i ++ ) { int temp = arr [ i ] ; int j = i - 1 ; while ( j >= left && arr [ j ] > temp ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } public static void merge ( int [ ] arr , int l , int m , int r ) { int len1 = m - l + 1 , len2 = r - m ; int [ ] left = new int [ len1 ] ; int [ ] right = new int [ len2 ] ; for ( int x = 0 ; x < len1 ; x ++ ) { left [ x ] = arr [ l + x ] ; } for ( int x = 0 ; x < len2 ; x ++ ) { right [ x ] = arr [ m + 1 + x ] ; } int i = 0 ; int j = 0 ; int k = l ; while ( i < len1 && j < len2 ) { if ( left [ i ] <= right [ j ] ) { arr [ k ] = left [ i ] ; i ++ ; } else { arr [ k ] = right [ j ] ; j ++ ; } k ++ ; } while ( i < len1 ) { arr [ k ] = left [ i ] ; k ++ ; i ++ ; } while ( j < len2 ) { arr [ k ] = right [ j ] ; k ++ ; j ++ ; } } public static void timSort ( int [ ] arr , int n ) { int minRun = minRunLength ( MIN_MERGE ) ; for ( int i = 0 ; i < n ; i += minRun ) { insertionSort ( arr , i , Math . min ( ( i + MIN_MERGE - 1 ) , ( n - 1 ) ) ) ; } for ( int size = minRun ; size < n ; size = 2 * size ) { for ( int left = 0 ; left < n ; left += 2 * size ) { int mid = left + size - 1 ; int right = Math . min ( ( left + 2 * size - 1 ) , ( n - 1 ) ) ; if ( mid < right ) merge ( arr , left , mid , right ) ; } } } public static void printArray ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } System . out . print ( "NEW_LINE"); } public static void main ( String [ ] args ) { int [ ] arr = { - 2 , 7 , 15 , - 14 , 0 , 15 , 0 , 7 , - 7 , - 4 , - 13 , 5 , 8 , - 14 , 12 } ; int n = arr . length ; System . out . println ( " Given ▁ Array ▁ is " ) ; printArray ( arr , n ) ; timSort ( arr , n ) ; System . out . println ( " After ▁ Sorting ▁ Array ▁ is " ) ; printArray ( arr , n ) ; } }

Index/key variables: i, j, k, len1, len2, x
Accumulator variables: i, j, k, left, r, x
Iterator variables: i, left, size, x
Class/struct names: GFG
Java program:
import java . util . Arrays ; class Test { static void pendulumArrangement ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int op [ ] = new int [ n ] ; int mid = ( n - 1 ) / 2 ; int j = 1 , i = 1 ; op [ mid ] = arr [ 0 ] ; for ( i = 1 ; i <= mid ; i ++ ) { op [ mid + i ] = arr [ j ++ ] ; op [ mid - i ] = arr [ j ++ ] ; } if ( n % 2 == 0 ) op [ mid + i ] = arr [ j ] ; System . out . println ( " Pendulum ▁ arrangement : " ) ; for ( i = 0 ; i < n ; i ++ ) System . out . print ( op [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 14 , 6 , 19 , 21 , 12 } ; pendulumArrangement ( arr , arr . length ) ; } }

Index/key variables: i, j, mid, n
Accumulator variables: i, j
Iterator variables: i
Class/struct names: Test
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; int getMaxWidth ( Node node ) { int width ; int h = height ( node ) ; int count [ ] = new int [ 10 ] ; int level = 0 ; getMaxWidthRecur ( node , count , level ) ; return getMax ( count , h ) ; } void getMaxWidthRecur ( Node node , int count [ ] , int level ) { if ( node != null ) { count [ level ] ++ ; getMaxWidthRecur ( node . left , count , level + 1 ) ; getMaxWidthRecur ( node . right , count , level + 1 ) ; } } int height ( Node node ) { if ( node == null ) return 0 ; else { int lHeight = height ( node . left ) ; int rHeight = height ( node . right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } int getMax ( int arr [ ] , int n ) { int max = arr [ 0 ] ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } return max ; } 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 . right = new Node ( 8 ) ; tree . root . right . right . left = new Node ( 6 ) ; tree . root . right . right . right = new Node ( 7 ) ; System . out . println ( " Maximum ▁ width ▁ is ▁ " + tree . getMaxWidth ( tree . root ) ) ; } }

Index/key variables: i, level
Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static long minValue ( int A [ ] , int B [ ] , int n ) { Arrays . sort ( A ) ; Arrays . sort ( B ) ; long result = 0 ; for ( int i = 0 ; i < n ; i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ; return result ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 1 , 1 } ; int B [ ] = { 6 , 5 , 4 } ; int n = A . length ; ; System . out . println ( minValue ( A , B , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int TotalPerfectPowerSum ( int L , int R ) { ArrayList < Integer > pows = new ArrayList < Integer > ( ) ; pows . add ( 0 ) ; pows . add ( 1 ) ; for ( int p = 2 ; p < 25 ; p ++ ) { int num = 2 ; while ( ( int ) ( Math . pow ( num , p ) + 0.5 ) <= R ) { pows . add ( ( int ) ( Math . pow ( num , p ) + 0.5 ) ) ; num ++ ; } } int [ ] ok = new int [ R + 2 ] ; for ( int i = 0 ; i < pows . size ( ) ; i ++ ) { for ( int j = 0 ; j < pows . size ( ) ; j ++ ) { if ( pows . get ( i ) + pows . get ( j ) <= R && pows . get ( i ) + pows . get ( j ) >= L ) { ok [ pows . get ( i ) + pows . get ( j ) ] = 1 ; } } } for ( int i = 1 ; i <= R ; i ++ ) { ok [ i ] += ok [ i - 1 ] ; } return ok [ R ] - ok [ L - 1 ] ; } public static void main ( String args [ ] ) { int L = 5 , R = 8 ; System . out . print ( TotalPerfectPowerSum ( L , R ) ) ; } }

Index/key variables: R, i
Accumulator variables: i, j, num, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . lang . Math ; import java . io . * ; class GFG { static class Node { Node left , right ; int val ; public Node ( int val ) { this . val = val ; this . left = this . right = null ; } } } ; public static int minAbsDiff ( Node root ) { int [ ] minDiff = new int [ 1 ] ; minDiff [ 0 ] = Integer . MAX_VALUE ; postOrder ( root ) ; preOrder ( root , minDiff ) ; return minDiff [ 0 ] ; } public static int postOrder ( Node root ) { if ( root == null ) return 0 ; root . val += postOrder ( root . left ) + postOrder ( root . right ) ; return root . val ; } public static void preOrder ( Node root , int [ ] minDiff ) { if ( root == null ) return ; int leftDiff = Math . abs ( root . left . val - ( root . val - root . left . val ) ) ; int rightDiff = Math . abs ( root . right . val - ( root . val - root . right . val ) ) ; minDiff [ 0 ] = Math . min ( minDiff [ 0 ] , Math . min ( leftDiff , rightDiff ) ) ; return ; } 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 ) ; System . out . println ( minAbsDiff ( root ) ) ; } }

Accumulator variables: val
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static int maximum = 0 , minimum = 0 ; static void lengthUtil ( Node root , int curr ) { if ( root == null ) return ; lengthUtil ( root . left , curr - 1 ) ; if ( minimum > curr ) minimum = curr ; if ( maximum < curr ) maximum = curr ; lengthUtil ( root . right , curr + 1 ) ; } static int getLength ( Node root ) { maximum = 0 ; minimum = 0 ; lengthUtil ( root , 0 ) ; return ( Math . abs ( minimum ) + maximum ) + 1 ; } static Node newNode ( int data ) { Node curr = new Node ( ) ; curr . data = data ; curr . left = curr . right = null ; return curr ; } public static void main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; System . out . println ( getLength ( root ) ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; import java . lang . * ; import java . lang . Math ; class GFG { static void findMaximumSumWithMflips ( int arr [ ] , int N , int M ) { PriorityQueue < Integer > minHeap = new PriorityQueue < Integer > ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { minHeap . add ( arr [ i ] ) ; sum += arr [ i ] ; } while ( M -- > 0 ) { sum -= minHeap . peek ( ) ; int temp = - 1 * minHeap . peek ( ) ; minHeap . remove ( ) ; sum += temp ; minHeap . add ( temp ) ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 3 , 7 , - 1 , - 5 , - 3 } ; int M = 4 , N = 5 ; findMaximumSumWithMflips ( arr , N , M ) ; } }

Index/key variables: i
Accumulator variables: M, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void miniOperToMakeAllEleEqual ( int arr [ ] , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } if ( sum % n != 0 ) { System . out . println ( - 1 ) ; return ; } int valueAfterDivision = sum / n ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( valueAfterDivision - arr [ i ] ) % k != 0 ) { System . out . println ( - 1 ) ; return ; } count += Math . abs ( valueAfterDivision - arr [ i ] ) / k ; } System . out . println ( ( int ) count / 2 ) ; } public static void main ( String [ ] args ) { int n = 3 , k = 3 ; int arr [ ] = { 5 , 8 , 11 } ; miniOperToMakeAllEleEqual ( arr , n , k ) ; } }

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minOperations ( ArrayList < Integer > a ) { int res = Integer . MAX_VALUE ; int N = a . size ( ) ; for ( int r = 0 ; r < 2 ; r ++ ) { int sum = 0 , ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += a . get ( i ) ; if ( ( i + r ) % 2 == 1 ) { if ( sum <= 0 ) { ans += - sum + 1 ; sum = 1 ; } } else { if ( sum >= 0 ) { ans += sum + 1 ; sum = - 1 ; } } } res = Math . min ( res , ans ) ; } System . out . print ( res ) ; } public static void main ( String args [ ] ) { ArrayList < Integer > a = new ArrayList < Integer > ( ) ; a . add ( 1 ) ; a . add ( - 3 ) ; a . add ( 1 ) ; a . add ( 0 ) ; minOperations ( a ) ; } }

Accumulator variables: ans, i, r, sum
Iterator variables: i, r
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; public class Main { static void print ( long a [ ] , long b [ ] ) { int minProd = 0 ; for ( int i = 0 ; i < a . length ; ++ i ) { System . out . print ( a [ i ] + " ▁ " ) ; } System . out . println ( ) ; for ( int i = 0 ; i < b . length ; ++ i ) { System . out . print ( b [ i ] + " ▁ " ) ; minProd += a [ i ] * b [ i ] ; } System . out . println ( ) ; System . out . println ( minProd ) ; } static void reverse ( int left , int right , long arr [ ] ) { while ( left < right ) { long temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; ++ left ; -- right ; } } static void minimumProdArray ( long a [ ] , long b [ ] , int l ) { long total = 0 ; for ( int i = 0 ; i < a . length ; ++ i ) { total += a [ i ] * b [ i ] ; } long min = Integer . MAX_VALUE ; int first = 0 ; int second = 0 ; for ( int i = 0 ; i < a . length ; ++ i ) { int left = i - 1 ; int right = i + 1 ; long total1 = total ; while ( left >= 0 && right < a . length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } for ( int i = 0 ; i < a . length ; ++ i ) { int left = i ; int right = i + 1 ; long total1 = total ; while ( left >= 0 && right < a . length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } if ( min < total ) { reverse ( first , second , a ) ; print ( a , b ) ; } else { print ( a , b ) ; } } public static void main ( String [ ] args ) { int n = 4 ; long a [ ] = { 2 , 3 , 1 , 5 } ; long b [ ] = { 8 , 2 , 4 , 3 } ; minimumProdArray ( a , b , n ) ; } }

Index/key variables: i, left, right
Accumulator variables: minProd, total, total1
Iterator variables: i
Class/struct names: Main
Java program:
import java . util . * ; class GFG { public static int MaxCollection ( String S , int P , int Q ) { char maxstr [ ] = ( P >= Q ? " ab " : " ba " ) . toCharArray ( ) ; char minstr [ ] = ( P >= Q ? " ba " : " ab " ) . toCharArray ( ) ; int maxp = Math . max ( P , Q ) ; int minp = Math . min ( P , Q ) ; int cost = 0 ; Stack < Character > stack1 = new Stack < > ( ) ; char [ ] s = S . toCharArray ( ) ; for ( char ch : s ) { if ( ! stack1 . isEmpty ( ) && ( stack1 . peek ( ) == maxstr [ 0 ] && ch == maxstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += maxp ; } else { stack1 . push ( ch ) ; } } StringBuilder sb = new StringBuilder ( ) ; while ( ! stack1 . isEmpty ( ) ) sb . append ( stack1 . pop ( ) ) ; sb = sb . reverse ( ) ; String remstr = sb . toString ( ) ; for ( char ch : remstr . toCharArray ( ) ) { if ( ! stack1 . isEmpty ( ) && ( stack1 . peek ( ) == minstr [ 0 ] && ch == minstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += minp ; } else { stack1 . push ( ch ) ; } } return cost ; } public static void main ( String [ ] args ) { String S = " cbbaabbaab " ; int P = 6 ; int Q = 4 ; System . out . println ( MaxCollection ( S , P , Q ) ) ; } }

Accumulator variables: cost
Iterator variables: ch
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void fillSet ( Node root , Set < Integer > set , int hd ) { if ( root == null ) return ; fillSet ( root . left , set , hd - 1 ) ; set . add ( hd ) ; fillSet ( root . right , set , hd + 1 ) ; } int verticalWidth ( Node root ) { Set < Integer > set = new HashSet < Integer > ( ) ; fillSet ( root , set , 0 ) ; return set . size ( ) ; } 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 . right = new Node ( 8 ) ; tree . root . right . right . left = new Node ( 6 ) ; tree . root . right . right . right = new Node ( 7 ) ; System . out . println ( tree . verticalWidth ( tree . root ) ) ; } }

Class/struct names: BinaryTree, Node