dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int hashFunction ( int N ) { int [ ] prime = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 } ; int value = 1 , r ; while ( N != 0 ) { r = N % 10 ; value = value * prime [ r ] ; N = N / 10 ; } return value ; } static void findDiff ( int [ ] arr , int n ) { HashMap < Integer , Vector < Integer > > m = new HashMap < > ( ) ; int h , min , max ; for ( int i = 0 ; i < n ; i ++ ) { h = hashFunction ( arr [ i ] ) ; if ( ! m . containsKey ( h ) ) { m . put ( h , new Vector < Integer > ( ) ) ; } m . get ( h ) . add ( arr [ i ] ) ; } for ( Map . Entry < Integer , Vector < Integer > > i : m . entrySet ( ) ) { if ( i . getValue ( ) . size ( ) > 1 ) { min = Integer . MAX_VALUE ; max = - ( Integer . MAX_VALUE ) ; for ( int j = 0 ; j < i . getValue ( ) . size ( ) ; j ++ ) { if ( m . get ( i . getKey ( ) ) . get ( j ) < min ) { min = m . get ( i . getKey ( ) ) . get ( j ) ; } if ( m . get ( i . getKey ( ) ) . get ( j ) > max ) { max = m . get ( i . getKey ( ) ) . get ( j ) ; } } System . out . print ( max - min ) ; break ; } else if ( m . get ( i . getKey ( ) ) == m . values ( ) . toArray ( ) [ m . size ( ) - 1 ] ) System . out . print ( - 1 ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 121 , 312 , 234 , 211 , 112 , 102 } ; int N = arr . length ; findDiff ( arr , N ) ; } }

Index/key variables: i, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; import java . util . Collections ; public class GFG { static int findArea ( Integer arr [ ] , int n ) { Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; int [ ] dimension = { 0 , 0 } ; for ( int i = 0 , j = 0 ; i < n - 1 && j < 2 ; i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ; return ( dimension [ 0 ] * dimension [ 1 ] ) ; } public static void main ( String args [ ] ) { Integer arr [ ] = { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = arr . length ; System . out . println ( findArea ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashSet ; import java . util . Set ; public class GFG { static int findArea ( int arr [ ] , int n ) { Set < Integer > s = new HashSet < > ( ) ; int first = 0 , second = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! s . contains ( arr [ i ] ) ) { s . add ( arr [ i ] ) ; continue ; } if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) second = arr [ i ] ; } return ( first * second ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = arr . length ; System . out . println ( findArea ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Stack ; import java . util . HashMap ; public class PrintPath { class Node { int data ; Node left , right ; Node ( int data ) { left = right = null ; this . data = data ; } } ; public static void printTopToBottomPath ( Node curr , HashMap < Node , Node > parent ) { Stack < Node > stk = new Stack < > ( ) ; while ( curr != null ) { stk . push ( curr ) ; curr = parent . get ( curr ) ; } while ( ! stk . isEmpty ( ) ) { curr = stk . pop ( ) ; System . out . print ( curr . data + " ▁ " ) ; } System . out . println ( ) ; } public static void printRootToLeaf ( Node root ) { if ( root == null ) return ; Stack < Node > nodeStack = new Stack < > ( ) ; nodeStack . push ( root ) ; HashMap < Node , Node > parent = new HashMap < > ( ) ; parent . put ( root , null ) ; while ( ! nodeStack . isEmpty ( ) ) { Node current = nodeStack . pop ( ) ; if ( current . left == null && current . right == null ) printTopToBottomPath ( current , parent ) ; if ( current . right != null ) { parent . put ( current . right , current ) ; nodeStack . push ( current . right ) ; } if ( current . left != null ) { parent . put ( current . left , current ) ; nodeStack . push ( current . left ) ; } } } public static void main ( String args [ ] ) { Node root = new Node ( 10 ) ; root . left = new Node ( 8 ) ; root . right = new Node ( 2 ) ; root . left . left = new Node ( 3 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 2 ) ; printRootToLeaf ( root ) ; } }

Class/struct names: Node, PrintPath
Java program:
import java . util . HashSet ; public class GameOfReplacingArrayElements { public static int playGame ( int arr [ ] ) { HashSet < Integer > set = new HashSet < > ( ) ; for ( int i : arr ) set . add ( i ) ; return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 2 , 2 , 2 , 2 } ; System . out . print ( " Player ▁ " + playGame ( arr ) + " ▁ wins " ) ; } }

Iterator variables: i
Class/struct names: GameOfReplacingArrayElements
Java program:
import java . util . * ; class GfG { static int longLenStrictBitonicSub ( int arr [ ] , int n ) { HashMap < Integer , Integer > inc = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > dcr = new HashMap < Integer , Integer > ( ) ; int len_inc [ ] = new int [ n ] ; int len_dcr [ ] = new int [ n ] ; int longLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int len = 0 ; if ( inc . containsKey ( arr [ i ] - 1 ) ) len = inc . get ( arr [ i ] - 1 ) ; len_inc [ i ] = len + 1 ; inc . put ( arr [ i ] , len_inc [ i ] ) ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { int len = 0 ; if ( dcr . containsKey ( arr [ i ] - 1 ) ) len = dcr . get ( arr [ i ] - 1 ) ; len_dcr [ i ] = len + 1 ; dcr . put ( arr [ i ] , len_dcr [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) if ( longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) ) longLen = len_inc [ i ] + len_dcr [ i ] - 1 ; return longLen ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 2 , 3 , 4 , 5 , 3 , 2 } ; int n = arr . length ; System . out . println ( " Longest ▁ length ▁ strict ▁ " + " bitonic ▁ subsequence ▁ = ▁ " + longLenStrictBitonicSub ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
class GFG { static void Selection_Sort ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; ++ i ) { int min_index = i ; for ( int j = i + 1 ; j < n ; ++ j ) { if ( arr [ j ] < arr [ min_index ] ) min_index = j ; } int temp = arr [ i ] ; arr [ i ] = arr [ min_index ] ; arr [ min_index ] = temp ; } } public static void main ( String [ ] args ) { int n = 5 ; int arr [ ] = { 2 , 0 , 1 , 4 , 3 } ; Selection_Sort ( arr , n ) ; System . out . print ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Selection ▁ Sort ▁ is ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i, j, min_index
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int lastSeenElement ( int a [ ] , int n ) { HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hash . put ( a [ i ] , i ) ; } int res_ind = Integer . MAX_VALUE , res = 0 ; for ( Map . Entry < Integer , Integer > x : hash . entrySet ( ) ) { if ( x . getValue ( ) < res_ind ) { res_ind = x . getValue ( ) ; res = x . getKey ( ) ; } } return res ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 1 , 2 , 2 , 4 , 1 } ; int n = a . length ; System . out . println ( lastSeenElement ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void Bubble_Sort ( int arr [ ] , int n ) { for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 0 ; j <= ( n - i - 1 ) ; ++ j ) { if ( arr [ j ] > arr [ j + 1 ] ) { int temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; } } } } public static void main ( String [ ] args ) { int n = 5 ; int arr [ ] = { 2 , 0 , 1 , 4 , 3 } ; Bubble_Sort ( arr , n ) ; System . out . print ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Bubble ▁ Sort ▁ is ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minimum_possible_sum ( int arr [ ] , int n , int k ) { if ( n == 0 ) { return 0 ; } if ( n == 1 ) { return arr [ 0 ] ; } Vector < Integer > ms = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { ms . add ( arr [ i ] ) ; } Collections . sort ( ms ) ; for ( int i = 0 ; i < k ; i ++ ) { int smallest_element = ms . get ( 0 ) ; int largest_element = ms . get ( ms . size ( ) - 1 ) ; int a = smallest_element * 2 ; int b = largest_element / 2 ; if ( a + b < smallest_element + largest_element ) { ms . remove ( 0 ) ; ms . remove ( ms . size ( ) - 1 ) ; ms . add ( a ) ; ms . add ( b ) ; Collections . sort ( ms ) ; } } int ans = 0 ; for ( int x : ms ) { ans += x ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 50 , 1 , 100 , 100 , 1 } ; int K = 2 ; int n = arr . length ; System . out . print ( minimum_possible_sum ( arr , n , K ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void firstSubsequence ( String s ) { int isMax = - 1 ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) > s . charAt ( i + 1 ) ) { isMax = i ; break ; } } if ( isMax >= 0 ) { s = s . substring ( 0 , isMax ) + s . substring ( isMax + 1 ) ; s . rerase ( isMax , 1 ) ; } else { s . erase ( s . length ( ) - 1 , 1 ) ; s = s . substring ( 0 , s . length ( ) - 1 ) ; } System . out . print ( s ) ; } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; firstSubsequence ( S ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int largeProduct ( int A [ ] , int B [ ] , int N ) { if ( N == 0 ) return 0 ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) pq . add ( A [ i ] ) ; Arrays . sort ( B ) ; for ( int i = 0 ; i < N ; i ++ ) { int minn = pq . poll ( ) ; int maximized_element = Math . max ( minn * B [ i ] , minn + B [ i ] ) ; pq . add ( maximized_element ) ; } int max_product = 1 ; while ( pq . size ( ) > 0 ) { max_product *= pq . poll ( ) ; } return max_product ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 1 , 10 } ; int B [ ] = { 1 , 1 , 1 } ; int N = 3 ; System . out . println ( largeProduct ( A , B , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, max_product
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; class Graph { static final int MAX_PATH_SIZE = 1000 ; static class Node { char data ; Node left , right ; } ; static Node newNode ( char data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static class PATH { int Hd ; char key ; public PATH ( int Hd , char key ) { this . Hd = Hd ; this . key = key ; } public PATH ( ) { } } ; static void printPath ( ArrayList < PATH > path , int size ) { int minimum_Hd = Integer . MAX_VALUE ; PATH p ; for ( int it = 0 ; it < size ; it ++ ) { p = path . get ( it ) ; minimum_Hd = Math . min ( minimum_Hd , p . Hd ) ; } for ( int it = 0 ; it < size ; it ++ ) { p = path . get ( it ) ; int noOfUnderScores = Math . abs ( p . Hd - minimum_Hd ) ; for ( int i = 0 ; i < noOfUnderScores ; i ++ ) System . out . print ( " _ " ) ; System . out . println ( p . key ) ; } System . out . println ( " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ) ; } static void printAllPathsUtil ( Node root , ArrayList < PATH > AllPath , int HD , int order ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { AllPath . set ( order , new PATH ( HD , root . data ) ) ; printPath ( AllPath , order + 1 ) ; return ; } AllPath . set ( order , new PATH ( HD , root . data ) ) ; printAllPathsUtil ( root . left , AllPath , HD - 1 , order + 1 ) ; printAllPathsUtil ( root . right , AllPath , HD + 1 , order + 1 ) ; } static void printAllPaths ( Node root ) { if ( root == null ) return ; ArrayList < PATH > Allpaths = new ArrayList < > ( ) ; for ( int i = 0 ; i < MAX_PATH_SIZE ; i ++ ) { Allpaths . add ( new PATH ( ) ) ; } printAllPathsUtil ( root , Allpaths , 0 , 0 ) ; } public static void main ( String [ ] args ) { Node root = newNode ( ' A ' ) ; root . left = newNode ( ' B ' ) ; root . right = newNode ( ' C ' ) ; root . left . left = newNode ( ' D ' ) ; root . left . right = newNode ( ' E ' ) ; root . right . left = newNode ( ' F ' ) ; root . right . right = newNode ( ' G ' ) ; printAllPaths ( root ) ; } }

Accumulator variables: i, it
Iterator variables: i, it
Class/struct names: Graph, Node, PATH
Java program:
import java . util . * ; import java . lang . Math ; class GFG { static int minsteps ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += Math . abs ( arr [ i ] - Math . pow ( 2 , i ) ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 8 , 2 , 10 , 6 } ; int n = arr . length ; System . out . println ( minsteps ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void leftRotate ( int arr [ ] , int d , int n ) { leftRotateRec ( arr , 0 , d , n ) ; } public static void leftRotateRec ( int arr [ ] , int i , int d , int n ) { if ( d == 0 d == n ) return ; if ( n - d == d ) { swap ( arr , i , n - d + i , d ) ; return ; } if ( d < n - d ) { swap ( arr , i , n - d + i , d ) ; leftRotateRec ( arr , i , d , n - d ) ; } else { swap ( arr , i , d , n - d ) ; leftRotateRec ( arr , n - d + i , 2 * d - n , d ) ; } } public static void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void swap ( int arr [ ] , int fi , int si , int d ) { int i , temp ; for ( i = 0 ; i < d ; i ++ ) { temp = arr [ fi + i ] ; arr [ fi + i ] = arr [ si + i ] ; arr [ si + i ] = temp ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; leftRotate ( arr , 2 , 7 ) ; printArray ( arr , 7 ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findCost ( Integer [ ] a , int n ) { Arrays . sort ( a , Collections . reverseOrder ( ) ) ; int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int p = a [ j ] - j ; a [ j ] = 0 ; if ( p < 0 ) { p = 0 ; continue ; } count += p ; } return count ; } public static void main ( String [ ] args ) { Integer arr [ ] = { 1 , 6 , 7 , 4 , 2 , 5 , 3 } ; int N = arr . length ; System . out . print ( findCost ( arr , N ) ) ; } }

Index/key variables: j
Accumulator variables: count, j
Iterator variables: j
Class/struct names: GFG
Java program:
static void leftRotate ( int arr [ ] , int d , int n ) { int i , j ; if ( d == 0 d == n ) return ; i = d ; j = n - d ; while ( i != j ) { if ( i < j ) { swap ( arr , d - i , d + j - i , i ) ; j -= i ; } else { swap ( arr , d - i , d , j ) ; i -= j ; } } swap ( arr , d - i , d , i ) ; }

Accumulator variables: i, j
Java program:
import java . util . * ; class GFG { static int countPairs ( int arr [ ] , int n ) { int ans = 0 ; HashMap < Integer , Integer > count = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( arr [ i ] ) ) { ans += count . get ( arr [ i ] ) ; count . put ( arr [ i ] , count . get ( arr [ i ] ) + 1 ) ; } else { count . put ( arr [ i ] , 1 ) ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 1 , 1 } ; int N = arr . length ; System . out . print ( countPairs ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int INF = ( int ) 1e9 + 7 ; static int N , M ; static ArrayList < ArrayList < Integer > > edges ; static int [ ] [ ] dist = new int [ 2 ] [ 200000 ] ; static void bfs ( int [ ] dist , int s ) { int [ ] q = new int [ 200000 ] ; Arrays . fill ( dist , INF ) ; int qh = 0 , qt = 0 ; q [ qh ++ ] = s ; dist [ s ] = 0 ; while ( qt < qh ) { int x = q [ qt ++ ] ; for ( Integer y : edges . get ( x ) ) { if ( dist [ y ] == INF ) { dist [ y ] = dist [ x ] + 1 ; q [ qh ++ ] = y ; } } } } static void shortestPathCost ( int selected [ ] , int K ) { ArrayList < int [ ] > data = new ArrayList < > ( ) ; bfs ( dist [ 0 ] , 0 ) ; bfs ( dist [ 1 ] , N - 1 ) ; for ( int i = 0 ; i < K ; i ++ ) { data . add ( new int [ ] { dist [ 0 ] [ selected [ i ] ] - dist [ 1 ] [ selected [ i ] ] , selected [ i ] } ) ; } Collections . sort ( data , ( a , b ) -> a [ 0 ] - b [ 0 ] ) ; int best = 0 ; int MAX = - INF ; for ( int [ ] it : data ) { int a = it [ 1 ] ; best = Math . max ( best , MAX + dist [ 1 ] [ a ] ) ; MAX = Math . max ( MAX , dist [ 0 ] [ a ] ) ; } System . out . println ( Math . min ( dist [ 0 ] [ N - 1 ] , best + 1 ) ) ; } public static void main ( String [ ] args ) { N = 5 ; M = 4 ; int K = 2 ; int selected [ ] = { 1 , 3 } ; Arrays . sort ( selected ) ; edges = new ArrayList < > ( ) ; for ( int i = 0 ; i < 200005 ; i ++ ) edges . add ( new ArrayList < Integer > ( ) ) ; edges . get ( 0 ) . add ( 1 ) ; edges . get ( 1 ) . add ( 0 ) ; edges . get ( 1 ) . add ( 2 ) ; edges . get ( 2 ) . add ( 1 ) ; edges . get ( 2 ) . add ( 3 ) ; edges . get ( 3 ) . add ( 2 ) ; edges . get ( 3 ) . add ( 4 ) ; edges . get ( 4 ) . add ( 3 ) ; shortestPathCost ( selected , K ) ; } }

Index/key variables: a, i, s, x, y
Accumulator variables: i, qh, qt
Iterator variables: i, it, y
Class/struct names: GFG
Java program:
import java . util . Arrays ; public class Test { static int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; static void rotate ( ) { int i = 0 , j = arr . length - 1 ; while ( i != j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i ++ ; } } public static void main ( String [ ] args ) { System . out . println ( " Given ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; rotate ( ) ; System . out . println ( " Rotated ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; } }

Index/key variables: i, j
Accumulator variables: i
Class/struct names: Test
Java program:
import java . util . * ; class GFG { static long [ ] reverse ( long a [ ] ) { int i , n = a . length ; long t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } static long removeElements ( long arr [ ] , int n ) { Arrays . sort ( arr ) ; arr = reverse ( arr ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += arr [ i ] * Math . pow ( 2 , i ) ; } return ans ; } public static void main ( String [ ] args ) { int n = 4 ; long arr [ ] = { 3 , 1 , 2 , 3 } ; System . out . print ( removeElements ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class Node { int data ; Node right , down ; Node ( int data ) { this . data = data ; right = null ; down = null ; } } class pair { int val ; Node head ; pair ( Node head , int val ) { this . val = val ; this . head = head ; } } public static void printList ( Node h ) { while ( h != null ) { System . out . print ( h . data + " ▁ " ) ; h = h . down ; } } class pairComp implements Comparator < pair > { public int compare ( pair p1 , pair p2 ) { return p1 . val - p2 . val ; } } class GFG { public static Node flatten ( Node root ) { Node ptr = root ; Node h = null ; PriorityQueue < pair > pq = new PriorityQueue < pair > ( new pairComp ( ) ) ; while ( ptr != null ) { pq . add ( new pair ( ptr , ptr . data ) ) ; ptr = ptr . right ; } while ( ! pq . isEmpty ( ) ) { Node temp = pq . poll ( ) . head ; if ( temp . down != null ) { pq . add ( new pair ( temp . down , temp . down . data ) ) ; } if ( h == null ) { h = temp ; ptr = temp ; ptr . right = null ; } else { ptr . down = temp ; ptr = temp ; ptr . right = null ; } } return h ; } public static Node push ( Node head_ref , int data ) { Node new_node = new Node ( data ) ; new_node . down = head_ref ; head_ref = new_node ; return head_ref ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 30 ) ; head = push ( head , 8 ) ; head = push ( head , 7 ) ; head = push ( head , 5 ) ; head . right = push ( head . right , 20 ) ; head . right = push ( head . right , 10 ) ; head . right . right = push ( head . right . right , 50 ) ; head . right . right = push ( head . right . right , 22 ) ; head . right . right = push ( head . right . right , 19 ) ; head . right . right . right = push ( head . right . right . right , 45 ) ; head . right . right . right = push ( head . right . right . right , 40 ) ; head . right . right . right = push ( head . right . right . right , 35 ) ; head . right . right . right = push ( head . right . right . right , 20 ) ; head = flatten ( head ) ; printList ( head ) ; } }

Class/struct names: GFG, Node, pair, pairComp
Java program:
import java . util . * ; import java . lang . * ; class GFG { static String findLargest ( StringBuilder s ) { int len = s . length ( ) ; int [ ] loccur = new int [ 26 ] ; Arrays . fill ( loccur , - 1 ) ; for ( int i = len - 1 ; i >= 0 ; -- i ) { int chI = s . charAt ( i ) - ' a ' ; if ( loccur [ chI ] == - 1 ) { loccur [ chI ] = i ; } } char [ ] sorted_s = s . toString ( ) . toCharArray ( ) ; Arrays . sort ( sorted_s ) ; reverse ( sorted_s ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( s . charAt ( i ) != sorted_s [ i ] ) { int chI = sorted_s [ i ] - ' a ' ; int last_occ = loccur [ chI ] ; char tmp = s . charAt ( i ) ; s . setCharAt ( i , s . charAt ( last_occ ) ) ; s . setCharAt ( last_occ , tmp ) ; break ; } } return s . toString ( ) ; } static void reverse ( char a [ ] ) { int i , n = a . length ; for ( i = 0 ; i < n / 2 ; i ++ ) { char t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } public static void main ( String [ ] args ) { StringBuilder s = new StringBuilder ( " yrstvw " ) ; System . out . println ( findLargest ( s ) ) ; } }

Index/key variables: chI, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class PairInSortedRotated { static boolean pairInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) return true ; if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 15 , 6 , 8 , 9 , 10 } ; int sum = 16 ; int n = arr . length ; if ( pairInSortedRotated ( arr , n , sum ) ) System . out . print ( " Array ▁ has ▁ two ▁ elements " + " ▁ with ▁ sum ▁ 16" ) ; else System . out . print ( " Array ▁ doesn ' t ▁ have ▁ two " + " ▁ elements ▁ with ▁ sum ▁ 16 ▁ " ) ; } }

Index/key variables: i, l, r
Accumulator variables: i
Iterator variables: i
Class/struct names: PairInSortedRotated
Java program:
import java . io . * ; class GFG { static int pairsInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; int cnt = 0 ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) { cnt ++ ; if ( l == ( r - 1 + n ) % n ) { return cnt ; } l = ( l + 1 ) % n ; r = ( r - 1 + n ) % n ; } else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 15 , 6 , 7 , 9 , 10 } ; int sum = 16 ; int n = arr . length ; System . out . println ( pairsInSortedRotated ( arr , n , sum ) ) ; } }

Index/key variables: i, l, r
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG