dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function longestSubarray ( arr , N , K ) { let um = new Map ( ) ; let sum = 0 , maxLen = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; if ( sum == K ) maxLen = i + 1 ; if ( ! um . has ( sum ) ) um . set ( sum , i ) ; if ( um . has ( sum - K ) ) { if ( maxLen < ( i - um . get ( sum - K ) ) ) maxLen = i - um . get ( sum - K ) ; } } return maxLen ; } function minRequiredOperation ( arr , N , K ) { let TotalSum = 0 ; for ( let i = 0 ; i < N ; i ++ ) TotalSum += arr [ i ] ; let maxLen = longestSubarray ( arr , N , TotalSum - K ) ; if ( maxLen == - 1 ) { document . write ( - 1 ) ; } else document . write ( N - maxLen ) ; } let arr = [ 1 , 3 , 1 , 1 , 2 ] ; let K = 4 ; let N = arr . length minRequiredOperation ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: TotalSum, i, sum
Iterator variables: i
Javascript program:
function minimumDeletions ( s ) { let n = s . length ; let ans = n ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let t = s [ i ] - ' ' ; if ( t % 2 == 0 ) { for ( let j = i - 1 ; j >= 0 ; j -- ) { let num = ( s [ j ] - ' ' ) * 10 + t ; if ( num % 4 === 0 ) { let k1 = i - j - 1 ; let k2 = n - i - 1 ; ans = Math . min ( ans , k1 + k2 ) ; } } } } if ( ans === n ) { for ( let i = 0 ; i < n ; i ++ ) { let num = s [ i ] - ' ' ; if ( num % 4 === 0 ) { ans = n - 1 ; } } } document . write ( ans ) ; } let str = " " ; minimumDeletions ( str ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function generateSequence ( arr , n ) { var ans ; ans = ( arr [ 0 ] . toString ( ) ) ; if ( n == 1 ) document . write ( ans ) ; else if ( n == 2 ) { document . write ( ans + " " + ( arr [ 1 ] . toString ( ) ) ) ; } else { ans += " " + ( arr [ 1 ] . toString ( ) ) ; for ( var i = 2 ; i < n ; i ++ ) { ans += " " + ( arr [ i ] . toString ( ) ) ; } ans += " " ; document . write ( ans ) ; } } var arr = [ 1000 , 100 , 10 , 2 ] ; var N = arr . length ; generateSequence ( arr , N ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function LCMPairs ( arr , N ) { var total_pairs = ( N * ( N - 1 ) ) / 2 ; var odd = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } odd = ( odd * ( odd - 1 ) ) / 2 ; document . write ( " " + ( total_pairs - odd ) + " " + odd ) ; } var arr = [ 3 , 6 , 5 , 4 ] ; var N = arr . length ; LCMPairs ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Javascript program:
function countEvenOdd ( L , R ) { let range = R - L + 1 ; let even = parseInt ( range / 4 ) * 2 ; if ( ( L & 1 ) && ( range % 4 == 3 ) ) { even ++ ; } else if ( ! ( L & 1 ) && ( range % 4 ) ) { even ++ ; } document . write ( " " + even + " " + ( range - even ) ) ; } let L = 2 , R = 7 ; countEvenOdd ( L , R ) ;

Accumulator variables: even
Javascript program:
function countSwaps ( S , T ) { var value = [ ... Array ( 26 ) ] ; for ( var i = 0 ; i < 26 ; i ++ ) value [ i ] = i + 1 ; var N = S . length ; var sum1 = 0 ; var sum2 = 0 ; var flag = false ; for ( var i = 0 ; i < N ; i ++ ) { sum1 += value [ S [ i ] - " " ] ; sum2 += value [ T [ i ] - " " ] ; if ( ( value [ S [ i ] - " " ] % 2 === 0 && value [ T [ i ] - " " ] % 2 === 1 ) || ( value [ S [ i ] - " " ] % 2 === 1 && value [ T [ i ] - " " ] % 2 === 0 ) ) flag = false ; } if ( sum1 % 2 === 1 && sum2 % 2 === 1 ) document . write ( " " ) ; else if ( sum1 % 2 === 0 && sum2 % 2 === 0 ) { if ( flag ) document . write ( " " ) ; else document . write ( " " ) ; } else { document . write ( " " ) ; } } var S = " " ; var T = " " ; countSwaps ( S , T ) ;

Index/key variables: i
Accumulator variables: i, sum1, sum2
Iterator variables: i
Boolean variables: flag
Javascript program:
function isPrime ( N ) { if ( N <= 1 ) return false ; for ( let i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } function countPrimeTuples ( N ) { let count = 0 ; for ( let i = 2 ; i <= N ; i ++ ) { if ( isPrime ( i ) && isPrime ( i - 2 ) ) count ++ ; } document . write ( count ) ; } let N = 6 ; countPrimeTuples ( N ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countPairs ( A , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) if ( ( A [ i ] A [ j ] ) > ( A [ i ] & A [ j ] ) ) { count ++ ; } } document . write ( count ) ; } var A = [ 1 , 4 , 7 ] ; var N = A . length ; countPairs ( A , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function maximumCandy ( candies , safety , N , M ) { let total = 0 ; let ans = Number . MAX_VALUE ; let all_safe = true ; for ( let i = 0 ; i < N ; i ++ ) { if ( candies [ i ] + M > safety [ i ] ) { all_safe = false ; ans = Math . min ( ans , safety [ i ] ) ; } else { ans = Math . min ( ans , candies [ i ] + M ) ; } total += candies [ i ] ; } if ( all_safe ) return total ; else return ans ; } let A = [ 4 , 5 , 2 , 3 ] ; let B = [ 8 , 13 , 6 , 4 ] ; let M = 5 ; let N = A . length ; document . write ( maximumCandy ( A , B , N , M ) ) ;

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Boolean variables: all_safe
Javascript program:
function checkArrays ( arr1 , arr2 , N ) { let count = 0 ; let flag = true ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) { if ( arr1 [ i ] == 0 ) count ++ ; else { count -- ; if ( count < 0 ) { flag = false ; break ; } } } } if ( ( flag && ( count == 0 ) ) == true ) document . write ( " " ) ; else document . write ( " " ) ; } let arr1 = [ 0 , 0 , 1 , 1 ] ; let arr2 = [ 1 , 1 , 0 , 0 ] ; let N = arr1 . length ; checkArrays ( arr1 , arr2 , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function MinimumMoves ( A , B , N ) { let totalOperations = 0 ; let carry = 0 ; let K = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { let nearestMultiple = ( Math . ceil ( ( A [ i ] + carry ) / ( B [ i ] ) ) * B [ i ] ) ; K = nearestMultiple - ( A [ i ] + carry ) ; totalOperations += K ; carry += K ; } return totalOperations ; } let A = [ 3 , 4 , 5 , 2 , 5 , 5 , 9 ] ; let B = [ 1 , 1 , 9 , 6 , 3 , 8 , 7 ] ; let N = A . length ; document . write ( MinimumMoves ( A , B , N ) + " " ) ;

Index/key variables: i
Accumulator variables: carry, i, totalOperations
Iterator variables: i
Javascript program:
function minimumDeviation ( A , N ) { var s = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) s . add ( A [ i ] ) ; else s . add ( 2 * A [ i ] ) ; } var tmp = [ ... s ] . sort ( ( a , b ) => a - b ) ; var diff = tmp [ tmp . length - 1 ] - tmp [ 0 ] ; while ( s . size && tmp [ tmp . length - 1 ] % 2 == 0 ) { var maxEl = tmp [ tmp . length - 1 ] ; s . delete ( maxEl ) ; s . add ( parseInt ( maxEl / 2 ) ) ; tmp = [ ... s ] . sort ( ( a , b ) => a - b ) ; diff = Math . min ( diff , tmp [ tmp . length - 1 ] - tmp [ 0 ] ) ; } document . write ( diff ) ; } var A = [ 4 , 1 , 5 , 20 , 3 ] ; var N = A . length ; minimumDeviation ( A , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaxNum ( num ) { var binaryNumber = Number ( num ) . toString ( 2 ) ; ; var maxBinaryNumber = " " ; var count0 = 0 , count1 = 0 ; var N = binaryNumber . length ; for ( i = 0 ; i < N ; i ++ ) { if ( binaryNumber . charAt ( i ) == ' ' ) { count1 ++ ; } else { count0 ++ ; } } for ( i = 0 ; i < count1 ; i ++ ) { maxBinaryNumber += ' ' ; } for ( i = 0 ; i < count0 ; i ++ ) { maxBinaryNumber += ' ' ; } return parseInt ( maxBinaryNumber , 2 ) ; } var N = 11 ; document . write ( findMaxNum ( N ) ) ;

Accumulator variables: count0, count1, i, maxBinaryNumber
Iterator variables: i
Javascript program:
function minOperations ( N ) { var even = 0 ; var odd = 0 ; for ( var it = 0 ; it < N . length ; it ++ ) { if ( ( N [ it ] - ' ' ) % 2 == 0 ) { even ++ ; } else { odd ++ ; } } if ( odd == 0 odd == 1 ) { document . write ( " " + " " ) ; } else { var ans = 0 ; for ( var it = 0 ; it < N . length ; it ++ ) { if ( ( N [ it ] - ' ' ) % 2 == 0 ) { ans ++ ; } else { ans = 0 ; } } if ( odd % 2 ) { ans ++ ; } document . write ( ans ) ; } } var N = " " ; minOperations ( N ) ;

Index/key variables: it
Accumulator variables: ans, even, it, odd
Iterator variables: it
Javascript program:
function FindwinnerOfGame ( S ) { let cntZero = 0 ; let cntConOne = 0 ; let nimSum = 0 ; let N = S . length ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { cntConOne += 1 ; } else { nimSum ^= cntConOne ; cntConOne = 0 ; cntZero ++ ; } } nimSum ^= cntConOne ; if ( cntZero % 2 == 0 ) { document . write ( " " ) ; } else if ( nimSum != 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let S = " " ; FindwinnerOfGame ( S ) ;

Index/key variables: i
Accumulator variables: cntConOne, cntZero, i, nimSum
Iterator variables: i
Javascript program:
function generatepermutation ( N ) { var answer = [ ] ; answer . push ( N ) ; console . log ( answer ) ; for ( var i = 1 ; i < N ; i ++ ) { console . log ( answer ) ; answer . push ( i ) ; } for ( var i in answer ) document . write ( answer [ i ] + " " ) ; } var N = 4 ; generatepermutation ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( arr , N ) { let ans = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { let t = i ; if ( t + arr [ i ] < N ) { arr [ i ] += arr [ t + arr [ i ] ] ; } } for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + ' ' ) ; } } let arr = [ 1 , 2 , 7 , 1 , 8 ] ; let N = arr . length ; maxSum ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOpsToTurnArrToZero ( arr , N ) { var st = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( st . has ( arr [ i ] ) arr [ i ] == 0 ) { continue ; } else { st . add ( arr [ i ] ) ; } } document . write ( st . size ) } var arr = [ 3 , 7 , 3 ] ; var N = arr . length ; minOpsToTurnArrToZero ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function splitArray ( arr , N ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . set ( arr [ i ] , 1 ) ; } } var G = 0 ; mp . forEach ( ( value , key ) => { G = gcd ( G , value ) ; } ) ; if ( G > 1 ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 1 , 2 , 3 , 4 , 4 , 3 , 2 , 1 ] ; var n = arr . length ; splitArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CheckAllEqual ( arr , N ) { for ( i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return false ; } } return true ; } function minCntOperations ( arr , N ) { var Max = Math . max . apply ( Math , arr ) ; var isPower2 ; if ( parseInt ( ( Math . ceil ( ( Math . log ( N ) / Math . log ( N ) ) ) ) ) == parseInt ( ( Math . floor ( ( ( Math . log ( N ) / Math . log ( 2 ) ) ) ) ) ) ) { isPower2 = true ; } else { isPower2 = false ; } if ( isPower2 && CheckAllEqual ( arr , N ) ) { return parseInt ( ( Math . log ( Max ) / Math . log ( 2 ) ) ) ; } else { return parseInt ( Math . ceil ( Math . log ( Max ) / Math . log ( 2 ) ) ) + 1 ; } } var arr = [ 2 , 4 ] ; var N = arr . length ; document . write ( minCntOperations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: isPower2
Javascript program:
function greatestReducedNumber ( num , s ) { let vis_s = [ false , false , false , false , false , false , false , false , false , false ] ; for ( let i = 0 ; i < s . length ; i ++ ) { vis_s [ Number ( s [ i ] ) - 48 ] = true ; } let n = num . length ; let inn = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( vis_s [ Number ( num [ i ] ) - ' ' ] ) { inn = i ; break ; } } if ( inn == - 1 ) { return num ; } for ( let dig = String ( num [ inn ] ) ; dig >= ' ' ; dig -- ) { if ( vis_s [ Number ( dig ) - ' ' ] == 0 ) { num [ inn ] = dig ; break ; } } let LargestDig = ' ' ; for ( let dig = ' ' ; dig >= ' ' ; dig -- ) { if ( vis_s [ dig - ' ' ] == false ) { LargestDig = dig ; break ; } } for ( let i = inn + 1 ; i < n ; i ++ ) { num [ i ] = LargestDig ; } let Count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( num [ i ] == ' ' ) Count ++ ; else break ; } num = Number ( num ) . toString ( ) ; if ( num . length == 0 ) return " " ; return num ; } let N = " " ; let S = " " ; document . write ( greatestReducedNumber ( N , S ) ) ;

Index/key variables: i, inn
Accumulator variables: Count, dig, i
Iterator variables: dig, i
Javascript program:
function minXOR ( Arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { if ( Arr [ i ] == 2 ) { document . write ( ( Arr [ i ] ^ 3 ) + " " ) ; } else { document . write ( ( Arr [ i ] ^ 2 ) + " " ) ; } } } let Arr = [ 5 , 4 , 7 , 6 ] ; let N = Arr . length ; minXOR ( Arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findArray ( n ) { let Arr = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; Arr [ 0 ] = 0 ; Arr [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { Arr [ i ] = Arr [ i / 2 ] ; } else { Arr [ i ] = Arr [ ( i - 1 ) / 2 ] + Arr [ ( i - 1 ) / 2 + 1 ] ; } } return Arr ; } function maxElement ( n ) { if ( n == 0 ) return 0 ; if ( n == 1 ) return 1 ; let Arr = findArray ( n ) ; let ans = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , Arr [ i ] ) ; } return ans ; } let N = 7 ; document . write ( maxElement ( N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this [ 0 ] = first ; this [ 1 ] = second ; } } function constGraphWithCon ( N , K ) { var Max = ( ( N - 1 ) * ( N - 2 ) ) / 2 ; if ( K > Max ) { document . write ( - 1 + " " ) ; return ; } var ans = [ ] ; for ( var i = 1 ; i < N ; i ++ ) { for ( var j = i + 1 ; j <= N ; j ++ ) { ans . push ( [ i , j ] ) ; } } for ( var i = 0 ; i < ( N - 1 ) + Max - K ; i ++ ) { document . write ( ans [ i ] [ 0 ] + " " + ans [ i ] [ 1 ] + " " ) ; } } var N = 5 , K = 3 ; constGraphWithCon ( N , K ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: pair
Javascript program:
function min_elements ( arr , N , K ) { let mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) } else { mp . set ( arr [ i ] , 1 ) } } let Freq = [ ] ; for ( let it of mp ) { let i = it [ 0 ] ; Freq . push ( mp . get ( i ) ) ; } Freq . sort ( ( a , b ) => b - a ) ; let len = Freq . length ; if ( len <= K ) { return 0 ; } let cntMin = 0 ; for ( let i = K ; i < len ; i ++ ) { cntMin += Freq [ i ] ; } return cntMin ; } let arr = [ 5 , 1 , 3 , 2 , 4 , 1 , 1 , 2 , 3 , 4 ] ; let N = arr . length ; let K = 3 ; document . write ( min_elements ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: cntMin, i
Iterator variables: i, it
Javascript program:
function sumzero ( arr , N , K ) { var sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 0 ) document . write ( " " ) ; else if ( sum > 0 ) { if ( sum % K == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } else document . write ( " " ) ; return 0 ; } var K , N ; var arr1 = [ 1 , - 6 , 2 , 2 ] ; K = 1 ; N = arr1 . length ; sumzero ( arr1 , N , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function cntOnesArrWithGivenOp ( arr , N ) { let cntOnes = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = i - 1 ; j < N ; j += i ) { arr [ j ] = arr [ j ] == 0 ? 1 : 0 ; } } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { cntOnes += 1 ; } } return cntOnes ; } let arr = [ 0 , 0 , 0 , 0 , 0 ] ; let N = arr . length ; document . write ( cntOnesArrWithGivenOp ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: cntOnes, i, j
Iterator variables: i, j
Javascript program:
function cntKnightsAttackPawn ( knights , pawn , M ) { let cntKnights = 0 ; for ( let i = 0 ; i < M ; i ++ ) { let X = Math . abs ( knights [ i ] [ 0 ] - pawn [ 0 ] ) ; let Y = Math . abs ( knights [ i ] [ 1 ] - pawn [ 1 ] ) ; if ( ( X == 1 && Y == 2 ) || ( X == 2 && Y == 1 ) ) { cntKnights ++ ; } } return cntKnights ; } let knights = [ [ 0 , 4 ] , [ 4 , 5 ] , [ 1 , 4 ] , [ 3 , 1 ] ] ; let pawn = [ 2 , 3 ] ; let M = knights . length ; document . write ( cntKnightsAttackPawn ( knights , pawn , M ) ) ;

Index/key variables: i
Accumulator variables: cntKnights, i
Iterator variables: i
Javascript program:
function minimumSwaps ( arr1 , arr2 , n ) { let sumArr1 = 0 , sumArr2 = 0 ; for ( let i = 0 ; i < n ; ++ i ) { sumArr1 += arr1 [ i ] ; sumArr2 += arr2 [ i ] ; } if ( sumArr1 % 2 == 0 && sumArr2 % 2 == 0 ) { document . write ( 0 ) ; return ; } if ( sumArr1 % 2 != 0 && sumArr2 % 2 != 0 ) { let flag = - 1 ; for ( let i = 0 ; i < n ; ++ i ) { if ( ( arr1 [ i ] + arr2 [ i ] ) % 2 == 1 ) { flag = 1 ; break ; } } document . write ( flag ) ; return ; } document . write ( - 1 ) ; } let arr1 = [ 11 , 14 , 20 , 2 ] ; let arr2 = [ 5 , 9 , 6 , 3 ] ; let N = arr1 . length ; minimumSwaps ( arr1 , arr2 , N ) ;

Index/key variables: i
Accumulator variables: sumArr1, sumArr2
Iterator variables: i
Javascript program:
function corpFlightBookings ( Bookings , N ) { let res = new Array ( N ) . fill ( 0 ) ; for ( let i = 0 ; i < Bookings . length ; i ++ ) { let l = Bookings [ i ] [ 0 ] ; let r = Bookings [ i ] [ 1 ] ; let K = Bookings [ i ] [ 2 ] ; res [ l - 1 ] = res [ l - 1 ] + K ; if ( r <= res . length - 1 ) res [ r ] = ( - K ) + res [ r ] ; } for ( let i = 1 ; i < res . length ; i ++ ) res [ i ] = res [ i ] + res [ i - 1 ] ; for ( let i = 0 ; i < res . length ; i ++ ) { document . write ( res [ i ] + " " ) ; } } let bookings = [ [ 1 , 3 , 100 ] , [ 2 , 6 , 100 ] , [ 3 , 4 , 100 ] ] ; let N = 6 ; corpFlightBookings ( bookings , N ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSmallestNumber ( n ) { for ( i = n ; i <= ( n + 2520 ) ; ++ i ) { var possible = 1 ; var temp = i ; while ( temp != 0 ) { if ( temp % 10 != 0 ) { var digit = temp % 10 ; if ( i % digit != 0 ) { possible = 0 ; break ; } } temp = parseInt ( temp / 10 ) ; } if ( possible == 1 ) { document . write ( i ) ; return ; } } } var N = 31 ; findSmallestNumber ( N ) ;

Iterator variables: i
Javascript program:
function findSmallestNumberPossible ( N , K ) { if ( N > 45 * K ) { document . write ( " " ) ; return ; } var res = " " ; var count = 0 ; for ( var i = 9 ; i >= 1 ; ) { if ( count === K ) { i -- ; count = 0 ; } if ( N > i ) { N -= i ; res += String . fromCharCode ( " " . charCodeAt ( 0 ) + i ) ; } else { res += String . fromCharCode ( " " . charCodeAt ( 0 ) + N ) ; N = 0 ; break ; } count ++ ; } var ans = " " ; for ( var i = res . length - 1 ; i >= 0 ; i -- ) { ans += res [ i ] + " " ; } document . write ( ans ) ; } var N = 25 , K = 3 ; findSmallestNumberPossible ( N , K ) ;

Index/key variables: i
Accumulator variables: N, ans, count, i, res
Iterator variables: i
Javascript program:
function minValue ( arr , n ) { var minimum = Math . min . apply ( Math , arr ) ; var sum = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + ( arr [ i ] - minimum ) ; } return sum ; } var arr = [ 1 , 2 , 3 ] ; var N = arr . length ; document . write ( minValue ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function result ( n ) { if ( n > 45 ) { document . write ( - 1 ) ; } var res = " " ; var digit = 9 ; while ( n > digit ) { res = String . fromCharCode ( 48 + digit ) + res ; n -= digit ; digit -= 1 ; } if ( n > 0 ) { res = String . fromCharCode ( 48 + n ) + res ; } document . write ( res ) ; } var N = 19 ; result ( N ) ;

Accumulator variables: digit, n
Javascript program:
function findArray ( N , K ) { if ( N == 1 ) { document . write ( K + " " ) ; return ; } if ( N == 2 ) { document . write ( 0 + " " + K ) ; return ; } let P = N - 2 ; let Q = N - 1 ; let VAL = 0 ; for ( let i = 1 ; i <= ( N - 3 ) ; i ++ ) { document . write ( i + " " ) ; VAL ^= i ; } if ( VAL == K ) { document . write ( P + " " + Q + " " + ( P ^ Q ) ) ; } else { document . write ( 0 + " " + P + " " + ( P ^ K ^ VAL ) ) ; } } let N = 4 , X = 6 ; findArray ( N , X ) ;

Accumulator variables: VAL, i
Iterator variables: i
Javascript program:
function findNumber ( N ) { let count = 0 ; while ( ( N & 1 ) == 1 ) { N = N >> 1 ; count ++ ; } return N << count ; } let N = 39 ; document . write ( findNumber ( N ) ) ;

Accumulator variables: count
Javascript program:
function subString ( s , n ) { var v = [ ] ; var i , len ; for ( i = 0 ; i < n ; i ++ ) { for ( len = 1 ; len <= n - i ; len ++ ) { var find = s . substr ( i , len ) ; v . push ( find ) ; } } return v ; } function IsPresent ( str , target ) { if ( str . includes ( target ) ) { return 1 ; } return - 1 ; } function countSubstrings ( S , T ) { var v = subString ( S , S . length ) ; var ans = 0 ; var i ; for ( i = 0 ; i < v . length ; i ++ ) { if ( IsPresent ( v [ i ] , T ) != - 1 ) { ans ++ ; } } document . write ( ans ) ; } var S = " " ; var T = " " ; countSubstrings ( S , T ) ;

Index/key variables: i
Accumulator variables: ans, i, len
Iterator variables: i, len
Javascript program:
function minOperation ( X , Y , n ) { let C = 0 ; let count = 0 ; for ( let i = 1 ; i < n ; i = i + 2 ) { if ( X [ i ] != Y [ i ] ) { count ++ ; } else { if ( count != 0 ) C ++ ; count = 0 ; } } if ( count != 0 ) C ++ ; count = 0 ; for ( let i = 0 ; i < n ; i = i + 2 ) { if ( X [ i ] != Y [ i ] ) { count ++ ; } else { if ( count != 0 ) C ++ ; count = 0 ; } } if ( count != 0 ) C ++ ; document . write ( C ) ; } let X = [ 1 , 0 , 0 , 0 , 0 , 1 ] ; let Y = [ 1 , 1 , 0 , 1 , 1 , 1 ] ; let N = X . length ; minOperation ( X , Y , N ) ;

Index/key variables: i
Accumulator variables: C, count
Iterator variables: i
Javascript program:
function minimumcntOperationReq ( arr , N ) { let cntOp = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { cntOp ++ ; } } return ( cntOp + 1 ) / 2 ; } let arr = [ 1 , 1 , 1 , 0 , 1 , 0 , 0 , 0 ] ; let N = arr . length ; document . write ( Math . floor ( minimumcntOperationReq ( arr , N ) ) ) ;

Index/key variables: i
Accumulator variables: cntOp, i
Iterator variables: i
Javascript program:
function isSequenceValid ( B , N ) { for ( let i = 0 ; i < N ; i ++ ) { if ( ( i + 1 ) % B [ i ] != 0 ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let N = 4 ; let arr = [ 1 , 2 , 3 , 2 ] ; isSequenceValid ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function ConstArrayAdjacentCoprime ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { document . write ( i + " " ) ; } } let N = 6 ; ConstArrayAdjacentCoprime ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumCost ( a , b ) { var fre1 = Array ( 256 ) . fill ( 0 ) , fre2 = Array ( 256 ) . fill ( 0 ) ; a . split ( ' ' ) . forEach ( c => { fre1 [ c . charCodeAt ( 0 ) ] ++ ; } ) ; b . split ( ' ' ) . forEach ( c => { fre2 [ c . charCodeAt ( 0 ) ] ++ ; } ) ; var mincost = 0 ; for ( var i = 0 ; i < 256 ; i ++ ) { mincost += Math . abs ( fre1 [ i ] - fre2 [ i ] ) ; } document . write ( mincost ) ; } var A = " " , B = " " ; minimumCost ( A , B ) ;

Index/key variables: i
Accumulator variables: i, mincost
Iterator variables: i
Javascript program:
function minCost ( arr ) { let odd = 0 , even = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } document . write ( Math . min ( even , odd ) ) ; } let arr = [ 1 , 2 , 3 ] ; minCost ( arr ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i