dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let factorial = [ 1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 ] ; function isStrong ( N ) { let num = N . toString ( ) ; let sum = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { sum += factorial [ num [ i ] - ' ' ] ; } return sum == N ; } function printStrongNumbers ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { if ( isStrong ( i ) ) { document . write ( i + " " ) ; } } } let N = 1000 ; printStrongNumbers ( N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countPairs ( A , B ) { var countY = 0 , countX = ( B - A ) + 1 , next_val = 9 ; while ( next_val <= B ) { if ( next_val >= A ) { countY += 1 ; } next_val = next_val * 10 + 9 ; } return ( countX * countY ) ; } var A = 1 ; var B = 16 ; document . write ( countPairs ( A , B ) ) ;

Accumulator variables: countY
Javascript program:
function solve ( N , M ) { var ans = ( N ) * parseInt ( ( M / 2 ) ) ; if ( M % 2 == 1 ) { ans += parseInt ( ( N + 1 ) / 2 ) ; } document . write ( ans ) ; } var N , M ; N = 5 ; M = 3 ; solve ( N , M ) ;

Accumulator variables: ans
Javascript program:
var max_len = 100005 ; var cnt = Array ( max_len ) . fill ( 0 ) ; function precompute ( s , K ) { var n = s . length ; for ( var i = 0 ; i < n - 1 ; i ++ ) { cnt [ i + 1 ] = cnt [ i ] + ( s . substring ( i , i + K . length ) == K ) ; } } var s = " " ; var K = " " ; precompute ( s , K ) ; var Q = [ [ 1 , 6 ] , [ 5 , 11 ] ] ; Q . forEach ( ( it ) => { document . write ( cnt [ it [ 1 ] - 1 ] - cnt [ it [ 0 ] - 1 ] + " " ) ; } ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getXOR ( BITree , index ) { let ans = 0 ; index += 1 ; while ( index > 0 ) { ans ^= BITree [ index ] ; index -= index & ( - index ) ; } return ans ; } function updateBIT ( BITree , n , index , val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] ^= val ; index += index & ( - index ) ; } } function constructBITree ( arr , n ) { let BITree = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) BITree [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) updateBIT ( BITree , n , i , arr [ i ] ) ; return BITree ; } function rangeXor ( BITree , l , r ) { return getXOR ( BITree , r ) ^ getXOR ( BITree , l - 1 ) ; } let A = [ 2 , 1 , 1 , 3 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let n = A . length ; let q = [ [ 1 , 0 , 9 ] , [ 2 , 3 , 6 ] , [ 2 , 5 , 5 ] , [ 2 , 8 , 1 ] , [ 1 , 0 , 9 ] ] ; let BITree = constructBITree ( A , n ) ; for ( let i = 0 ; i < q . length ; i ++ ) { let id = q [ i ] [ 0 ] ; if ( id == 1 ) { let L = q [ i ] [ 1 ] ; let R = q [ i ] [ 2 ] ; document . write ( " " + " " + rangeXor ( BITree , L , R ) + " " ) ; } else { let idx = q [ i ] [ 1 ] ; let val = q [ i ] [ 2 ] ; A [ idx ] ^= val ; updateBIT ( BITree , n , idx , val ) ; } }

Index/key variables: i, idx, index
Accumulator variables: ans, i, index
Iterator variables: i
Javascript program:
let arr = [ ] ; let dp = [ ] ; function count ( ) { let maxN = 1000000 , i , j ; for ( i = 0 ; i < maxN ; i ++ ) arr [ i ] = 1 ; arr [ 0 ] = 0 ; arr [ 1 ] = 0 ; for ( i = 2 ; i * i <= maxN ; i ++ ) { if ( arr [ i ] == 1 ) { for ( j = 2 * i ; j <= maxN ; j += i ) { arr [ j ] = 0 ; } } } let cnt = 0 ; for ( i = 0 ; i <= maxN ; i ++ ) { if ( arr [ i ] == 1 ) cnt ++ ; if ( arr [ cnt ] == 1 ) dp [ i ] = 1 ; else dp [ i ] = 0 ; } for ( i = 1 ; i <= maxN ; i ++ ) dp [ i ] += dp [ i - 1 ] ; } let L = 4 , R = 12 ; count ( ) ; document . write ( dp [ R ] - dp [ L - 1 ] ) ;

Index/key variables: R, cnt, i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function findUngroupedElement ( s , k ) { let n = s . length ; let b = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < 26 ; i ++ ) b [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let p = s [ i ] ; b [ p . charCodeAt ( ) - ' ' . charCodeAt ( ) ] += 1 ; } let sum = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( b [ i ] > k ) sum += b [ i ] - k ; } document . write ( sum ) ; } let s = " " ; let k = 1 ; findUngroupedElement ( s , k ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findSolution ( N ) { if ( N % 4 != 0 ) document . write ( - 1 + " " ) ; else { let temp = 0 , sum_odd = 0 , sum_even = 0 ; let result = new Uint8Array ( N ) ; for ( let i = 0 ; i < N ; i += 2 ) { temp += 2 ; result [ i + 1 ] = temp ; sum_even += result [ i + 1 ] ; result [ i ] = temp - 1 ; sum_odd += result [ i ] ; } let diff = sum_even - sum_odd ; result [ N - 2 ] += diff ; for ( let i = 0 ; i < N ; i ++ ) document . write ( result [ i ] + " " ) ; document . write ( " " ) ; } } let N = 8 ; findSolution ( N ) ;

Index/key variables: i
Accumulator variables: i, sum_even, sum_odd, temp
Iterator variables: i
Javascript program:
function mutually_coprime ( n ) { if ( n <= 3 ) { for ( let j = 1 ; j < n + 1 ; j ++ ) document . write ( j + " " + " " ) ; document . write ( " " ) ; } else { document . write ( " " + " " ) ; for ( let j = 4 ; j < n ; j += 2 ) { document . write ( j + " " + ( j + 1 ) + " " ) ; if ( n % 2 == 0 ) document . write ( n + " " ) ; } } } let n = 9 ; mutually_coprime ( n ) ;

Accumulator variables: j
Iterator variables: j
Javascript program:
function findMaxSum ( arr , n ) { var a = [ ] ; var b = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { a . push ( arr [ i ] ) ; } else if ( arr [ i ] < 0 ) { b . push ( arr [ i ] ) ; } } a . sort ( ( a , b ) => a - b ) b . sort ( ( a , b ) => a - b ) var p = a . length - 1 ; var q = b . length - 1 ; var s = 0 ; while ( p >= 0 && q >= 0 ) { if ( a [ p ] + b [ q ] > 0 ) { s = s + a [ p ] + b [ q ] ; } else { break ; } p = p - 1 ; q = q - 1 ; } return s ; } var arr1 = [ 1 , - 2 , 3 , 4 , - 5 , 8 ] ; var n1 = arr1 . length ; document . write ( findMaxSum ( arr1 , n1 ) ) ;

Index/key variables: i, p, q
Accumulator variables: i
Iterator variables: i
Javascript program:
function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } function PrimeDegreeNodes ( prufer , n ) { let nodes = n + 2 ; let prime = new Array ( nodes + 1 ) ; prime . fill ( true ) ; SieveOfEratosthenes ( prime , nodes + 1 ) ; let degree = new Array ( n + 2 + 1 ) ; for ( let i = 1 ; i <= nodes ; i ++ ) degree [ i ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) degree [ prufer [ i ] ] ++ ; for ( let i = 1 ; i <= nodes ; i ++ ) { if ( prime [ degree [ i ] ] ) { document . write ( i + " " ) ; } } } let a = [ 4 , 1 , 3 , 4 ] ; let n = a . length PrimeDegreeNodes ( a , n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function kthSmallest ( a , k ) { let res = 0 ; let j = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) { while ( j < 32 && ( a & ( 1 << j ) ) ) { j ++ ; } if ( k & ( 1 << i ) ) { res |= ( 1 << j ) ; } j ++ ; } return res ; } let a = 5 , k = 3 ; document . write ( kthSmallest ( a , k ) ) ;

Accumulator variables: i, j, res
Iterator variables: i
Javascript program:
let n = 10005 ; let Prime = new Array ( n + 1 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { let i , j ; Prime [ 0 ] = Prime [ 1 ] = false ; for ( i = 2 ; i * i <= 10005 ; i ++ ) { if ( Prime [ i ] ) { for ( j = 2 * i ; j < 10005 ; j += i ) { Prime [ j ] = false ; } } } } function primeDegreeNodes ( N , M , edges ) { let Adj = new Array ( ) ; for ( let i = 0 ; i < N + 1 ; i ++ ) { Adj . push ( new Array ( ) ) } for ( let i = 0 ; i < M ; i ++ ) { let x = edges [ i ] [ 0 ] ; let y = edges [ i ] [ 1 ] ; Adj [ x ] . push ( y ) ; Adj [ y ] . push ( x ) ; } SieveOfEratosthenes ( ) ; for ( let i = 1 ; i <= N ; i ++ ) { let x = Adj [ i ] . length ; if ( Prime [ x ] ) document . write ( i + ' ' ) ; } } let N = 4 , M = 6 ; let edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 3 , 4 ] ] ; primeDegreeNodes ( N , M , edges ) ;

Index/key variables: i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let mod = 1000000007 ; function countWays ( colored , count , n ) { if ( count == n ) { return 1 ; } let answer = 0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { if ( colored [ i ] == 0 ) { if ( colored [ i - 1 ] == 1 colored [ i + 1 ] == 1 ) { colored [ i ] = 1 ; answer = ( answer + countWays ( colored , count + 1 , n ) ) % mod ; colored [ i ] = 0 ; } } } return answer ; } function waysToColor ( arr , n , k ) { let colored = Array . from ( { length : n + 2 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < k ; i ++ ) { colored [ arr [ i ] ] = 1 ; } return countWays ( colored , k , n ) ; } let N = 6 ; let K = 3 ; let arr = [ 1 , 2 , 6 ] ; document . write ( waysToColor ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function ShortestPalindrome ( s ) { let n = s . length ; let ans = s [ 0 ] . charCodeAt ( ) ; for ( let i = 1 ; i < n ; i ++ ) { ans = Math . min ( ans , s [ i ] . charCodeAt ( ) ) ; } return String . fromCharCode ( ans ) ; } let s = " " ; document . write ( ShortestPalindrome ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSubsequence ( arr , n ) { let sign = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) sign [ i ] = 1 ; else sign [ i ] = - 1 ; } let k = 0 ; let result = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { let cur = arr [ i ] ; let j = i ; while ( j < n && sign [ i ] == sign [ j ] ) { cur = Math . max ( cur , arr [ j ] ) ; ++ j ; } result [ k ++ ] = cur ; i = j - 1 ; } for ( let i = 0 ; i < k ; i ++ ) document . write ( result [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ - 4 , 9 , 4 , 11 , - 5 , - 17 , 9 , - 3 , - 5 , 2 ] ; let n = arr . length ; findSubsequence ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function isPalindrome ( r ) { let p = r ; p = reverse ( p ) ; return ( r == ( p ) ) ; } function PrefixSuffixPalindrome ( str ) { let n = str . length , len = 0 ; for ( let i = 0 ; i < n / 2 ; i ++ ) { if ( str [ i ] != str [ n - i - 1 ] ) { len = i ; break ; } } let prefix = " " , suffix = " " ; let midPal = " " ; prefix = str . substring ( 0 , len ) ; suffix = str . substring ( n - len ) ; str = str . substring ( len , ( n - 2 * len ) + len ) ; for ( let i = 1 ; i <= str . length ; i ++ ) { let y = str . substring ( 0 , i ) ; if ( isPalindrome ( y ) ) { if ( midPal . length < y . length ) { midPal = y ; } } } for ( let i = 1 ; i <= str . length ; i ++ ) { let y = str . substring ( str . length - i ) ; if ( isPalindrome ( y ) ) { if ( midPal . length < y . length ) { midPal = y ; } } } let answer = prefix + midPal + suffix ; return answer ; } function reverse ( input ) { let a = input . split ( " " ) ; let l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { let temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return ( a ) . join ( " " ) ; } let str = " " ; document . write ( PrefixSuffixPalindrome ( str ) ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r
Iterator variables: i, l
Javascript program:
function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } function minimumAdjacentDifference ( a , n , k ) { let minDiff = Number . MAX_VALUE ; for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { let cnt = countSetBits ( i ) ; if ( cnt == n - k ) { let temp = [ ] ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) temp . push ( a [ j ] ) ; } let maxDiff = Number . MIN_VALUE ; for ( let j = 0 ; j < temp . length - 1 ; j ++ ) { maxDiff = Math . max ( maxDiff , temp [ j + 1 ] - temp [ j ] ) ; } minDiff = Math . min ( minDiff , maxDiff ) ; } } return minDiff ; } let n = 5 ; let k = 2 ; let a = [ 3 , 7 , 8 , 10 , 14 ] ; document . write ( minimumAdjacentDifference ( a , n , k ) ) ;

Index/key variables: j
Accumulator variables: i, j, setBits
Iterator variables: i, j
Javascript program:
function minimumAdjacentDifference ( a , n , k ) { let minDiff = Number . MAX_VALUE ; for ( let i = 0 ; i <= k ; i ++ ) { let maxDiff = Number . MIN_VALUE ; for ( let j = 0 ; j < n - k - 1 ; j ++ ) { for ( let p = i ; p <= i + j ; p ++ ) { maxDiff = Math . max ( maxDiff , a [ p + 1 ] - a [ p ] ) ; } } minDiff = Math . min ( minDiff , maxDiff ) ; } return minDiff ; } let n = 5 ; let k = 2 ; let a = [ 3 , 7 , 8 , 10 , 14 ] ; document . write ( minimumAdjacentDifference ( a , n , k ) ) ;

Index/key variables: p
Accumulator variables: i, j, p
Iterator variables: i, j, p
Javascript program:
function gcdFunc ( a , b ) { if ( b == 0 ) return a ; return gcdFunc ( b , a % b ) ; } function findMinimumElements ( a , n ) { let b = new Array ( n - 1 ) ; for ( let i = 1 ; i < n ; i ++ ) { b [ i - 1 ] = a [ i ] - a [ i - 1 ] ; } let gcd = b [ 0 ] ; for ( let i = 0 ; i < n - 1 ; i ++ ) { gcd = gcdFunc ( gcd , b [ i ] ) ; } let ans = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { ans += ( b [ i ] / gcd ) - 1 ; } return ans ; } let arr1 = [ 1 , 6 , 8 , 10 , 14 , 16 ] ; let n1 = arr1 . length ; document . write ( findMinimumElements ( arr1 , n1 ) + " " ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function checkPermutation ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; let prefix = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; prefix [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefix [ i ] = prefix [ i - 1 ] + arr [ i ] ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let lsum = prefix [ i ] ; let rsum = sum - prefix [ i ] ; let l_len = i + 1 , r_len = n - i - 1 ; if ( ( ( 2 * lsum ) == ( l_len * ( l_len + 1 ) ) ) && ( ( 2 * rsum ) == ( r_len * ( r_len + 1 ) ) ) ) return true ; } return false ; } let arr = [ 1 , 2 , 5 , 3 , 4 , 1 , 2 ] ; let n = arr . length ; if ( checkPermutation ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findTheNumber ( n ) { if ( n == 1 ) { document . write ( " " ) ; return ; } for ( var i = 0 ; i < n - 1 ; i ++ ) { document . write ( " " ) ; } document . write ( " " ) ; } var n = 12 ; findTheNumber ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAXN = 1000005 ; var even = Array ( MAXN ) . fill ( 0 ) ; var odd = Array ( MAXN ) . fill ( 0 ) ; function precompute ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) odd [ i ] = 1 ; if ( arr [ i ] % 2 == 0 ) even [ i ] = 1 ; } for ( var i = 1 ; i < n ; i ++ ) { even [ i ] = even [ i ] + even [ i - 1 ] ; odd [ i ] = odd [ i ] + odd [ i - 1 ] ; } } function isOdd ( L , R ) { var cnt = odd [ R ] ; if ( L > 0 ) cnt -= odd [ L - 1 ] ; if ( cnt == R - L + 1 ) return true ; return false ; } function performQueries ( a , n , q , m ) { precompute ( a , n ) ; for ( var i = 0 ; i < m ; i ++ ) { var L = q [ i ] [ 0 ] , R = q [ i ] [ 1 ] ; if ( isOdd ( L , R ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } } var a = [ 2 , 1 , 5 , 7 , 6 , 8 , 9 ] ; var n = a . length ; var q = [ [ 0 , 2 ] , [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 6 ] ] ; var m = q . length ; performQueries ( a , n , q , m ) ;

Index/key variables: R, i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function findTriplets ( x ) { let fact = [ ] ; let factors = new Set ( ) ; for ( let i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { fact . push ( i ) ; if ( x / i != i ) fact . push ( x / i ) ; factors . add ( i ) ; factors . add ( x / i ) ; } } let found = false ; let k = fact . length ; for ( let i = 0 ; i < k ; i ++ ) { let a = fact [ i ] ; for ( let j = 0 ; j < k ; j ++ ) { let b = fact [ j ] ; if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) { document . write ( a + " " + b + " " + ( x / ( a * b ) ) ) ; found = true ; break ; } } if ( found ) break ; } if ( ! found ) document . write ( " " ) ; } let x = 105 ; findTriplets ( x ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: found
Javascript program:
function countPair ( a , b ) { var s = ( b . toString ( ) ) ; var i ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] != ' ' ) break ; } var result ; if ( i == s . length ) result = a * s . length ; else result = a * ( s . length - 1 ) ; return result ; } var a = 5 , b = 101 ; document . write ( countPair ( a , b ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function flipsPossible ( a , n ) { let count_odd = 0 ; let count_even = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ; else count_even ++ ; } if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ; else return true ; } let a = [ 1 , 0 , 1 , 1 , 0 , 1 ] ; let n = a . length ; if ( flipsPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: count_even, count_odd, i
Iterator variables: i
Javascript program:
function PerformQueries ( a , vec ) { let ans = new Array ( ) ; let n = a . length - 1 ; let q = vec . length ; for ( let i = 0 ; i < q ; ++ i ) { let t = vec [ i ] [ 0 ] ; let m = vec [ i ] [ 1 ] ; if ( m > n ) { ans . push ( - 1 ) ; continue ; } let turn = Math . floor ( t / n ) ; let rem = t % n ; if ( rem == 0 && turn % 2 == 1 ) { ans . push ( - 1 ) ; continue ; } if ( rem == 0 && turn % 2 == 0 ) { ans . push ( a [ m ] ) ; continue ; } if ( turn % 2 == 0 ) { let cursize = n - rem ; if ( cursize < m ) { ans . push ( - 1 ) ; continue ; } ans . push ( a [ m + rem ] ) ; } else { let cursize = rem ; if ( cursize < m ) { ans . push ( - 1 ) ; continue ; } ans . push ( a [ m ] ) ; } } for ( let i of ans ) document . write ( i + " " ) ; } let a = [ - 1 , 1 , 2 , 3 , 4 , 5 ] ; let vec = [ [ 1 , 4 ] , [ 6 , 1 ] , [ 3 , 5 ] ] ; PerformQueries ( a , vec ) ;

Index/key variables: i, m
Iterator variables: i
Javascript program:
function sumEqualProduct ( a , n ) { var zero = 0 , two = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { zero ++ ; } if ( a [ i ] == 2 ) { two ++ ; } } var cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ; return cnt ; } var a = [ 2 , 2 , 3 , 4 , 2 , 6 ] ; var n = a . length ; document . write ( sumEqualProduct ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, two, zero
Iterator variables: i
Javascript program:
function minSum ( n ) { var sum = 0 ; while ( n > 0 ) { sum += ( n % 10 ) ; n = parseInt ( n / 10 ) ; } if ( sum == 1 ) return 10 ; return sum ; } var n = 1884 ; document . write ( minSum ( n ) ) ;

Accumulator variables: sum
Javascript program:
function initialize ( mul , div , size ) { for ( i = 1 ; i < size ; i ++ ) { mul [ i ] = ( mul [ i ] * mul [ i - 1 ] ) / div [ i ] ; } } function update ( l , r , x , mul , div ) { mul [ l ] *= x ; div [ r + 1 ] *= x ; } function printArray ( ar , mul , div , n ) { for ( i = 0 ; i < n ; i ++ ) { ar [ i ] = ar [ i ] * mul [ i ] ; document . write ( ar [ i ] + " " ) ; } } var ar = [ 10 , 5 , 20 , 40 ] ; var n = ar . length ; var mul = Array ( n + 1 ) . fill ( 0 ) ; var div = Array ( n + 1 ) . fill ( 0 ) ; for ( i = 0 ; i < n + 1 ; i ++ ) { mul [ i ] = div [ i ] = 1 ; } update ( 0 , 1 , 10 , mul , div ) ; update ( 1 , 3 , 20 , mul , div ) ; update ( 2 , 2 , 2 , mul , div ) ; initialize ( mul , div , n + 1 ) ; printArray ( ar , mul , div , n ) ;

Index/key variables: i, l
Accumulator variables: i
Iterator variables: i
Javascript program:
function getWinner ( str , len ) { var total = 0 ; if ( str [ 0 ] == ' ' str [ len - 1 ] == ' ' ) return " " ; else { for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) { total ++ ; } } if ( ( total % 2 ) == 1 ) return " " ; return " " ; } } var str = " " ; var len = str . length ; document . write ( getWinner ( str , len ) ) ;

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function findArrangement ( arr , n ) { if ( n < 2 ) { document . write ( " " ) ; return ; } var minVal = arr . reduce ( ( a , b ) => Math . min ( a , b ) ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == minVal ) { [ arr [ i ] , arr [ n - 1 ] ] = [ arr [ n - 1 ] , arr [ i ] ] ; break ; } } var andVal = arr [ 0 ] ; for ( var i = 1 ; i < n - 1 ; i ++ ) { andVal &= arr [ i ] ; } if ( andVal == arr [ n - 1 ] ) printArr ( arr , n ) ; else document . write ( " " ) ; } var arr = [ 1 , 5 , 3 , 3 ] ; var n = arr . length ; findArrangement ( arr , n ) ;

Index/key variables: i
Accumulator variables: andVal, i
Iterator variables: i
Javascript program:
var DIGITS = 10 var MAX = 10000 var MOD = 1000000007 var dp = Array . from ( Array ( MAX ) , ( ) => Array ( DIGITS ) . fill ( 0 ) ) ; var cnt = Array . from ( Array ( MAX ) , ( ) => Array ( DIGITS ) . fill ( 0 ) ) ; function precompute ( ) { for ( var i = 0 ; i < DIGITS ; i ++ ) dp [ 1 ] [ i ] = i , cnt [ 1 ] [ i ] = 1 ; for ( var i = 2 ; i < MAX ; i ++ ) { for ( var j = 0 ; j < DIGITS ; j ++ ) { for ( var k = 0 ; k < DIGITS ; k ++ ) { if ( j != k ) { dp [ i ] [ j ] = dp [ i ] [ j ] + ( dp [ i - 1 ] [ k ] + ( cnt [ i - 1 ] [ k ] * j ) % MOD ) % MOD ; dp [ i ] [ j ] %= MOD ; cnt [ i ] [ j ] += cnt [ i - 1 ] [ k ] ; cnt [ i ] [ j ] %= MOD ; } } } } } var x = 6 , y = 4 ; precompute ( ) ; document . write ( dp [ x ] [ y ] ) ;

Index/key variables: i, j, k, x, y
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
var N = 10000 ; var MOD = 1000000007 ; var F = Array ( N ) ; function precompute ( ) { F [ 1 ] = 2 ; F [ 2 ] = 3 ; F [ 3 ] = 4 ; for ( var i = 4 ; i < N ; i ++ ) F [ i ] = ( F [ i - 1 ] + F [ i - 2 ] ) % MOD ; } var n = 8 ; precompute ( ) ; document . write ( F [ n ] ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubArraySum ( a , size ) { var max_so_far = - 1000000000 , max_ending_here = 0 ; for ( var i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } function minimizedSum ( a , n , K ) { var sum = maxSubArraySum ( a , n ) ; var totalSum = 0 ; for ( var i = 0 ; i < n ; i ++ ) totalSum += a [ i ] ; if ( sum < 0 ) return totalSum ; totalSum = totalSum - sum + sum / K ; return totalSum ; } var a = [ 1 , - 2 , 3 ] ; var n = a . length ; var K = 2 ; document . write ( minimizedSum ( a , n , K ) ) ;

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function randomList ( m , n ) { let arr = new Array ( m ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { arr [ ( Math . floor ( ( Math . random ( ) * n ) ) % m ) ] ++ ; } printArr ( arr , m ) ; } let m = 4 , n = 8 ; randomList ( m , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxPartition ( s ) { var n = s . length , P = 0 ; var current = " " , previous = " " ; for ( var i = 0 ; i < n ; i ++ ) { current += s [ i ] ; if ( current != previous ) { previous = current ; current = " " ; P ++ ; } } return P ; } var s = " " ; var ans = maxPartition ( s ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: P, current, i
Iterator variables: i
Javascript program:
var N = 4 , i , j , min ; document . write ( " " + N + " " ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; }

Accumulator variables: i, j
Iterator variables: i, j