dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function sort ( arr ) { var n = arr . length ; var output = Array . from ( { length : n } , ( _ , i ) => 0 ) ; var count = Array . from ( { length : 256 } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < n ; ++ i ) ++ count [ arr [ i ] . charCodeAt ( 0 ) ] ; for ( var i = 1 ; i <= 255 ; ++ i ) count [ i ] += count [ i - 1 ] ; for ( var i = n - 1 ; i >= 0 ; i -- ) { output [ count [ arr [ i ] . charCodeAt ( 0 ) ] - 1 ] = arr [ i ] ; -- count [ arr [ i ] . charCodeAt ( 0 ) ] ; } for ( var i = 0 ; i < n ; ++ i ) arr [ i ] = output [ i ] ; return arr ; } var arr = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; arr = sort ( arr ) ; document . write ( " " ) ; for ( var i = 0 ; i < arr . length ; ++ i ) document . write ( arr [ i ] ) ; cript

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSort ( arr ) { var max = Math . max . apply ( Math , arr ) ; var min = Math . min . apply ( Math , arr ) ; var range = max - min + 1 ; var count = Array . from ( { length : range } , ( _ , i ) => 0 ) ; var output = Array . from ( { length : arr . length } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < arr . length ; i ++ ) { count [ arr [ i ] - min ] ++ ; } for ( i = 1 ; i < count . length ; i ++ ) { count [ i ] += count [ i - 1 ] ; } for ( i = arr . length - 1 ; i >= 0 ; i -- ) { output [ count [ arr [ i ] - min ] - 1 ] = arr [ i ] ; count [ arr [ i ] - min ] -- ; } for ( i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = output [ i ] ; } } function printArray ( arr ) { for ( i = 0 ; i < arr . length ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( ' ' ) ; } var arr = [ - 5 , - 10 , 0 , - 3 , 8 , 5 , - 1 , 10 ] ; countSort ( arr ) ; printArray ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { let C = new Array ( k + 1 ) ; C . fill ( 0 ) ; C [ 0 ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = Math . min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } let n = 5 , k = 2 ; document . write ( " " + n + " " + k + " " + binomialCoeff ( n , k ) ) ;

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findPartiion ( arr , n ) { let sum = 0 ; let i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; let part = new Array ( parseInt ( sum / 2 + 1 , 10 ) ) ; for ( i = 0 ; i <= parseInt ( sum / 2 , 10 ) ; i ++ ) { part [ i ] = false ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = parseInt ( sum / 2 , 10 ) ; j >= arr [ i ] ; j -- ) { if ( part [ j - arr [ i ] ] == true j == arr [ i ] ) part [ j ] = true ; } } return part [ parseInt ( sum / 2 , 10 ) ] ; } let arr = [ 1 , 3 , 3 , 2 , 3 , 2 ] ; let n = arr . length ; if ( findPartiion ( arr , n ) == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findoptimal ( N ) { if ( N <= 6 ) return N ; let max = 0 ; let b ; for ( b = N - 3 ; b >= 1 ; b -- ) { let curr = ( N - b - 1 ) * findoptimal ( b ) ; if ( curr > max ) max = curr ; } return max ; } let N ; for ( N = 1 ; N <= 20 ; N ++ ) document . write ( " " + N + " " + findoptimal ( N ) + " " ) ;

Accumulator variables: N, b
Iterator variables: N, b
Javascript program:
function findoptimal ( N ) { if ( N <= 6 ) return N ; let screen = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { screen [ i ] = 0 ; } let b ; let n ; for ( n = 1 ; n <= 6 ; n ++ ) screen [ n - 1 ] = n ; for ( n = 7 ; n <= N ; n ++ ) { screen [ n - 1 ] = 0 ; for ( b = n - 3 ; b >= 1 ; b -- ) { let curr = ( n - b - 1 ) * screen [ b - 1 ] ; if ( curr > screen [ n - 1 ] ) screen [ n - 1 ] = curr ; } } return screen [ N - 1 ] ; } let N ; for ( N = 1 ; N <= 20 ; N ++ ) document . write ( " " + N + " " + findoptimal ( N ) + " " ) ;

Index/key variables: i
Accumulator variables: N, b, i, n
Iterator variables: N, b, i, n
Javascript program:
function findoptimal ( N ) { if ( N <= 6 ) return N ; let screen = [ ] ; let b ; let n ; for ( n = 1 ; n <= 6 ; n ++ ) screen [ n - 1 ] = n ; for ( n = 7 ; n <= N ; n ++ ) { screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ; } return screen [ N - 1 ] ; } let N ; for ( N = 1 ; N <= 20 ; N ++ ) document . write ( " " + N + " " + findoptimal ( N ) + " " ) ;

Accumulator variables: N, n
Iterator variables: N, n
Javascript program:
function getAvg ( prev_avg , x , n ) { return ( prev_avg * n + x ) / ( n + 1 ) ; } function streamAvg ( arr , n ) { let avg = 0 ; for ( let i = 0 ; i < n ; i ++ ) { avg = getAvg ( avg , arr [ i ] , i ) ; document . write ( " " + ( i + 1 ) + " " + avg . toFixed ( 6 ) + " " ) ; } return ; } let arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ; let n = arr . length ; streamAvg ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var sum = 0 , n = 0 ; function getAvg ( x ) { sum += x ; n ++ ; return ( sum / n ) ; } function streamAvg ( arr , m ) { var avg = 0 ; for ( i = 0 ; i < m ; i ++ ) { avg = getAvg ( parseInt ( arr [ i ] ) ) ; document . write ( " " + ( i + 1 ) + " " + avg . toFixed ( 1 ) + " " ) ; } return ; } var arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ; var m = arr . length ; streamAvg ( arr , m ) ;

Index/key variables: i
Accumulator variables: i, n, sum
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } let n = 8 ; let k = 2 ; document . write ( " " + n + " " + k + " " + " " + " " + binomialCoeff ( n , k ) ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function primeFactors ( n ) { while ( n % 2 == 0 ) { document . write ( 2 + " " ) ; n = Math . floor ( n / 2 ) ; } for ( let i = 3 ; i <= Math . floor ( Math . sqrt ( n ) ) ; i = i + 2 ) { while ( n % i == 0 ) { document . write ( i + " " ) ; n = Math . floor ( n / i ) ; } } if ( n > 2 ) document . write ( n + " " ) ; } let n = 315 ; primeFactors ( n ) ;

Iterator variables: i
Javascript program:
function printCombination ( arr , n , r ) { let data = new Array ( r ) ; combinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ; } function combinationUtil ( arr , data , start , end , index , r ) { if ( index == r ) { for ( let j = 0 ; j < r ; j ++ ) { document . write ( data [ j ] + " " ) ; } document . write ( " " ) } for ( let i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { data [ index ] = arr [ i ] ; combinationUtil ( arr , data , i + 1 , end , index + 1 , r ) ; } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let r = 3 ; let n = arr . length ; printCombination ( arr , n , r ) ;

Index/key variables: i, index, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printCombination ( arr , n , r ) { let data = new Array ( r ) ; combinationUtil ( arr , n , r , 0 , data , 0 ) ; } function combinationUtil ( arr , n , r , index , data , i ) { if ( index == r ) { for ( let j = 0 ; j < r ; j ++ ) { document . write ( data [ j ] + " " ) ; } document . write ( " " ) ; return ; } if ( i >= n ) { return ; } data [ index ] = arr [ i ] ; combinationUtil ( arr , n , r , index + 1 , data , i + 1 ) ; combinationUtil ( arr , n , r , index , data , i + 1 ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let r = 3 ; let n = arr . length ; printCombination ( arr , n , r ) ;

Index/key variables: i, index, j
Accumulator variables: j
Iterator variables: j
Javascript program:
function findgroups ( arr , n ) { let c = [ 0 , 0 , 0 ] ; let i ; let res = 0 ; for ( i = 0 ; i < n ; i ++ ) c [ arr [ i ] % 3 ] ++ ; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ; res += c [ 1 ] * c [ 2 ] ; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * Math . floor ( ( c [ 0 ] - 2 ) ) / 6 ) ; res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * Math . floor ( ( c [ 1 ] - 2 ) ) / 6 ) ; res += ( Math . floor ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ; res += c [ 0 ] * c [ 1 ] * c [ 2 ] ; return res ; } let arr = [ 3 , 6 , 7 , 2 , 9 ] ; let n = arr . length ; document . write ( " " + findgroups ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function nextPowerOf2 ( n ) { n -= 1 n |= n >> 1 n |= n >> 2 n |= n >> 4 n |= n >> 8 n |= n >> 16 n += 1 return n } n = 5 ; document . write ( nextPowerOf2 ( n ) ) ;

Accumulator variables: n
Javascript program:
function segregate0and1 ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) count ++ ; } for ( let i = 0 ; i < count ; i ++ ) arr [ i ] = 0 ; for ( let i = count ; i < n ; i ++ ) arr [ i ] = 1 ; } function print ( arr , n ) { document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 0 , 1 , 0 , 1 , 1 , 1 ] ; let n = arr . length ; segregate0and1 ( arr , n ) ; print ( arr , n ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function segregate0and1 ( arr , size ) { let left = 0 , right = size - 1 ; while ( left < right ) { while ( arr [ left ] == 0 && left < right ) left ++ ; while ( arr [ right ] == 1 && left < right ) right -- ; if ( left < right ) { arr [ left ] = 0 ; arr [ right ] = 1 ; left ++ ; right -- ; } } } let arr = [ 0 , 1 , 0 , 1 , 1 , 1 ] ; let i , arr_size = arr . length ; segregate0and1 ( arr , arr_size ) ; document . write ( " " ) ; for ( i = 0 ; i < 6 ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, left, right
Accumulator variables: i, left, right
Iterator variables: i
Javascript program:
function segregate0and1 ( arr , size ) { let type0 = 0 ; let type1 = size - 1 ; while ( type0 < type1 ) { if ( arr [ type0 ] == 1 ) { arr [ type1 ] = arr [ type1 ] + arr [ type0 ] ; arr [ type0 ] = arr [ type1 ] - arr [ type0 ] ; arr [ type1 ] = arr [ type1 ] - arr [ type0 ] ; type1 -- ; } else type0 ++ ; } } let arr = [ 0 , 1 , 0 , 1 , 1 , 1 ] ; let i , arr_size = arr . length ; segregate0and1 ( arr , arr_size ) ; document . write ( " " ) ; for ( i = 0 ; i < arr_size ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, type0, type1
Accumulator variables: i, type0, type1
Iterator variables: i
Javascript program:
function distinctAdjacentElement ( a , n ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { m [ a [ i ] ] ++ ; if ( m . has ( a [ i ] ) ) { m . set ( a [ i ] , m . get ( a [ i ] ) + 1 ) } else { m . set ( a [ i ] , 1 ) } } let mx = 0 ; for ( let i = 0 ; i < n ; ++ i ) if ( mx < m . get ( a [ i ] ) ) mx = m . get ( a [ i ] ) ; if ( mx > Math . floor ( ( n + 1 ) / 2 ) ) document . write ( " " + " " ) ; else document . write ( " " ) ; } let a = [ 7 , 7 , 7 , 7 ] ; let n = a . length ; distinctAdjacentElement ( a , n ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function maxIndexDiff ( arr , n ) { let maxDiff = - 1 ; let i , j ; for ( i = 0 ; i < n ; ++ i ) { for ( j = n - 1 ; j > i ; -- j ) { if ( arr [ j ] > arr [ i ] && maxDiff < ( j - i ) ) maxDiff = j - i ; } } return maxDiff ; } let arr = [ 9 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 18 , 0 ] ; let n = arr . length ; let maxDiff = maxIndexDiff ( arr , n ) ; document . write ( maxDiff ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
let v = [ 34 , 8 , 10 , 3 , 2 , 80 , 30 , 33 , 1 ] ; let n = v . length ; let maxFromEnd = new Array ( n + 1 ) ; for ( let i = 0 ; i < maxFromEnd . length ; i ++ ) maxFromEnd [ i ] = Number . MIN_VALUE ; for ( let i = v . length - 1 ; i >= 0 ; i -- ) { maxFromEnd [ i ] = Math . max ( maxFromEnd [ i + 1 ] , v [ i ] ) ; } let result = 0 ; for ( let i = 0 ; i < v . length ; i ++ ) { let low = i + 1 , high = v . length - 1 , ans = i ; while ( low <= high ) { let mid = parseInt ( ( low + high ) / 2 , 10 ) ; if ( v [ i ] <= maxFromEnd [ mid ] ) { ans = Math . max ( ans , mid ) ; low = mid + 1 ; } else { high = mid - 1 ; } } result = Math . max ( result , ans - i ) ; } document . write ( result ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSwapsToSort ( arr , n ) { let arrPos = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { arrPos . push ( [ arr [ i ] , i ] ) ; } arrPos . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; let vis = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { vis [ i ] = false ; } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] [ 1 ] == i ) continue ; let cycle_size = 0 ; let j = i ; while ( ! vis [ j ] ) { vis [ j ] = true ; j = arrPos [ j ] [ 1 ] ; cycle_size ++ ; } ans += ( cycle_size - 1 ) ; } return ans ; } function minSwapToMakeArraySame ( a , b , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mp . set ( b [ i ] , i ) ; } for ( let i = 0 ; i < n ; i ++ ) b [ i ] = mp . get ( a [ i ] ) ; return minSwapsToSort ( b , n ) ; } let a = [ 3 , 6 , 4 , 8 ] ; let b = [ 4 , 6 , 8 , 3 ] ; let n = a . length ; document . write ( minSwapToMakeArraySame ( a , b , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, cycle_size, i
Iterator variables: i
Javascript program:
function missingK ( a , k , n ) { let difference = 0 , ans = 0 , count = k ; let flag = false ; for ( let i = 0 ; i < n - 1 ; i ++ ) { difference = 0 ; if ( ( a [ i ] + 1 ) != a [ i + 1 ] ) { difference += ( a [ i + 1 ] - a [ i ] ) - 1 ; if ( difference >= count ) { ans = a [ i ] + count ; flag = true ; break ; } else count -= difference ; } } if ( flag ) return ans ; else return - 1 ; } let a = [ 1 , 5 , 11 , 19 ] ; let k = 11 ; let n = a . length ; let missing = missingK ( a , k , n ) ; document . write ( missing ) ;

Index/key variables: i
Accumulator variables: count, difference, i
Iterator variables: i
Boolean variables: flag
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } document . write ( ) ; } function newNode ( key ) { var temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } function insertBeg ( head , val ) { var temp = newNode ( val ) ; temp . next = head ; head = temp ; return head ; } function rearrangeOddEven ( head ) { var odd = [ ] ; var even = [ ] ; var i = 1 ; while ( head != null ) { if ( head . data % 2 != 0 && i % 2 == 0 ) { odd . push ( head ) ; } else if ( head . data % 2 == 0 && i % 2 != 0 ) { even . push ( head ) ; } head = head . next ; i ++ ; } while ( odd . length > 0 && even . length > 0 ) { var k = odd [ odd . length - 1 ] . data ; odd [ odd . length - 1 ] . data = even [ even . length - 1 ] . data ; even [ even . length - 1 ] . data = k ; odd . pop ( ) ; even . pop ( ) ; } } var head = newNode ( 8 ) ; head = insertBeg ( head , 7 ) ; head = insertBeg ( head , 6 ) ; head = insertBeg ( head , 5 ) ; head = insertBeg ( head , 3 ) ; head = insertBeg ( head , 2 ) ; head = insertBeg ( head , 1 ) ; document . write ( " " ) ; printList ( head ) ; rearrangeOddEven ( head ) ; document . write ( " " + " " ) ; printList ( head ) ;

Accumulator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } document . write ( " " ) ; } function newNode ( key ) { var temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } function insertBeg ( head , val ) { var temp = newNode ( val ) ; temp . next = head ; head = temp ; return head ; } function rearrange ( head ) { var even ; var temp , prev_temp ; var i , j , k , l , ptr = null ; temp = ( head ) . next ; prev_temp = head ; while ( temp != null ) { var x = temp . next ; if ( temp . data % 2 != 0 ) { prev_temp . next = x ; temp . next = ( head ) ; ( head ) = temp ; } else { prev_temp = temp ; } temp = x ; } temp = ( head ) . next ; prev_temp = ( head ) ; while ( temp != null && temp . data % 2 != 0 ) { prev_temp = temp ; temp = temp . next ; } even = temp ; prev_temp . next = null ; i = head ; j = even ; while ( j != null && i != null ) { k = i . next ; l = j . next ; i . next = j ; j . next = k ; ptr = j ; i = k ; j = l ; } if ( i == null ) { ptr . next = j ; } return head ; } var head = newNode ( 8 ) ; head = insertBeg ( head , 7 ) ; head = insertBeg ( head , 6 ) ; head = insertBeg ( head , 3 ) ; head = insertBeg ( head , 5 ) ; head = insertBeg ( head , 1 ) ; head = insertBeg ( head , 2 ) ; head = insertBeg ( head , 10 ) ; document . write ( " " ) ; printList ( head ) ; document . write ( " " ) ; head = rearrange ( head ) ; printList ( head ) ;

Class/struct names: Node
Javascript program:
function print ( mat ) { for ( let i = 0 ; i < mat . length ; i ++ ) { for ( let j = 0 ; j < mat [ 0 ] . length ; j ++ ) document . write ( mat [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } function performSwap ( mat , i , j ) { let N = mat . length ; let ei = N - 1 - i ; let ej = N - 1 - j ; let temp = mat [ i ] [ j ] ; mat [ i ] [ j ] = mat [ ej ] [ i ] ; mat [ ej ] [ i ] = mat [ ei ] [ ej ] ; mat [ ei ] [ ej ] = mat [ j ] [ ei ] ; mat [ j ] [ ei ] = temp ; } function rotate ( mat , N , K ) { K = K % 4 ; while ( K -- > 0 ) { for ( let i = 0 ; i < N / 2 ; i ++ ) { for ( let j = i ; j < N - i - 1 ; j ++ ) { if ( i != j && ( i + j ) != N - 1 ) { performSwap ( mat , i , j ) ; } } } } print ( mat ) ; } let K = 5 ; let mat = [ [ 1 , 2 , 3 , 4 ] , [ 6 , 7 , 8 , 9 ] , [ 11 , 12 , 13 , 14 ] , [ 16 , 17 , 18 , 19 ] , ] ; let N = mat . length ; rotate ( mat , N , K ) ;

Index/key variables: ei, ej, i, j
Accumulator variables: K, i, j
Iterator variables: i, j
Javascript program:
let MAX = 10000 ; let prefix = Array . from ( { length : MAX + 1 } , ( _ , i ) => 0 ) ; function isPowerOfTwo ( x ) { if ( x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ) return true ; return false ; } function computePrefix ( n , a ) { if ( isPowerOfTwo ( a [ 0 ] ) ) prefix [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] ; if ( isPowerOfTwo ( a [ i ] ) ) prefix [ i ] ++ ; } } function query ( L , R ) { if ( L == 0 ) return prefix [ R ] ; return prefix [ R ] - prefix [ L - 1 ] ; } let A = [ 3 , 8 , 5 , 2 , 5 , 10 ] ; let N = A . length ; computePrefix ( N , A ) ; document . write ( query ( 0 , 4 ) + " " ) ; document . write ( query ( 3 , 5 ) ) ;

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findNextNumber ( n ) { let h = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; let i = 0 , msb = n , rem = 0 ; let next_num = - 1 , count = 0 ; while ( msb > 9 ) { rem = msb % 10 ; h [ rem ] = 1 ; msb = Math . floor ( msb / 10 ) ; count ++ ; } h [ msb ] = 1 ; count ++ ; for ( i = msb + 1 ; i < 10 ; i ++ ) { if ( h [ i ] == 0 ) { next_num = i ; break ; } } if ( next_num == - 1 ) { for ( i = 1 ; i < msb ; i ++ ) { if ( h [ i ] == 0 ) { next_num = i ; count ++ ; break ; } } } if ( next_num > 0 ) { for ( i = 0 ; i < 10 ; i ++ ) { if ( h [ i ] == 0 ) { msb = i ; break ; } } for ( i = 1 ; i < count ; i ++ ) { next_num = ( ( next_num * 10 ) + msb ) ; } if ( next_num > n ) document . write ( next_num + " " ) ; else document . write ( " " ) ; } else { document . write ( " " ) ; } } let n = 2019 ; findNextNumber ( n ) ;

Index/key variables: i, msb, rem
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function CalculateValues ( N ) { var A = 0 , B = 0 , C = 0 ; for ( C = 0 ; C < N / 7 ; C ++ ) { for ( B = 0 ; B < N / 5 ; B ++ ) { var A = N - 7 * C - 5 * B ; if ( A >= 0 && A % 3 == 0 ) { document . write ( " " + A / 3 + " " + B + " " + C ) ; return ; } } } document . write ( - 1 ) ; } var N = 19 ; CalculateValues ( 19 ) ;

Accumulator variables: B, C
Iterator variables: B, C
Javascript program:
function minimumTime ( arr , n ) { var sum = 0 ; var T = Math . max ( ... arr ) ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } document . write ( Math . max ( 2 * T , sum ) ) ; } var arr = [ 2 , 8 , 3 ] ; var N = arr . length ; minimumTime ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function lexicographicallyMax ( s ) { var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) { var count = 0 ; var beg = i ; var end = i ; if ( s [ i ] == ' ' ) count ++ ; for ( var j = i + 1 ; j < n ; j ++ ) { if ( s [ j ] == ' ' ) count ++ ; if ( count % 2 == 0 && count != 0 ) { end = j ; break ; } } for ( var i = beg ; i < parseInt ( ( end + 1 ) / 2 ) ; i ++ ) { let temp = s [ i ] ; s [ i ] = s [ end - i + 1 ] ; s [ end - i + 1 ] = temp ; } } document . write ( s . join ( " " ) + " " ) ; } var S = " " . split ( ' ' ) ; lexicographicallyMax ( S ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function maxPairs ( nums , k ) { nums . sort ( ) ; let result = 0 ; let start = 0 , end = nums . length - 1 ; while ( start < end ) { if ( nums [ start ] + nums [ end ] > k ) end -- ; else if ( nums [ start ] + nums [ end ] < k ) start ++ ; else { start ++ ; end -- ; result ++ ; } } document . write ( result ) ; } let arr = [ 1 , 2 , 3 , 4 ] ; let K = 5 ; maxPairs ( arr , K ) ;

Index/key variables: end, start
Accumulator variables: end, result, start
Javascript program:
function maxPairs ( nums , k ) { var m = new Map ( ) ; var result = 0 ; nums . forEach ( i => { if ( m . has ( i ) && m . get ( i ) > 0 ) { m . set ( i , m . get ( i ) - 1 ) ; result ++ ; } else { if ( m . has ( k - i ) ) m . set ( k - i , m . get ( k - i ) + 1 ) else m . set ( k - i , 1 ) } } ) ; document . write ( result ) ; } var arr = [ 1 , 2 , 3 , 4 ] ; var K = 5 ; maxPairs ( arr , K ) ;

Accumulator variables: result
Javascript program:
function removeIndicesToMakeSumEqual ( arr ) { var N = arr . length ; var odd = Array ( N ) . fill ( 0 ) ; var even = Array ( N ) . fill ( 0 ) ; even [ 0 ] = arr [ 0 ] ; for ( i = 1 ; i < N ; i ++ ) { odd [ i ] = odd [ i - 1 ] ; even [ i ] = even [ i - 1 ] ; if ( i % 2 == 0 ) { even [ i ] += arr [ i ] ; } else { odd [ i ] += arr [ i ] ; } } var find = false ; var p = odd [ N - 1 ] ; var q = even [ N - 1 ] - arr [ 0 ] ; if ( p == q ) { document . write ( " " ) ; find = true ; } for ( i = 1 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { p = even [ N - 1 ] - even [ i - 1 ] - arr [ i ] + odd [ i - 1 ] ; q = odd [ N - 1 ] - odd [ i - 1 ] + even [ i - 1 ] ; } else { q = odd [ N - 1 ] - odd [ i - 1 ] - arr [ i ] + even [ i - 1 ] ; p = even [ N - 1 ] - even [ i - 1 ] + odd [ i - 1 ] ; } if ( p == q ) { find = true ; document . write ( i + " " ) ; } } if ( ! find ) { document . write ( - 1 ) ; } } var arr = [ 4 , 1 , 6 , 2 ] ; removeIndicesToMakeSumEqual ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: find
Javascript program:
function min_element_removal ( arr , N ) { var left = Array ( N ) . fill ( 1 ) ; var right = Array ( N ) . fill ( 1 ) ; for ( var i = 1 ; i < N ; i ++ ) { for ( var j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { left [ i ] = Math . max ( left [ i ] , left [ j ] + 1 ) ; } } } for ( var i = N - 2 ; i >= 0 ; i -- ) { for ( var j = N - 1 ; j > i ; j -- ) { if ( arr [ i ] > arr [ j ] ) { right [ i ] = Math . max ( right [ i ] , right [ j ] + 1 ) ; } } } var maxLen = 0 ; for ( var i = 1 ; i < N - 1 ; i ++ ) { maxLen = Math . max ( maxLen , left [ i ] + right [ i ] - 1 ) ; } document . write ( ( N - maxLen ) + " " ) ; } function makeBitonic ( arr , N ) { if ( N == 1 ) { document . write ( " " + " " ) ; return ; } if ( N == 2 ) { if ( arr [ 0 ] != arr [ 1 ] ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; return ; } min_element_removal ( arr , N ) ; } var arr = [ 2 , 1 , 1 , 5 , 6 , 2 , 3 , 1 ] ; var N = arr . length ; makeBitonic ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j