dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countPairs ( a , n ) { let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let y = a [ i ] ; if ( y != 0 && y != 1 ) { let x = ( ( y * 1.0 ) / ( 1 - y ) ) * y ; if ( mp . has ( x ) ) count += mp . get ( x ) ; } if ( mp . has ( y ) ) { mp . set ( y , mp . get ( y ) + 1 ) ; } else { mp . set ( y , 1 ) ; } } return count ; } let arr = [ - 4 , - 3 , 0 , 2 , 1 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function contains ( num , K , base ) { var isThere = 0 ; while ( num ) { var remainder = num % base ; if ( remainder == K ) { isThere = 1 ; } num /= base ; } return isThere ; } function count ( n , k , v ) { var pref = Array ( 100005 ) . fill ( 0 ) ; for ( var i = 1 ; i < 100005 ; i ++ ) { var present = contains ( i , k , 10 ) || contains ( i , k , 8 ) ; pref [ i ] += pref [ i - 1 ] + present ; } for ( var i = 0 ; i < n ; ++ i ) { document . write ( v [ i ] [ 1 ] - v [ i ] [ 0 ] + 1 - ( pref [ v [ i ] [ 1 ] ] - pref [ v [ i ] [ 0 ] - 1 ] ) + ' ' ) ; } } var K = 7 ; var Q = [ [ 2 , 5 ] , [ 1 , 15 ] ] ; var N = Q . length ; count ( N , K , Q ) ;

Index/key variables: i
Accumulator variables: i, num
Iterator variables: i
Javascript program:
function canMakeEqual ( arr1 , arr2 , N ) { var count = 0 ; var arr1_one = 0 , arr1_zero = 0 ; var arr2_one = 0 , arr2_zero = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr1 [ i ] == 1 ) { arr1_one ++ ; } else if ( arr1 [ i ] == 0 ) { arr1_zero ++ ; } if ( arr2 [ i ] == 1 ) { arr2_one ++ ; } else if ( arr2 [ i ] == 0 ) { arr2_zero ++ ; } } if ( arr1_one != arr2_one arr1_zero != arr2_zero ) { document . write ( " " ) ; return ; } for ( var i = 0 ; i < N ; i ++ ) { count = count + ( arr1 [ i ] - arr2 [ i ] ) ; if ( count < 0 ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var arr1 = [ 0 , 1 , 1 , 0 ] ; var arr2 = [ 0 , 0 , 1 , 1 ] ; var N = arr1 . length ; canMakeEqual ( arr1 , arr2 , N ) ;

Index/key variables: i
Accumulator variables: arr1_one, arr1_zero, arr2_one, arr2_zero, i
Iterator variables: i
Javascript program:
function checksubarrayExist1_N ( arr , N ) { let pos = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { pos . set ( arr [ i ] , i ) ; } let st = new Set ( ) ; for ( let i = 1 ; i <= N ; i ++ ) { st . add ( pos . get ( i ) ) ; let Min = Math . min ( ... st ) ; let Max = Math . max ( ... st ) ; if ( Max - Min + 1 == i ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } let arr = [ 1 , 4 , 3 , 2 ] ; let N = arr . length ; checksubarrayExist1_N ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkSamePosition ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { var temp = ( ( i + arr [ i ] ) % n + n ) % n ; if ( mp . has ( temp ) ) { document . write ( " " ) ; return ; } if ( mp . has ( temp ) ) { mp . set ( temp , mp . get ( temp ) + 1 ) } else mp . set ( temp , 1 ) } document . write ( " " ) ; } var arr = [ 5 , 4 , 3 ] ; var N = arr . length ; checkSamePosition ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( 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 ans = 0 ; while ( mp . has ( k ) == false || mp . get ( k ) < n ) { for ( let i = 1 ; i <= k - 1 ; i ++ ) { if ( mp . has ( i ) && mp . get ( i ) > 0 ) { mp . set ( i , mp . get ( i ) - 1 ) ; if ( mp . has ( i + 1 ) ) mp . set ( i + 1 , mp . get ( i + 1 ) + 1 ) ; else mp . set ( i + 1 , 1 ) ; if ( mp . has ( i + 1 ) && mp . get ( i + 1 ) == 1 ) { i ++ ; } } } ans ++ ; } document . write ( ans ) ; } let arr = [ 2 , 3 , 3 , 4 ] ; let K = 5 ; let N = arr . length ; minOperations ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function maxProduct ( arr , N ) { var max_product = Number . MIN_VALUE ; var prefix_sum = 0 ; var sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } for ( i = 0 ; i < N - 1 ; i ++ ) { prefix_sum += arr [ i ] ; var X = prefix_sum ; var Y = sum - prefix_sum ; max_product = Math . max ( max_product , X * Y ) ; } document . write ( max_product ) ; } var arr = [ 2 , 3 , 5 , 6 , 7 ] ; var N = arr . length ; maxProduct ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, prefix_sum, sum
Iterator variables: i
Javascript program:
function findMask ( K ) { let mask = 1 ; while ( ( K & mask ) == 0 ) { mask = mask << 1 ; } return mask ; } function sameRightSetBitPos ( arr , N , K ) { let mask = findMask ( K ) ; let pos = ( K & mask ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & mask ) == pos ) document . write ( arr [ i ] + " " ) ; } } let arr = [ 3 , 4 , 6 , 7 , 9 , 12 , 15 ] ; let N = arr . length ; let K = 7 ; sameRightSetBitPos ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 100001 function maxSum ( arr , N , K ) { if ( N < K ) { document . write ( " " ) ; return - 1 ; } let CountDistinct = new Array ( MAX + 1 ) ; let prime = new Array ( MAX + 1 ) ; for ( let i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; prime [ i ] = true ; } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) { CountDistinct [ i ] = 1 ; for ( let j = i * 2 ; j <= MAX ; j += i ) { CountDistinct [ j ] ++ ; prime [ j ] = false ; } } } let Maxarr_sum = 0 , DistPrimeSum = 0 ; for ( let i = 0 ; i < K ; i ++ ) { Maxarr_sum += arr [ i ] ; DistPrimeSum += CountDistinct [ arr [ i ] ] ; } let curr_sum = DistPrimeSum ; let curr_arrSum = Maxarr_sum ; for ( let i = K ; i < N ; i ++ ) { curr_sum += CountDistinct [ arr [ i ] ] - CountDistinct [ arr [ i - K ] ] ; curr_arrSum += arr [ i ] - arr [ i - K ] ; if ( curr_sum > DistPrimeSum ) { DistPrimeSum = curr_sum ; Maxarr_sum = curr_arrSum ; } else if ( curr_sum == DistPrimeSum ) { Maxarr_sum = Math . max ( curr_arrSum , Maxarr_sum ) ; } } document . write ( Maxarr_sum ) ; } let arr = [ 1 , 4 , 2 , 10 , 3 ] ; let K = 3 ; let N = arr . length maxSum ( arr , N , K ) ;

Index/key variables: i, j
Accumulator variables: DistPrimeSum, Maxarr_sum, curr_arrSum, curr_sum, i, j
Iterator variables: i, j
Javascript program:
function checkPronic ( x ) { for ( let i = 0 ; i <= parseInt ( Math . sqrt ( x ) ) ; i ++ ) { if ( x == i * ( i + 1 ) ) { return true ; } } return false ; } function countPronic ( A , B ) { let count = 0 ; for ( let i = A ; i <= B ; i ++ ) { if ( checkPronic ( i ) ) { count ++ ; } } document . write ( count ) ; } let A = 3 , B = 20 ; countPronic ( A , B ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function oddDivisors ( arr , N ) { for ( i = 0 ; i < N ; i ++ ) { var powerOfTwo = 2 ; var count = 0 ; while ( powerOfTwo <= arr [ i ] ) { count ++ ; powerOfTwo = 2 * powerOfTwo ; } document . write ( count + " " ) ; } return ; } var arr = [ 15 , 16 , 20 , 35 ] ; var N = arr . length ; oddDivisors ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function checkPossible ( arr , n ) { for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { document . write ( " " ) ; return ; } else { arr [ i ] -= arr [ i - 1 ] ; arr [ i - 1 ] = 0 ; } } if ( arr [ n - 1 ] == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var arr = [ 2 , 3 , 3 , 4 , 2 ] ; var N = arr . length ; checkPossible ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function highestPowerOfTwo ( num ) { var s = num . toString ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] === " " ) { document . write ( " " ) ; continue ; } var lg = parseInt ( Math . log2 ( s [ i ] . charCodeAt ( 0 ) - 48 ) ) ; var p = Math . pow ( 2 , lg ) ; document . write ( String . fromCharCode ( p + 48 ) ) ; } } var num = 4317 ; highestPowerOfTwo ( num ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSumAfterKReverse ( arr , K , N ) { let sum = Number . MIN_VALUE ; if ( K % 2 != 0 ) arr . reverse ( ) ; let currsum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { currsum += arr [ i ] ; sum = Math . max ( sum , currsum ) ; } document . write ( sum ) ; } let arr = [ 1 , 5 , 8 , 9 , 11 , 2 ] ; let K = 1 ; let N = arr . length ; maxSumAfterKReverse ( arr , K , N ) ;

Index/key variables: i
Accumulator variables: currsum, i
Iterator variables: i
Javascript program:
function SubMasks ( N ) { for ( let S = N ; S > 0 ; S = ( S - 1 ) & N ) { document . write ( S + " " ) ; } } let N = 25 ; SubMasks ( N ) ;

Iterator variables: S
Javascript program:
MOD = 1000000007 ; function power ( x , y ) { var res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } function countPairs ( N ) { var high = power ( 2 , N ) ; var count = 0 ; for ( i = 0 ; i < high ; i ++ ) { for ( j = 0 ; j < high ; j ++ ) { var X = ( i ^ j ) ; var Y = ( i j ) ; if ( X == Y ) { count ++ ; } } } document . write ( count % MOD ) ; } var N = 10 ; countPairs ( N ) ;

Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function minimumMoves ( a , n ) { let min_element = Number . MAX_VALUE ; let max_element = Number . MIN_VALUE ; let min_ind = - 1 ; let max_ind = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= min_element ) { min_element = a [ i ] ; min_ind = i ; } if ( a [ i ] > max_element ) { max_element = a [ i ] ; max_ind = i ; } } if ( max_ind == min_ind ) { return 0 ; } else if ( max_ind > min_ind ) { return max_ind + ( n - min_ind - 2 ) ; } else { return max_ind + n - min_ind - 1 ; } } let arr = [ 35 , 46 , 17 , 23 ] ; let N = arr . length ; document . write ( minimumMoves ( arr , N ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findIndex ( arr , n , K ) { let sum = 0 ; let res = - 1 ; let mini = parseInt ( 1e9 ) ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } for ( let i = 0 ; i < n ; i ++ ) { let temp = sum - arr [ i ] ; if ( temp % K == 0 ) { if ( res == - 1 mini > arr [ i ] ) { res = i + 1 ; mini = arr [ i ] ; } } } return res ; } let arr = [ 14 , 7 , 8 , 2 , 4 ] ; let K = 7 ; let N = arr . length ; document . write ( findIndex ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function divisionalArrays ( arr , N ) { var sum = 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 ) ; } } mp . forEach ( ( value , key ) => { if ( value > 1 ) { sum += value - 1 ; } } ) ; document . write ( sum ) ; } var arr = [ 1 , 1 , 3 ] ; var N = arr . length ; divisionalArrays ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function totalInversions ( arr , K , N ) { let inv = 0 ; let X = 0 ; let i , j ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { if ( arr [ i ] > arr [ j ] && i < j ) inv ++ ; if ( arr [ i ] > arr [ j ] ) X ++ ; } } let totalInv = X * K * ( K - 1 ) / 2 + inv * K ; document . write ( totalInv ) ; } let arr = [ 2 , 1 , 3 ] ; let K = 3 ; let N = arr . length ; totalInversions ( arr , K , N ) ;

Index/key variables: i, j
Accumulator variables: X, i, inv, j
Iterator variables: i, j
Javascript program:
function Fact ( N ) { let result = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { result = ( result * i ) ; } return result ; } function numberOfWays ( M , arr , N ) { let B = new Array ( M ) . fill ( 0 ) ; let counter = new Array ( M + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != 0 ) { if ( B [ i % M ] == 0 ) { B [ i % M ] = arr [ i ] ; counter [ arr [ i ] ] ++ ; if ( counter [ arr [ i ] ] > 1 ) { document . write ( 0 ) ; return ; } } else if ( B [ i % M ] != arr [ i ] ) { document . write ( 0 ) ; return ; } } } let cnt = 0 ; for ( let i = 0 ; i < M ; i ++ ) { if ( B [ i ] == 0 ) { cnt ++ ; } } document . write ( Fact ( cnt ) ) ; } let M = 4 ; let arr = [ 1 , 0 , 3 , 0 , 0 ] ; let N = arr . length ; numberOfWays ( M , arr , N ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function MaximumSum ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let x = 0 , y = i , sum = 0 ; for ( let j = i ; j < n ; j ++ ) { sum += arr [ x ++ ] [ y ++ ] ; } if ( sum > ans ) ans = sum ; } for ( let i = 1 ; i < n ; i ++ ) { let x = i , y = 0 , sum = 0 ; for ( let j = i ; j < n ; j ++ ) { sum += arr [ x ++ ] [ y ++ ] ; } if ( sum > ans ) ans = sum ; } return ans ; } let arr = [ [ 1 , 2 , 3 ] , [ 3 , 5 , 10 ] , [ 1 , 3 , 5 ] ] ; let n = arr . length ; document . write ( MaximumSum ( arr , n ) ) ;

Accumulator variables: i, j, sum, x, y
Iterator variables: i, j
Javascript program:
function numberOfIntegers ( arr , N ) { let cur_max = 0 , count = 0 ; if ( N == 1 ) { count = 1 ; } else { for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] > cur_max ) { cur_max = arr [ i ] ; if ( arr [ i ] > arr [ i + 1 ] ) { count ++ ; } } } if ( arr [ N - 1 ] > cur_max ) count ++ ; } document . write ( count ) ; } let arr = [ 1 , 2 , 0 , 7 , 2 , 0 , 2 , 0 ] ; let N = arr . length ; numberOfIntegers ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function possibleTriplets ( arr , N ) { var freq = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { freq ++ ; } } return ( freq * 1 * ( freq - 1 ) * ( freq - 2 ) ) / 6 ; } var arr = [ 2 , 5 , - 9 , - 3 , 6 ] ; var N = arr . length ; document . write ( possibleTriplets ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: freq, i
Iterator variables: i
Javascript program:
function maxPossibleDiff ( arr , N ) { arr . push ( - 1 ) ; arr . reverse ( ) ; arr . push ( - 1 ) ; arr . reverse ( ) ; var maxDiff = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] && arr [ i ] > arr [ i + 1 ] ) { maxDiff += arr [ i ] ; } if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) { maxDiff -= arr [ i ] ; } } document . write ( maxDiff ) ; } var arr = [ 3 , 2 , 1 , 4 , 5 , 2 , 1 , 7 , 8 , 9 ] ; var N = arr . length ; maxPossibleDiff ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, maxDiff
Iterator variables: i
Javascript program:
function printArray ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function reverseCircularArray ( arr , N , K ) { let start = K , end = K - 1 ; let count = Math . floor ( N / 2 ) ; while ( count -- ) { let temp = arr [ start % N ] ; arr [ start % N ] = arr [ end % N ] ; arr [ end % N ] = temp ; start ++ ; end -- ; if ( end === - 1 ) { end = N - 1 ; } } printArray ( arr , N ) ; } let arr = [ 3 , 5 , 2 , 4 , 1 ] ; let K = 2 ; let N = arr . length ; reverseCircularArray ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: count, end, i, start
Iterator variables: i
Javascript program:
function findOriginalMatrix ( B , N , M ) { var A = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) A [ i ] = Array ( M ) . fill ( 0 ) ; for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { A [ i ] [ j ] = 1 ; } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { if ( B [ i ] [ j ] == 0 ) { for ( k = 0 ; k < M ; ++ k ) { A [ i ] [ k ] = 0 ; } for ( k = 0 ; k < N ; ++ k ) { A [ k ] [ j ] = 0 ; } } } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { var c = 0 ; for ( k = 0 ; k < M ; ++ k ) { if ( c == 1 ) break ; c += A [ i ] [ k ] ; } for ( k = 0 ; k < N ; ++ k ) { if ( c == 1 ) break ; c += A [ k ] [ j ] ; } if ( c != B [ i ] [ j ] ) { document . write ( " " ) ; return ; } } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { document . write ( A [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } var B = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ; var N = B . length ; var M = B [ 0 ] . length ; findOriginalMatrix ( B , N , M ) ;

Index/key variables: i, j, k
Accumulator variables: c, i
Iterator variables: i, j, k
Javascript program:
const mod = 1000000007 ; function power ( a , n , d ) { var res = 1 ; while ( n != 0 ) { if ( ( n % 2 ) != 0 ) { res = ( ( res % d ) * ( a % d ) ) % d ; } a = ( ( a % d ) * ( a % d ) ) % d ; n /= 2 ; } return res ; } function gcd ( p , q , n ) { if ( p == q ) { return ( power ( p , n , mod ) + power ( q , n , mod ) ) % mod ; } var candidate = 1 ; var num = p - q ; var sq = parseInt ( Math . sqrt ( num ) ) ; for ( i = 1 ; i <= sq ; ++ i ) { if ( num % i == 0 ) { var X = power ( p , n , i ) ; var Y = power ( q , n , i ) ; var temp = ( X + Y ) % i ; if ( temp == 0 ) { candidate = Math . max ( candidate , i ) ; } temp = ( power ( p , n , num / i ) + power ( q , n , num / i ) ) % ( num / i ) ; if ( temp == 0 ) { candidate = Math . max ( candidate , num / i ) ; } } } return candidate % mod ; } var p , q , n ; p = 10 ; q = 6 ; n = 5 ; document . write ( gcd ( p , q , n ) ) ;

Accumulator variables: n
Iterator variables: i
Javascript program:
function findPolet ( n , h ) { for ( let i = 1 ; i < n ; i ++ ) document . write ( Math . sqrt ( i / ( n * 1.0 ) ) * h + " " ) ; } let n = 3 ; let h = 2 ; findPolet ( n , h ) ; ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function calculateK ( x , y ) { var g = gcd ( x , y ) ; var n = y / g ; var res = n ; for ( i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { res -= ( res / i ) ; while ( n % i == 0 ) n /= i ; } } if ( n != 1 ) res -= ( res / n ) ; return res ; } var x = 3 , y = 15 ; document . write ( calculateK ( x , y ) + " " ) ;

Accumulator variables: i, n, res
Iterator variables: i
Javascript program:
function nearestPowerOfTwo ( arr , N ) { for ( i = 0 ; i < N ; i ++ ) { var lg = parseInt ( ( Math . log ( arr [ i ] ) / Math . log ( 2 ) ) ) ; var a = parseInt ( ( Math . pow ( 2 , lg ) ) ) ; var b = parseInt ( ( Math . pow ( 2 , lg + 1 ) ) ) ; if ( ( arr [ i ] - a ) < ( b - arr [ i ] ) ) document . write ( a + " " ) ; else document . write ( b + " " ) ; } } var arr = [ 5 , 2 , 7 , 12 ] ; var N = arr . length ; nearestPowerOfTwo ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { var count = 0 ; while ( n != 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function invertBits ( n ) { var x = parseInt ( ( Math . log ( n ) / Math . log ( 2 ) ) ) ; var m = 1 << x ; m = m | m - 1 ; n = n ^ m ; return n ; } function invertSum ( A , B ) { var temp = countSetBits ( A ) + countSetBits ( B ) ; document . write ( invertBits ( temp ) ) ; } var A = 5 ; var B = 7 ; invertSum ( A , B ) ;

Accumulator variables: count, n
Javascript program:
function XOR_for_every_i ( A , N ) { let frequency_of_bits = new Uint8Array ( 32 ) ; for ( let i = 0 ; i < N ; i ++ ) { let bit_position = 0 ; let M = A [ i ] ; while ( M != 0 ) { if ( ( M & 1 ) != 0 ) { frequency_of_bits [ bit_position ] += 1 ; } bit_position += 1 ; M >>= 1 ; } } for ( let i = 0 ; i < N ; i ++ ) { let M = A [ i ] ; let value_at_that_bit = 1 ; let XOR_sum = 0 ; for ( let bit_position = 0 ; bit_position < 32 ; bit_position ++ ) { if ( ( M & 1 ) != 0 ) { XOR_sum += ( N - frequency_of_bits [ bit_position ] ) * value_at_that_bit ; } else { XOR_sum += ( frequency_of_bits [ bit_position ] ) * value_at_that_bit ; } M >>= 1 ; value_at_that_bit <<= 1 ; } document . write ( XOR_sum + " " ) ; } return ; } let A = [ 1 , 2 , 3 ] ; let N = A . length ; XOR_for_every_i ( A , N ) ;

Index/key variables: bit_position, i
Accumulator variables: XOR_sum, bit_position, i
Iterator variables: bit_position, i
Javascript program:
function minimumMaxDiff ( nums ) { var s = new Set ( ) ; for ( var i = 0 ; i < nums . length ; i ++ ) { if ( nums [ i ] % 2 == 0 ) s . add ( nums [ i ] ) ; else s . add ( nums [ i ] * 2 ) ; } var tmp = [ ... s ] . sort ( ( a , b ) => a - b ) var res = tmp [ tmp . length - 1 ] - tmp [ 0 ] ; while ( tmp [ tmp . length - 1 ] % 2 == 0 ) { var x = tmp [ tmp . length - 1 ] ; s . delete ( x ) ; s . add ( parseInt ( x / 2 ) ) ; tmp = [ ... s ] . sort ( ( a , b ) => a - b ) res = Math . min ( res , tmp [ tmp . length - 1 ] - tmp [ 0 ] ) ; } return res ; } var arr = [ 1 , 2 , 5 , 9 ] ; document . write ( minimumMaxDiff ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let M = 3 ; let N = 3 ; function countDigit ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { let X = arr [ i ] [ j ] ; let d = ( Math . floor ( Math . log10 ( X ) * 1.0 ) + 1 ) ; document . write ( d + " " ) ; } document . write ( " " ) ; } } let arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ] ; countDigit ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findSum ( arr , N ) { var mp = { } ; for ( let i = 0 ; i < N ; i ++ ) mp [ arr [ i ] ] = 0 ; for ( let i = 0 ; i < N ; i ++ ) { mp [ arr [ i ] ] ++ ; } var sum_odd = 0 , sum_even = 0 ; for ( let itr in mp ) { if ( mp [ itr ] % 2 != 0 ) { sum_odd += ( itr ) * ( mp [ itr ] ) ; } if ( mp [ itr ] % 2 == 0 ) { sum_even += ( itr ) * ( mp [ itr ] ) ; } } var diff = sum_even - sum_odd ; return diff ; } var arr = new Array ( 1 , 5 , 5 , 2 , 4 , 3 , 3 ) ; var N = arr . length ; console . log ( findSum ( arr , N ) ) ;

Index/key variables: i, itr
Accumulator variables: i, sum_even, sum_odd
Iterator variables: i, itr
Javascript program:
function noOfArraysPossible ( N , M ) { var ans = 1 ; for ( i = 0 ; i < N ; ++ i ) { ans = ans * ( M - i ) ; } document . write ( ans ) ; } var N = 2 , M = 3 ; noOfArraysPossible ( N , M ) ;

Iterator variables: i
Javascript program:
function printPermutation ( arr , n , k ) { let flag = false ; arr . sort ( ) ; do { let sum = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { sum += arr [ i ] & arr [ i + 1 ] ; } if ( sum >= k ) { flag = true ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } } while ( next_permutation ( arr ) ) ; if ( flag == false ) { System . out . print ( " " ) ; } } function next_permutation ( p ) { for ( let a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( let b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { let 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 ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let K = 8 ; let N = arr . length ; printPermutation ( arr , N , K ) ;

Index/key variables: a, b, i
Accumulator variables: i, sum
Iterator variables: a, b, i
Boolean variables: flag
Javascript program:
function findSum ( a , b , n ) { if ( n == 1 ) { document . write ( a ) ; return ; } let s = a + b ; for ( i = 0 ; i < n - 2 ; i ++ ) { let x = a ^ b ; s += x ; a = b ; b = x ; } document . write ( s ) ; } let a = 2 , b = 5 , N = 8 ; findSum ( a , b , N ) ;

Accumulator variables: i, s
Iterator variables: i
Javascript program:
function LongestLenXORK ( arr , N , K ) { var prefixXOR = 0 ; var maxLen = 0 ; var mp = new Map ( ) ; mp . set ( 0 , - 1 ) ; for ( var i = 0 ; i < N ; i ++ ) { prefixXOR ^= arr [ i ] ; if ( mp . has ( prefixXOR ^ K ) ) { maxLen = Math . max ( maxLen , ( i - mp . get ( prefixXOR ^ K ) ) ) ; } if ( ! mp . has ( prefixXOR ) ) { mp . set ( prefixXOR , i ) ; } } return maxLen ; } var arr = [ 1 , 2 , 4 , 7 , 2 ] ; var N = arr . length ; var K = 1 ; document . write ( LongestLenXORK ( arr , N , K ) ) ;

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