dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int findKth ( int arr [ ] , int n , int k ) { HashSet < Integer > missing = new HashSet < > ( ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { missing . add ( arr [ i ] ) ; } int maxm = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; int minm = Arrays . stream ( arr ) . min ( ) . getAsInt ( ) ; for ( int i = minm + 1 ; i < maxm ; i ++ ) { if ( ! missing . contains ( i ) ) { count ++ ; } if ( count == k ) { return i ; } } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 10 , 9 , 4 } ; int n = arr . length ; int k = 5 ; System . out . println ( findKth ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node next ; } ; static Node start ; static void sortList ( Node head ) { int startVal = 1 ; while ( head != null ) { head . data = startVal ; startVal ++ ; head = head . next ; } } static void push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; start = head_ref ; } static void printList ( Node node ) { while ( node != null ) { System . out . print ( node . data + " ▁ " ) ; node = node . next ; } } public static void main ( String [ ] args ) { start = null ; push ( start , 2 ) ; push ( start , 1 ) ; push ( start , 6 ) ; push ( start , 4 ) ; push ( start , 5 ) ; push ( start , 3 ) ; sortList ( start ) ; printList ( start ) ; } }

Accumulator variables: startVal
Class/struct names: GFG, Node
Java program:
class GfG { static class Node { int data ; Node next ; } static boolean isSortedDesc ( Node head ) { if ( head == null head . next == null ) return true ; return ( head . data > head . next . data && isSortedDesc ( head . next ) ) ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . next = null ; temp . data = data ; return temp ; } public static void main ( String [ ] args ) { Node head = newNode ( 7 ) ; head . next = newNode ( 5 ) ; head . next . next = newNode ( 4 ) ; head . next . next . next = newNode ( 3 ) ; if ( isSortedDesc ( head ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . Vector ; class GFG { static int minSum ( int arr [ ] , int n ) { Vector < Integer > evenArr = new Vector < > ( ) ; Vector < Integer > oddArr = new Vector < > ( ) ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n / 2 ) { oddArr . add ( arr [ i ] ) ; } else { evenArr . add ( arr [ i ] ) ; } } Comparator comparator = Collections . reverseOrder ( ) ; Collections . sort ( evenArr , comparator ) ; int i = 0 , sum = 0 ; for ( int j = 0 ; j < evenArr . size ( ) ; j ++ ) { arr [ i ++ ] = evenArr . get ( j ) ; arr [ i ++ ] = oddArr . get ( j ) ; sum += evenArr . get ( j ) * oddArr . get ( j ) ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 } ; int n = arr . length ; System . out . println ( " Minimum ▁ required ▁ sum ▁ = ▁ " + minSum ( arr , n ) ) ; System . out . println ( " Sorted ▁ array ▁ in ▁ required ▁ format ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } }

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void minTime ( String word ) { int ans = 0 ; int curr = 0 ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { int k = ( int ) word . charAt ( i ) - 97 ; int a = Math . abs ( curr - k ) ; int b = 26 - Math . abs ( curr - k ) ; ans += Math . min ( a , b ) ; ans ++ ; curr = ( int ) word . charAt ( i ) - 97 ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { String str = " zjpc " ; minTime ( str ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int reduceToOne ( long N ) { int cnt = 0 ; while ( N != 1 ) { if ( N == 2 || ( N % 2 == 1 ) ) { N = N - 1 ; cnt ++ ; } else if ( N % 2 == 0 ) { N = N / ( N / 2 ) ; cnt ++ ; } } return cnt ; } public static void main ( String [ ] args ) { long N = 35 ; System . out . println ( reduceToOne ( N ) ) ; } }

Accumulator variables: cnt
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maxDiamonds ( int A [ ] , int N , int K ) { PriorityQueue < Integer > pq = new PriorityQueue < > ( ( a , b ) -> b - a ) ; for ( int i = 0 ; i < N ; i ++ ) { pq . add ( A [ i ] ) ; } int ans = 0 ; while ( ! pq . isEmpty ( ) && K -- > 0 ) { int top = pq . peek ( ) ; pq . remove ( ) ; ans += top ; top = top / 2 ; pq . add ( top ) ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 1 , 7 , 4 , 2 } ; int K = 3 ; int N = A . length ; maxDiamonds ( A , N , K ) ; } }

Index/key variables: i
Accumulator variables: K, ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MinimumCost ( int A [ ] , int B [ ] , int N ) { int totalCost = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int mod_A = B [ i ] % A [ i ] ; int totalCost_A = Math . min ( mod_A , A [ i ] - mod_A ) ; int mod_B = A [ i ] % B [ i ] ; int totalCost_B = Math . min ( mod_B , B [ i ] - mod_B ) ; totalCost += Math . min ( totalCost_A , totalCost_B ) ; } return totalCost ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 6 , 3 } ; int B [ ] = { 4 , 8 , 13 } ; int N = A . length ; System . out . print ( MinimumCost ( A , B , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, totalCost
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void printLargestDivisible ( int arr [ ] , int N ) { int i , count0 = 0 , count7 = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) count0 ++ ; else count7 ++ ; } if ( count7 % 50 == 0 ) { while ( count7 != 0 ) { System . out . print ( 7 ) ; count7 -= 1 ; } while ( count0 != 0 ) { System . out . print ( 0 ) ; count0 -= 1 ; } } else if ( count7 < 5 ) { if ( count0 == 0 ) System . out . print ( " No " ) ; else System . out . print ( "0" ) ; } else { count7 = count7 - count7 % 5 ; while ( count7 != 0 ) { System . out . print ( 7 ) ; count7 -= 1 ; } while ( count0 != 0 ) { System . out . print ( 0 ) ; count0 -= 1 ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 7 , 0 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 } ; int N = arr . length ; printLargestDivisible ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: count0, count7, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMaxValByRearrArr ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int res = 0 ; do { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += __gcd ( i + 1 , arr [ i ] ) ; } res = Math . max ( res , sum ) ; } while ( next_permutation ( arr ) ) ; return res ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static boolean next_permutation ( int [ ] p ) { for ( int a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { int t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 } ; int N = arr . length ; System . out . print ( findMaxValByRearrArr ( arr , N ) ) ; } }

Index/key variables: a, b, i
Accumulator variables: i, sum
Iterator variables: a, b, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int min_elements ( int arr [ ] , int N ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { mp . put ( arr [ i ] , mp . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } int cntMinRem = 0 ; for ( int key : mp . keySet ( ) ) { int i = key ; int val = mp . get ( i ) ; if ( val < i ) { cntMinRem += val ; } else if ( val > i ) { cntMinRem += ( val - i ) ; } } return cntMinRem ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 1 , 4 , 2 } ; System . out . println ( min_elements ( arr , arr . length ) ) ; } }

Index/key variables: i
Accumulator variables: cntMinRem, i
Iterator variables: i, key
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean CheckAllarrayEqual ( int [ ] arr , int N ) { if ( N == 1 ) { return true ; } int totalSum = arr [ 0 ] ; int secMax = Integer . MIN_VALUE ; int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] >= Max ) { secMax = Max ; Max = arr [ i ] ; } else if ( arr [ i ] > secMax ) { secMax = arr [ i ] ; } totalSum += arr [ i ] ; } if ( ( secMax * ( N - 1 ) ) > totalSum ) { return false ; } if ( totalSum % ( N - 1 ) != 0 ) { return false ; } return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 6 , 2 , 2 , 2 } ; int N = arr . length ; if ( CheckAllarrayEqual ( arr , N ) ) { System . out . print ( " YES " ) ; } else { System . out . print ( " NO " ) ; } } }

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void Remove_one_element ( int arr [ ] , int n ) { int post_odd = 0 , post_even = 0 ; int curr_odd = 0 , curr_even = 0 ; int res = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i % 2 != 0 ) post_odd ^= arr [ i ] ; else post_even ^= arr [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) post_odd ^= arr [ i ] ; else post_even ^= arr [ i ] ; int X = curr_odd ^ post_even ; int Y = curr_even ^ post_odd ; if ( X == Y ) res ++ ; if ( i % 2 != 0 ) curr_odd ^= arr [ i ] ; else curr_even ^= arr [ i ] ; } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 } ; int N = arr . length ; Remove_one_element ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: curr_even, curr_odd, i, post_even, post_odd, res
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int cntIndexesToMakeBalance ( int arr [ ] , int n ) { if ( n == 1 ) { return 1 ; } if ( n == 2 ) return 0 ; int sumEven = 0 ; int sumOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { sumEven += arr [ i ] ; } else { sumOdd += arr [ i ] ; } } int currOdd = 0 ; int currEven = arr [ 0 ] ; int res = 0 ; int newEvenSum = 0 ; int newOddSum = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( i % 2 != 0 ) { currOdd += arr [ i ] ; newEvenSum = currEven + sumOdd - currOdd ; newOddSum = currOdd + sumEven - currEven - arr [ i ] ; } else { currEven += arr [ i ] ; newOddSum = currOdd + sumEven - currEven ; newEvenSum = currEven + sumOdd - currOdd - arr [ i ] ; } if ( newEvenSum == newOddSum ) { res ++ ; } } if ( sumOdd == sumEven - arr [ 0 ] ) { res ++ ; } if ( n % 2 == 1 ) { if ( sumOdd == sumEven - arr [ n - 1 ] ) { res ++ ; } } else { if ( sumEven == sumOdd - arr [ n - 1 ] ) { res ++ ; } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( cntIndexesToMakeBalance ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: currEven, currOdd, i, res, sumEven, sumOdd
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findNums ( int X , int Y ) { int A , B ; if ( X < Y ) { A = - 1 ; B = - 1 ; } else if ( ( ( Math . abs ( X - Y ) ) & 1 ) != 0 ) { A = - 1 ; B = - 1 ; } else if ( X == Y ) { A = 0 ; B = Y ; } else { A = ( X - Y ) / 2 ; if ( ( A & Y ) == 0 ) { B = ( A + Y ) ; } else { A = - 1 ; B = - 1 ; } } System . out . print ( A + " ▁ " + B ) ; } public static void main ( String [ ] args ) { int X = 17 , Y = 13 ; findNums ( X , Y ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void checkCount ( int A [ ] , int Q [ ] [ ] , int q ) { for ( int i = 0 ; i < q ; i ++ ) { int L = Q [ i ] [ 0 ] ; int R = Q [ i ] [ 1 ] ; L -- ; R -- ; if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 13 , 12 , 14 } ; int Q [ ] [ ] = { { 1 , 4 } , { 2 , 4 } } ; int q = Q . length ; checkCount ( arr , Q , q ) ; } }

Index/key variables: L, R, i
Accumulator variables: L, R, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double pairProductMean ( int arr [ ] , int N ) { Vector < Integer > pairArray = new Vector < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int pairProduct = arr [ i ] * arr [ j ] ; pairArray . add ( pairProduct ) ; } } int length = pairArray . size ( ) ; float sum = 0 ; for ( int i = 0 ; i < length ; i ++ ) sum += pairArray . get ( i ) ; float mean ; if ( length != 0 ) mean = sum / length ; else mean = 0 ; return mean ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 8 } ; int N = arr . length ; System . out . format ( " % .2f " , pairProductMean ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findPlayer ( String str [ ] , int n ) { int move_first = 0 ; int move_sec = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] . charAt ( 0 ) == str [ i ] . charAt ( str [ i ] . length ( ) - 1 ) ) { if ( str [ i ] . charAt ( 0 ) == 48 ) move_first ++ ; else move_sec ++ ; } } if ( move_first <= move_sec ) { System . out . print ( " Player ▁ 2 ▁ wins " ) ; } else { System . out . print ( " Player ▁ 1 ▁ wins " ) ; } } public static void main ( String [ ] args ) { String str [ ] = { "010" , "101" } ; int N = str [ 0 ] . length ( ) ; findPlayer ( str , N ) ; } }

Index/key variables: i
Accumulator variables: i, move_first, move_sec
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find_next ( int n , int k ) { int M = n + 1 ; while ( true ) { if ( ( M & ( 1L << k ) ) > 0 ) break ; M ++ ; } return M ; } public static void main ( String [ ] args ) { int N = 15 , K = 2 ; System . out . print ( find_next ( N , K ) ) ; } }

Accumulator variables: M
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find_next ( int n , int k ) { int ans = 0 ; if ( ( n & ( 1L << k ) ) == 0 ) { int cur = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( ( n & ( 1L << i ) ) > 0 ) cur += 1L << i ; } ans = ( int ) ( n - cur + ( 1L << k ) ) ; } else { int first_unset_bit = - 1 , cur = 0 ; for ( int i = 0 ; i < 64 ; i ++ ) { if ( ( n & ( 1L << i ) ) == 0 ) { first_unset_bit = i ; break ; } else cur += ( 1L << i ) ; } ans = ( int ) ( n - cur + ( 1L << first_unset_bit ) ) ; if ( ( ans & ( 1L << k ) ) == 0 ) ans += ( 1L << k ) ; } return ans ; } public static void main ( String [ ] args ) { int N = 15 , K = 2 ; System . out . print ( find_next ( N , K ) ) ; } }

Accumulator variables: ans, cur, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static String largestString ( String num , int k ) { String ans = " " ; for ( char i : num . toCharArray ( ) ) { while ( ans . length ( ) > 0 && ans . charAt ( ans . length ( ) - 1 ) < i && k > 0 ) { ans = ans . substring ( 0 , ans . length ( ) - 1 ) ; k -- ; } ans += i ; } while ( ans . length ( ) > 0 && k -- > 0 ) { ans = ans . substring ( 0 , ans . length ( ) - 1 ) ; } return ans ; } public static void main ( String [ ] args ) { String str = " zyxedcba " ; int k = 1 ; System . out . print ( largestString ( str , k ) + "NEW_LINE"); } }

Accumulator variables: ans, k
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void maxLengthSubArray ( int A [ ] , int N ) { int forward [ ] = new int [ N ] ; int backward [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 A [ i ] != A [ i - 1 ] ) { forward [ i ] = 1 ; } else forward [ i ] = forward [ i - 1 ] + 1 ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 A [ i ] != A [ i + 1 ] ) { backward [ i ] = 1 ; } else backward [ i ] = backward [ i + 1 ] + 1 ; } int ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) ans = Math . max ( ans , Math . min ( forward [ i ] , backward [ i + 1 ] ) * 2 ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 4 , 4 , 6 , 6 , 6 , 9 } ; int N = arr . length ; maxLengthSubArray ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void minNum ( int n ) { if ( n < 3 ) System . out . println ( - 1 ) ; else System . out . println ( 210 * ( ( int ) ( Math . pow ( 10 , n - 1 ) / 210 ) + 1 ) ) ; } public static void main ( String [ ] args ) { int n = 5 ; minNum ( n ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; @ SuppressWarnings ( " unchecked " ) class GFG { static String helper ( int d , int s ) { StringBuilder ans = new StringBuilder ( ) ; for ( int i = 0 ; i < d ; i ++ ) { ans . append ( "0" ) ; } for ( int i = d - 1 ; i >= 0 ; i -- ) { if ( s >= 9 ) { ans . setCharAt ( i , '9' ) ; s -= 9 ; } else { char c = ( char ) ( s + ( int ) '0' ) ; ans . setCharAt ( i , c ) ; s = 0 ; } } return ans . toString ( ) ; } static String findMin ( int x , int Y ) { String y = Integer . toString ( Y ) ; int n = y . length ( ) ; ArrayList p = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { p . add ( 0 ) ; } for ( int i = 0 ; i < n ; i ++ ) { p . add ( i , ( int ) ( ( int ) y . charAt ( i ) - ( int ) '0' ) ) ; if ( i > 0 ) { p . add ( i , ( int ) p . get ( i ) + ( int ) p . get ( i - 1 ) ) ; } } for ( int i = n - 1 , k = 0 ; ; i -- , k ++ ) { int d = 0 ; if ( i >= 0 ) { d = ( int ) y . charAt ( i ) - ( int ) '0' ; } for ( int j = d + 1 ; j <= 9 ; j ++ ) { int r = j ; if ( i > 0 ) { r += ( int ) p . get ( i - 1 ) ; } if ( x - r >= 0 && x - r <= 9 * k ) { String suf = helper ( k , x - r ) ; String pre = " " ; if ( i > 0 ) pre = y . substring ( 0 , i ) ; char cur = ( char ) ( j + ( int ) '0' ) ; pre += cur ; return pre + suf ; } } } } public static void main ( String [ ] arg ) { int x = 18 ; int y = 99 ; System . out . print ( findMin ( x , y ) ) ; } }

Accumulator variables: i, j, k, pre, r, s
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void largestNumber ( int n , int X , int Y ) { int maxm = Math . max ( X , Y ) ; Y = X + Y - maxm ; X = maxm ; int Xs = 0 ; int Ys = 0 ; while ( n > 0 ) { if ( n % Y == 0 ) { Xs += n ; n = 0 ; } else { n -= X ; Ys += X ; } } if ( n == 0 ) { while ( Xs -- > 0 ) System . out . print ( X ) ; while ( Ys -- > 0 ) System . out . print ( Y ) ; } else System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int n = 19 , X = 7 , Y = 5 ; largestNumber ( n , X , Y ) ; } }

Accumulator variables: Xs, Ys, n
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minChanges ( String str , int N ) { int res ; int count0 = 0 , count1 = 0 ; for ( char x : str . toCharArray ( ) ) { if ( x == '0' ) count0 ++ ; } res = count0 ; for ( char x : str . toCharArray ( ) ) { if ( x == '0' ) count0 -- ; if ( x == '1' ) count1 ++ ; res = Math . min ( res , count1 + count0 ) ; } return res ; } public static void main ( String [ ] args ) { int N = 9 ; String str = "000101001" ; System . out . println ( minChanges ( str , N ) ) ; } }

Accumulator variables: count0, count1
Iterator variables: x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int missingnumber ( int n , int arr [ ] ) { int mn = Integer . MAX_VALUE , mx = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 && arr [ i ] == - 1 && arr [ i - 1 ] != - 1 ) { mn = Math . min ( mn , arr [ i - 1 ] ) ; mx = Math . max ( mx , arr [ i - 1 ] ) ; } if ( i < ( n - 1 ) && arr [ i ] == - 1 && arr [ i + 1 ] != - 1 ) { mn = Math . min ( mn , arr [ i + 1 ] ) ; mx = Math . max ( mx , arr [ i + 1 ] ) ; } } int res = ( mx + mn ) / 2 ; return res ; } public static void main ( String [ ] args ) { int n = 5 ; int arr [ ] = { - 1 , 10 , - 1 , 12 , - 1 } ; int res = missingnumber ( n , arr ) ; System . out . print ( res ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int lcsubtr ( char a [ ] , char b [ ] , int length1 , int length2 ) { int dp [ ] [ ] = new int [ length1 + 1 ] [ length2 + 1 ] ; int max = 0 ; for ( int i = 0 ; i <= length1 ; ++ i ) { for ( int j = 0 ; j <= length2 ; ++ j ) { if ( i == 0 j == 0 ) { dp [ i ] [ j ] = 0 ; } else if ( a [ i - 1 ] == b [ j - 1 ] ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + 1 ; max = Math . max ( dp [ i ] [ j ] , max ) ; } else { dp [ i ] [ j ] = 0 ; } } } return max ; } public static void main ( String [ ] args ) { String m = "0110" ; String n = "1101" ; char m1 [ ] = m . toCharArray ( ) ; char m2 [ ] = n . toCharArray ( ) ; System . out . println ( lcsubtr ( m1 , m2 , m1 . length , m2 . length ) ) ; } }

Index/key variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int maxN = 20 ; static int maxSum = 50 ; static int minSum = 50 ; static int Base = 50 ; static int [ ] [ ] dp = new int [ maxN ] [ maxSum + minSum ] ; static boolean [ ] [ ] v = new boolean [ maxN ] [ maxSum + minSum ] ; static int findCnt ( int [ ] arr , int i , int required_sum , int n ) { if ( i == n ) { if ( required_sum == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ required_sum + Base ] ) return dp [ i ] [ required_sum + Base ] ; v [ i ] [ required_sum + Base ] = true ; dp [ i ] [ required_sum + Base ] = findCnt ( arr , i + 1 , required_sum , n ) + findCnt ( arr , i + 1 , required_sum - arr [ i ] , n ) ; return dp [ i ] [ required_sum + Base ] ; } static void countSubsets ( int [ ] arr , int K , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int S1 = ( sum + K ) / 2 ; System . out . print ( findCnt ( arr , 0 , S1 , n ) ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 3 } ; int N = arr . length ; int K = 1 ; countSubsets ( arr , K , N ) ; } }

Index/key variables: i, maxN
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static float [ ] [ ] dp = new float [ 105 ] [ 605 ] ; static float find ( int N , int sum ) { if ( N < 0 sum < 0 ) return 0 ; if ( dp [ N ] [ sum ] > 0 ) return dp [ N ] [ sum ] ; if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return ( float ) ( 1.0 / 6 ) ; else return 0 ; } for ( int i = 1 ; i <= 6 ; i ++ ) dp [ N ] [ sum ] = dp [ N ] [ sum ] + find ( N - 1 , sum - i ) / 6 ; return dp [ N ] [ sum ] ; } public static void main ( String [ ] args ) { int N = 4 , a = 13 , b = 17 ; float probability = 0.0f ; for ( int sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; System . out . printf ( " % .6f " , probability ) ; } }

Index/key variables: N, sum
Accumulator variables: i, sum
Iterator variables: i, sum
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { static int count ( int n ) { HashMap < Integer , Integer > dp = new HashMap < Integer , Integer > ( ) ; dp . put ( 0 , 0 ) ; dp . put ( 1 , 1 ) ; if ( ! dp . containsKey ( n ) ) dp . put ( n , 1 + Math . min ( n % 2 + count ( n / 2 ) , n % 3 + count ( n / 3 ) ) ) ; return dp . get ( n ) ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( String . valueOf ( ( count ( N ) ) ) ) ; } }

Class/struct names: GFG