dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int solve ( int A [ ] [ ] , int N , int M ) { int [ ] [ ] B = new int [ N ] [ M ] ; int c = 1 ; HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) B [ i ] [ j ] = c ++ ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i != 0 ) { if ( A [ i - 1 ] [ j ] == A [ i ] [ j ] ) B [ i - 1 ] [ j ] = B [ i ] [ j ] ; } if ( i != N - 1 ) { if ( A [ i + 1 ] [ j ] == A [ i ] [ j ] ) B [ i + 1 ] [ j ] = B [ i ] [ j ] ; } if ( j != 0 ) { if ( A [ i ] [ j - 1 ] == A [ i ] [ j ] ) B [ i ] [ j - 1 ] = B [ i ] [ j ] ; } if ( j != M - 1 ) { if ( A [ i ] [ j + 1 ] == A [ i ] [ j ] ) B [ i ] [ j + 1 ] = B [ i ] [ j ] ; } } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) s . add ( B [ i ] [ j ] ) ; } return s . size ( ) ; } public static void main ( String [ ] args ) { int N = 2 , M = 3 ; int A [ ] [ ] = { { 2 , 1 , 3 } , { 1 , 1 , 2 } } ; System . out . print ( solve ( A , N , M ) ) ; } }

Index/key variables: M, N, i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int splitArray ( int start , int end , int [ ] arr , int [ ] prefix_sum ) { if ( start >= end ) return 0 ; for ( int k = start ; k < end ; ++ k ) { if ( ( prefix_sum [ k ] - prefix_sum [ start - 1 ] ) == ( prefix_sum [ end ] - prefix_sum [ k ] ) ) { return 1 + splitArray ( start , k , arr , prefix_sum ) + splitArray ( k + 1 , end , arr , prefix_sum ) ; } } return 0 ; } static void solve ( int arr [ ] , int n ) { int [ ] prefix_sum = new int [ n + 1 ] ; prefix_sum [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i - 1 ] ; } System . out . print ( splitArray ( 1 , n , arr , prefix_sum ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 3 , 3 , 0 , 3 , 3 } ; int N = arr . length ; solve ( arr , N ) ; } }

Index/key variables: end, i, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
class GFG { static int minDays ( int [ ] arr , int n , int k ) { int l = arr . length , left = 1 , right = ( int ) 1e9 ; if ( n * k > l ) return - 1 ; while ( left < right ) { int mid = ( left + right ) / 2 , cnt = 0 , product = 0 ; for ( int j = 0 ; j < l ; ++ j ) { if ( arr [ j ] > mid ) { cnt = 0 ; } else if ( ++ cnt >= k ) { product ++ ; cnt = 0 ; } } if ( product < n ) { left = mid + 1 ; } else { right = mid ; } } return left ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 10 , 3 , 10 , 2 } ; int n = 3 , k = 1 ; System . out . print ( minDays ( arr , n , k ) + "NEW_LINE"); } }

Index/key variables: j
Accumulator variables: product
Iterator variables: j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countFac ( int n ) { int m = n ; int count = 0 ; for ( int i = 2 ; ( i * i ) <= m ; ++ i ) { int total = 0 ; while ( n % i == 0 ) { n /= i ; ++ total ; } int temp = 0 ; for ( int j = 1 ; ( temp + j ) <= total ; ++ j ) { temp += j ; ++ count ; } } if ( n != 1 ) ++ count ; return count ; } public static void main ( String [ ] args ) { int N = 24 ; System . out . println ( countFac ( N ) ) ; } }

Accumulator variables: n, temp
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minimumSum ( int a [ ] , int b [ ] , int c , int n ) { int [ ] [ ] dp = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = ( int ) 1e6 ; } } dp [ 0 ] [ 0 ] = a [ 0 ] ; dp [ 0 ] [ 1 ] = b [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = Math . min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 0 ] + a [ i ] ) ; dp [ i ] [ 0 ] = Math . min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 1 ] + a [ i ] + c ) ; dp [ i ] [ 1 ] = Math . min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 0 ] + b [ i ] + c ) ; dp [ i ] [ 1 ] = Math . min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + b [ i ] ) ; } System . out . print ( Math . min ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) + "NEW_LINE"); } public static void main ( String [ ] args ) { int arr1 [ ] = { 7 , 6 , 18 , 6 , 16 , 18 , 1 , 17 , 17 } ; int arr2 [ ] = { 6 , 9 , 3 , 10 , 9 , 1 , 10 , 1 , 5 } ; int C = 2 ; int N = arr1 . length ; minimumSum ( arr1 , arr2 , C , N ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { public static int minimumMoves ( String s , int K ) { StringBuilder S = new StringBuilder ( s ) ; int N = S . length ( ) ; int ops = 0 ; int last_idx = - 1 ; for ( int i = 0 ; i < K ; i ++ ) { if ( S . charAt ( i ) == '1' ) last_idx = i ; } if ( last_idx == - 1 ) { ++ ops ; S . setCharAt ( K - 1 , '1' ) ; last_idx = K - 1 ; } for ( int i = 1 ; i < N - K + 1 ; i ++ ) { if ( last_idx < i ) last_idx = - 1 ; if ( S . charAt ( i + K - 1 ) == '1' ) last_idx = i + K - 1 ; if ( last_idx == - 1 ) { ++ ops ; S . setCharAt ( i + K - 1 , '1' ) ; last_idx = i + K - 1 ; } } return ops ; } public static void main ( String [ ] args ) { String S = "001010000" ; int K = 3 ; System . out . println ( minimumMoves ( S , K ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static char arr [ ] = { ' a ' , ' b ' , ' c ' } ; static void findString ( int n , int k , char [ ] s1 , char [ ] s2 ) { char [ ] s3 = s2 ; int d = 0 ; for ( int i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) d ++ ; } if ( ( d + 1 ) / 2 > k ) { System . out . print ( " - 1" + "NEW_LINE"); return ; } else { if ( k <= d ) { int X = d - k ; int T = 2 * k - d ; for ( int i = 0 ; i < s3 . length ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( T > 0 ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s2 [ i ] ) { s3 [ i ] = arr [ j ] ; T -- ; break ; } } } else if ( X > 0 ) { s3 [ i ] = s1 [ i ] ; X -- ; } } } System . out . print ( new String ( s3 ) + "NEW_LINE"); } else { for ( int i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] != s3 [ i ] ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } for ( int i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] == s3 [ i ] && k > 0 ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } System . out . print ( new String ( s3 ) + "NEW_LINE"); } } } public static void main ( String [ ] args ) { int N = 4 , k = 2 ; String S1 = " zzyy " ; String S2 = " zxxy " ; findString ( N , k , S1 . toCharArray ( ) , S2 . toCharArray ( ) ) ; } }

Index/key variables: i, j
Accumulator variables: T, X, d, i, j, k
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findSolutions ( int N ) { int count = 0 ; for ( int i = 1 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( ( i + N / i ) % 2 == 0 ) { count ++ ; } } } System . out . print ( 4 * count ) ; } public static void main ( String [ ] args ) { int N = 80 ; findSolutions ( N ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static long check ( int A , int B , int C , int D , long x ) { long ans ; ans = ( A * x * x * x + B * x * x + C * x + D ) ; return ans ; } static void findSolution ( int A , int B , int C , int D , int E ) { long start = 0 , end = 100000 ; long mid , ans ; while ( start <= end ) { mid = start + ( end - start ) / 2 ; ans = check ( A , B , C , D , mid ) ; if ( ans == E ) { System . out . println ( mid ) ; return ; } if ( ans < E ) start = mid + 1 ; else end = mid - 1 ; } System . out . println ( " NA " ) ; } public static void main ( String args [ ] ) { int A = 1 , B = 0 , C = 0 ; int D = 0 , E = 27 ; findSolution ( A , B , C , D , E ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int countTriplets ( String color ) { int result = 0 , Blue_Count = 0 ; int Red_Count = 0 ; int len = color . length ( ) ; int i ; for ( i = 0 ; i < len ; i ++ ) { if ( color . charAt ( i ) == ' B ' ) Blue_Count ++ ; } for ( i = 0 ; i < len ; i ++ ) { if ( color . charAt ( i ) == ' B ' ) Blue_Count -- ; if ( color . charAt ( i ) == ' R ' ) Red_Count ++ ; if ( color . charAt ( i ) == ' G ' ) result += Red_Count * Blue_Count ; } return result ; } public static void main ( String [ ] args ) { String color = " RRGGBBRGGBB " ; System . out . println ( countTriplets ( color ) ) ; } }

Accumulator variables: Blue_Count, Red_Count, i, result
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int naive_find_x ( int N ) { int c = 0 , i ; for ( i = 1 ; i < N ; i ++ ) { c += i * i * i ; if ( c >= N ) break ; } return i ; } public static void main ( String [ ] args ) { int N = 100 ; System . out . println ( naive_find_x ( N ) ) ; } }

Accumulator variables: c, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int binary_searched_find_x ( int k ) { int l = 0 ; int r = k ; int ans = 0 ; while ( l <= r ) { int mid = l + ( r - l ) / 2 ; if ( Math . pow ( ( ( mid * ( mid + 1 ) ) / 2 ) , 2 ) >= k ) { ans = mid ; r = mid - 1 ; } else { l = mid + 1 ; } } return ans ; } public static void main ( String [ ] args ) { int N = 100 ; System . out . println ( binary_searched_find_x ( N ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int lenOfLongZigZagArr ( int a [ ] , int n ) { int max = 1 , len = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( i % 2 == 0 && ( a [ i ] < a [ i + 1 ] ) ) len ++ ; else if ( i % 2 == 1 && ( a [ i ] > a [ i + 1 ] ) ) len ++ ; else { if ( max < len ) max = len ; len = 1 ; } } if ( max < len ) max = len ; return max ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( lenOfLongZigZagArr ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int checkPerfectSquare ( long N , long start , long last ) { long mid = ( start + last ) / 2 ; if ( start > last ) { return - 1 ; } if ( mid * mid == N ) { return ( int ) mid ; } else if ( mid * mid > N ) { return checkPerfectSquare ( N , start , mid - 1 ) ; } else { return checkPerfectSquare ( N , mid + 1 , last ) ; } } public static void main ( String [ ] args ) { long N = 65 ; System . out . println ( checkPerfectSquare ( N , 1 , N ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void minpoint ( int arr [ ] , int n , int k ) { int min_point = 0 ; for ( int i = 1 ; i < k - 1 ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) min_point += 1 ; } int final_point = min_point ; for ( int i = k ; i < n ; i ++ ) { if ( arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) + 1 ] && arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) - 1 ] ) min_point -= 1 ; if ( arr [ i - 1 ] < arr [ i ] && arr [ i - 1 ] < arr [ i - 2 ] ) min_point += 1 ; if ( min_point > final_point ) final_point = min_point ; } System . out . println ( final_point ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 4 , 2 , 3 , 4 , 1 , 2 } ; int n = arr . length ; int k = 4 ; minpoint ( arr , n , k ) ; } }

Index/key variables: i
Accumulator variables: i, min_point
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void CountStrings ( String [ ] str ) { int size = str . length ; int [ ] count = new int [ 26 ] ; boolean [ ] visited = new boolean [ 26 ] ; for ( int i = 0 ; i < size ; ++ i ) { for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { if ( visited [ str [ i ] . charAt ( j ) - ' a ' ] == false ) count [ str [ i ] . charAt ( j ) - ' a ' ] ++ ; visited [ str [ i ] . charAt ( j ) - ' a ' ] = true ; } for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { visited [ str [ i ] . charAt ( j ) - ' a ' ] = false ; } } for ( int i = 0 ; i < 26 ; ++ i ) { System . out . print ( count [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { String [ ] str = { " i " , " will " , " practice " , " everyday " } ; CountStrings ( str ) ; } }

Index/key variables: i
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void findSubArray ( int [ ] a , int n , int k ) { int [ ] pref = new int [ n ] ; pref [ 0 ] = 0 ; for ( int i = 1 ; i < n - 1 ; ++ i ) { pref [ i ] = pref [ i - 1 ] ; if ( a [ i ] > a [ i - 1 ] && a [ i ] > a [ i + 1 ] ) pref [ i ] ++ ; } int peak = 0 , left = 0 ; for ( int i = 0 ; i + k - 1 < n ; ++ i ) if ( pref [ i + k - 2 ] - pref [ i ] > peak ) { peak = pref [ i + k - 2 ] - pref [ i ] ; left = i ; } System . out . print ( " Left ▁ = ▁ " + ( left + 1 ) + "NEW_LINE"); System . out . print ( " Right ▁ = ▁ " + ( left + k ) + "NEW_LINE"); System . out . print ( " Peak ▁ = ▁ " + peak + "NEW_LINE"); } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 3 , 2 , 1 } ; int n = arr . length ; int k = 3 ; findSubArray ( arr , n , k ) ; } }

Index/key variables: i, n
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static void distanceSort ( int arr [ ] , int K , int n ) { Vector vd [ ] = new Vector [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { vd [ i ] = new Vector ( ) ; } int pos = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == K ) { pos = i ; break ; } } int i = pos - 1 , j = pos + 1 ; vd [ 0 ] . add ( arr [ pos ] ) ; while ( i >= 0 ) { vd [ pos - i ] . add ( arr [ i ] ) ; -- i ; } while ( j < n ) { vd [ j - pos ] . add ( arr [ j ] ) ; ++ j ; } for ( i = 0 ; i <= Math . max ( pos , n - pos - 1 ) ; ++ i ) { Collections . sort ( vd [ i ] ) ; for ( j = 0 ; j < vd [ i ] . size ( ) ; j ++ ) { int element = ( int ) vd [ i ] . get ( j ) ; System . out . print ( element + " ▁ " ) ; } } } public static void main ( String s [ ] ) { int arr [ ] = { 14 , 1101 , 10 , 35 , 0 } ; int K = 35 ; int n = arr . length ; distanceSort ( arr , K , n ) ; } }

Index/key variables: i, j, n, pos
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int [ ] find ( int dividend , int divisor , int start , int end ) { if ( start > end ) return new int [ ] { 0 , dividend } ; int mid = start + ( end - start ) / 2 ; int n = dividend - divisor * mid ; if ( n > divisor ) start = mid + 1 ; else if ( n < 0 ) end = mid - 1 ; else { if ( n == divisor ) { ++ mid ; n = 0 ; } return new int [ ] { mid , n } ; } return find ( dividend , divisor , start , end ) ; } static int [ ] divide ( int dividend , int divisor ) { return find ( dividend , divisor , 1 , dividend ) ; } public static void main ( String [ ] args ) { int dividend = 10 , divisor = 3 ; int [ ] ans = divide ( dividend , divisor ) ; System . out . print ( ans [ 0 ] + " , ▁ " ) ; System . out . print ( ans [ 1 ] + "NEW_LINE"); } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countTriplets ( int a [ ] , int n , int x ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { Vector < Integer > temp = new Vector < > ( ) ; temp . add ( a [ i ] ) ; temp . add ( a [ j ] ) ; temp . add ( a [ k ] ) ; Collections . sort ( temp ) ; if ( temp . get ( 0 ) < temp . get ( 1 ) && temp . get ( 1 ) < temp . get ( 2 ) && temp . get ( 0 ) * temp . get ( 1 ) * temp . get ( 2 ) <= x ) answer ++ ; } } } return answer ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 2 , 5 , 7 } ; int N = A . length ; int X = 42 ; System . out . println ( countTriplets ( A , N , X ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: answer, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int log ( int a , int b ) { return ( int ) ( Math . log10 ( a ) / Math . log10 ( b ) ) ; } static int get ( int a , int b , int n ) { int lo = 0 , hi = ( int ) 1e6 ; int ans = 0 ; while ( lo <= hi ) { int mid = ( lo + hi ) / 2 ; int dig = ( int ) Math . ceil ( ( mid * log ( mid , b ) + log ( a , b ) ) ) ; if ( dig > n ) { hi = mid - 1 ; } else { ans = mid ; lo = mid + 1 ; } } return ans ; } public static void main ( String [ ] args ) { int a = 2 , b = 2 , n = 6 ; System . out . print ( get ( a , b , n ) + "NEW_LINE"); } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMaxMatrixSize ( int [ ] [ ] arr , int K ) { int i , j ; int n = arr . length ; int m = arr [ 0 ] . length ; int [ ] [ ] sum = new int [ n + 1 ] [ m + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= m ; j ++ ) { if ( i == 0 j == 0 ) { sum [ i ] [ j ] = 0 ; continue ; } sum [ i ] [ j ] = arr [ i - 1 ] [ j - 1 ] + sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] ; } } int ans = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { if ( i + ans - 1 > n j + ans - 1 > m ) break ; int mid , lo = ans ; int hi = Math . min ( n - i + 1 , m - j + 1 ) ; while ( lo < hi ) { mid = ( hi + lo + 1 ) / 2 ; if ( sum [ i + mid - 1 ] [ j + mid - 1 ] + sum [ i - 1 ] [ j - 1 ] - sum [ i + mid - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j + mid - 1 ] <= K ) { lo = mid ; } else { hi = mid - 1 ; } } ans = Math . max ( ans , lo ) ; } } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 1 , 3 , 2 , 4 , 3 , 2 } , { 1 , 1 , 3 , 2 , 4 , 3 , 2 } , { 1 , 1 , 3 , 2 , 4 , 3 , 2 } } ; int K = 4 ; findMaxMatrixSize ( arr , K ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void FindRank ( int arr [ ] , int length ) { System . out . print ( "1" + " ▁ " ) ; for ( int i = 1 ; i < arr . length ; i ++ ) { int rank = 1 ; for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) rank ++ ; } System . out . print ( rank + " ▁ " ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 88 , 14 , 69 , 30 , 29 , 89 } ; int len = arr . length ; FindRank ( arr , len ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, rank
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int longestPermutation ( int arr [ ] , int n ) { HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . containsKey ( arr [ i ] ) ) { freq . put ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . put ( arr [ i ] , 1 ) ; } } int len = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ! freq . containsKey ( i ) ) { break ; } len ++ ; } return len ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 6 , 5 } ; int n = arr . length ; System . out . print ( longestPermutation ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 1000005 ; static Set < Integer > fib = new HashSet < Integer > ( ) ; static void fibonacci ( ) { int prev = 0 , curr = 1 , len = 2 ; fib . add ( prev ) ; fib . add ( curr ) ; while ( len <= MAX ) { int temp = curr + prev ; fib . add ( temp ) ; prev = curr ; curr = temp ; len ++ ; } } static void findFibonacci ( int N ) { for ( int i = N / 2 ; i > 1 ; i -- ) { if ( fib . contains ( i ) && fib . contains ( N - i ) ) { System . out . println ( i + " ▁ " + ( N - i ) ) ; return ; } } System . out . println ( " - 1" ) ; } public static void main ( String args [ ] ) { fibonacci ( ) ; int sum = 199 ; findFibonacci ( sum ) ; } }

Accumulator variables: i, len
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAX = 100005 ; static HashSet < Integer > fibonacci = new HashSet < Integer > ( ) ; static void createHash ( ) { int prev = 0 , curr = 1 ; fibonacci . add ( prev ) ; fibonacci . add ( curr ) ; while ( curr <= MAX ) { int temp = curr + prev ; fibonacci . add ( temp ) ; prev = curr ; curr = temp ; } } static boolean checkArray ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( fibonacci . contains ( arr [ i ] ) ) sum += arr [ i ] ; if ( fibonacci . contains ( sum ) ) return true ; return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 8 , 2 } ; int n = arr . length ; createHash ( ) ; if ( checkArray ( arr , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 1000005 ; static int [ ] fibUpto = new int [ MAX + 1 ] ; static void compute ( int sz ) { boolean [ ] isFib = new boolean [ sz + 1 ] ; int prev = 0 , curr = 1 ; isFib [ prev ] = isFib [ curr ] = true ; while ( curr <= sz ) { int temp = curr + prev ; if ( temp <= sz ) isFib [ temp ] = true ; prev = curr ; curr = temp ; } fibUpto [ 0 ] = 1 ; for ( int i = 1 ; i <= sz ; i ++ ) { fibUpto [ i ] = fibUpto [ i - 1 ] ; if ( isFib [ i ] ) fibUpto [ i ] ++ ; } } static int countOfNumbers ( int N , int K ) { compute ( N ) ; int low = 1 , high = N , ans = 0 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( mid - fibUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ( ans > 0 ? N - ans + 1 : 0 ) ; } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; System . out . print ( countOfNumbers ( N , K ) ) ; } }

Index/key variables: curr, i, mid, prev, temp
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 100001 ; static int [ ] [ ] f = new int [ 26 ] [ N ] ; static void precompute ( String s , int n ) { for ( int i = 0 ; i < n ; i ++ ) { f [ s . charAt ( i ) - ' a ' ] [ i ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { f [ i ] [ j ] += f [ i ] [ j - 1 ] ; } } } static int palindromicSubsequencesUtil ( int L , int R ) { int c = 0 , ok = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int cnt = f [ i ] [ R ] ; if ( L > 0 ) cnt -= f [ i ] [ L - 1 ] ; if ( cnt > 1 ) { ok = 1 ; c = i ; break ; } } if ( ok == 0 ) { return - 1 ; } return c ; } static void palindromicSubsequences ( int Q [ ] [ ] , int l ) { for ( int i = 0 ; i < l ; i ++ ) { int x = palindromicSubsequencesUtil ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; if ( x == - 1 ) { System . out . print ( - 1 + "NEW_LINE"); } else { char c = ( char ) ( ' a ' + x ) ; System . out . print ( ( char ) c + " " + ( char ) c + "NEW_LINE"); } } } public static void main ( String [ ] args ) { String str = " dbdeke " ; int Q [ ] [ ] = { { 0 , 5 } , { 1 , 5 } , { 1 , 3 } } ; int n = str . length ( ) ; int l = Q . length ; precompute ( str , n ) ; palindromicSubsequences ( Q , l ) ; } }

Index/key variables: N, R, i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG