dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findMaxValByRearrArr ( arr , N ) { arr . sort ( ) ; let res = 0 ; do { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += __gcd ( i + 1 , arr [ i ] ) ; } res = Math . max ( res , sum ) ; } while ( next_permutation ( arr ) ) ; return res ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } 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 = [ 3 , 2 , 1 ] ; let N = arr . length ; document . write ( findMaxValByRearrArr ( arr , N ) ) ;

Index/key variables: a, b, i
Accumulator variables: i, sum
Iterator variables: a, b, i
Javascript program:
function min_elements ( 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 cntMinRem = 0 ; mp . forEach ( ( value , key ) => { var i = key ; if ( mp . get ( i ) < i ) { cntMinRem += mp . get ( i ) ; } else if ( mp . get ( i ) > i ) { cntMinRem += ( mp . get ( i ) - i ) ; } } ) ; return cntMinRem ; } var arr = [ 2 , 4 , 1 , 4 , 2 ] ; var N = arr . length ; document . write ( min_elements ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: cntMinRem, i
Iterator variables: i
Javascript program:
function CheckAllarrayEqual ( arr , N ) { if ( N == 1 ) { return true ; } let totalSum = arr [ 0 ] ; let secMax = Number . MIN_VALUE ; let Max = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] >= Max ) { secMax = Max ; Max = arr [ i ] ; } else if ( arr [ i ] > secMax ) { secMax = arr [ i ] ; } totalSum += arr [ i ] ; } if ( ( secMax * ( N - 1 ) ) > totalSum ) { return false ; } if ( totalSum % ( N - 1 ) != 0 ) { return false ; } return true ; } let arr = [ 6 , 2 , 2 , 2 ] ; let N = arr . length ; if ( CheckAllarrayEqual ( arr , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Javascript program:
function Remove_one_element ( arr , n ) { let post_odd = 0 , post_even = 0 ; let curr_odd = 0 , curr_even = 0 ; let res = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( i % 2 != 0 ) post_odd ^= arr [ i ] ; else post_even ^= arr [ i ] ; } for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) post_odd ^= arr [ i ] ; else post_even ^= arr [ i ] ; let X = curr_odd ^ post_even ; let Y = curr_even ^ post_odd ; if ( X == Y ) res ++ ; if ( i % 2 != 0 ) curr_odd ^= arr [ i ] ; else curr_even ^= arr [ i ] ; } document . write ( res ) ; } let arr = [ 1 , 0 , 1 , 0 , 1 ] ; let N = arr . length ; Remove_one_element ( arr , N ) ;

Index/key variables: i
Accumulator variables: curr_even, curr_odd, i, post_even, post_odd, res
Iterator variables: i
Javascript program:
function cntIndexesToMakeBalance ( arr , n ) { if ( n == 1 ) { return 1 ; } if ( n == 2 ) return 0 ; let sumEven = 0 ; let sumOdd = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { sumEven += arr [ i ] ; } else { sumOdd += arr [ i ] ; } } let currOdd = 0 ; let currEven = arr [ 0 ] ; let res = 0 ; let newEvenSum = 0 ; let newOddSum = 0 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( i % 2 ) { currOdd += arr [ i ] ; newEvenSum = currEven + sumOdd - currOdd ; newOddSum = currOdd + sumEven - currEven - arr [ i ] ; } else { currEven += arr [ i ] ; newOddSum = currOdd + sumEven - currEven ; newEvenSum = currEven + sumOdd - currOdd - arr [ i ] ; } if ( newEvenSum == newOddSum ) { res ++ ; } } if ( sumOdd == sumEven - arr [ 0 ] ) { res ++ ; } if ( n % 2 == 1 ) { if ( sumOdd == sumEven - arr [ n - 1 ] ) { res ++ ; } } else { if ( sumEven == sumOdd - arr [ n - 1 ] ) { res ++ ; } } return res ; } let arr = [ 1 , 1 , 1 ] ; let n = arr . length ; document . write ( cntIndexesToMakeBalance ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: currEven, currOdd, i, res, sumEven, sumOdd
Iterator variables: i
Javascript program:
function checkCount ( A , Q , q ) { for ( let i = 0 ; i < q ; i ++ ) { let L = Q [ i ] [ 0 ] ; let R = Q [ i ] [ 1 ] ; L -- ; R -- ; if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } } let arr = [ 11 , 13 , 12 , 14 ] ; let Q = [ [ 1 , 4 ] , [ 2 , 4 ] ] ; let q = Q . length ; checkCount ( arr , Q , q ) ;

Index/key variables: L, R, i
Accumulator variables: L, R, i
Iterator variables: i
Javascript program:
function pairProductMean ( arr , N ) { var pairArray = [ ] ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var pairProduct = arr [ i ] * arr [ j ] ; pairArray . push ( pairProduct ) ; } } var length = pairArray . length ; var sum = 0 ; for ( i = 0 ; i < length ; i ++ ) sum += pairArray [ i ] ; var mean ; if ( length != 0 ) mean = sum / length ; else mean = 0 ; return mean ; } var arr = [ 1 , 2 , 4 , 8 ] ; var N = arr . length ; document . write ( pairProductMean ( arr , N ) . toFixed ( 2 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findPlayer ( str , n ) { let move_first = 0 ; let move_sec = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] [ 0 ] == str [ i ] [ str [ i ] . length - 1 ] ) { if ( str [ i ] [ 0 ] == 48 ) move_first ++ ; else move_sec ++ ; } } if ( move_first <= move_sec ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str = [ " " , " " ] ; let N = str [ 0 ] . length ; findPlayer ( str , N ) ;

Index/key variables: i
Accumulator variables: i, move_first, move_sec
Iterator variables: i
Javascript program:
function find_next ( n , k ) { let M = n + 1 ; while ( true ) { if ( ( M & ( 1 << k ) ) > 0 ) break ; M ++ ; } return M ; } let N = 15 , K = 2 ; document . write ( find_next ( N , K ) ) ;

Accumulator variables: M
Javascript program:
function largestString ( num , k ) { var ans = " " ; var str = num . split ( " " ) ; for ( const i of str ) { while ( ans . length > 0 && ans [ ans . length - 1 ] < i && k > 0 ) { ans = ans . substring ( 0 , ans . length - 1 ) ; k -- ; } ans += i ; } while ( ans . length > 0 && k -- > 0 ) { ans = ans . substring ( 0 , ans . length - 1 ) ; } return ans ; } var str = " " ; var k = 1 ; document . write ( largestString ( str , k ) + " " ) ;

Accumulator variables: ans, k
Iterator variables: i
Javascript program:
function maxLengthSubArray ( A , N ) { let forward = Array . from ( { length : N } , ( _ , i ) => 0 ) ; let backward = Array . from ( { length : N } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( i == 0 A [ i ] != A [ i - 1 ] ) { forward [ i ] = 1 ; } else forward [ i ] = forward [ i - 1 ] + 1 ; } for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 A [ i ] != A [ i + 1 ] ) { backward [ i ] = 1 ; } else backward [ i ] = backward [ i + 1 ] + 1 ; } let ans = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) ans = Math . max ( ans , Math . min ( forward [ i ] , backward [ i + 1 ] ) * 2 ) ; } document . write ( ans ) ; } let arr = [ 1 , 2 , 3 , 4 , 4 , 4 , 6 , 6 , 6 , 9 ] ; let N = arr . length ; maxLengthSubArray ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function helper ( d , s ) { let ans = [ ] ; for ( let i = 0 ; i < d ; i ++ ) { ans . push ( " " ) ; } for ( let i = d - 1 ; i >= 0 ; i -- ) { if ( s >= 9 ) { ans [ i ] = ' ' ; s -= 9 ; } else { let c = String . fromCharCode ( s + ' ' . charCodeAt ( 0 ) ) ; ans [ i ] = c ; s = 0 ; } } return ans . join ( " " ) ; } function findMin ( x , Y ) { let y = Y . toString ( ) ; let n = y . length ; let p = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { p . push ( 0 ) ; } for ( let i = 0 ; i < n ; i ++ ) { p [ i ] = y [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( i > 0 ) { p [ i ] = p [ i ] + p [ i - 1 ] ; } } for ( let i = n - 1 , k = 0 ; ; i -- , k ++ ) { let d = 0 ; if ( i >= 0 ) { d = y [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } for ( let j = d + 1 ; j <= 9 ; j ++ ) { let r = j ; if ( i > 0 ) { r += p [ i - 1 ] ; } if ( x - r >= 0 && x - r <= 9 * k ) { let suf = helper ( k , x - r ) ; let pre = " " ; if ( i > 0 ) pre = y . substring ( 0 , i ) ; let cur = String . fromCharCode ( j + ' ' . charCodeAt ( 0 ) ) ; pre += cur ; return pre + suf ; } } } } let x = 18 ; let y = 99 ; document . write ( findMin ( x , y ) ) ;

Index/key variables: i
Accumulator variables: i, j, k, pre, r, s
Iterator variables: i, j
Javascript program:
function largestNumber ( n , X , Y ) { let maxm = Math . max ( X , Y ) ; Y = X + Y - maxm ; X = maxm ; let Xs = 0 ; let Ys = 0 ; while ( n > 0 ) { if ( n % Y == 0 ) { Xs += n ; n = 0 ; } else { n -= X ; Ys += X ; } } if ( n == 0 ) { while ( Xs -- > 0 ) document . write ( X ) ; while ( Ys -- > 0 ) document . write ( Y ) ; } else document . write ( " " ) ; } let n = 19 , X = 7 , Y = 5 ; largestNumber ( n , X , Y ) ;

Accumulator variables: Xs, Ys, n
Javascript program:
function minChanges ( str , N ) { var res ; var count0 = 0 , count1 = 0 ; str . split ( ' ' ) . forEach ( x => { count0 += ( x == ' ' ) ; } ) ; res = count0 ; str . split ( ' ' ) . forEach ( x => { count0 -= ( x == ' ' ) ; count1 += ( x == ' ' ) ; res = Math . min ( res , count1 + count0 ) ; } ) ; return res ; } var N = 9 ; var str = " " ; document . write ( minChanges ( str , N ) ) ;

Accumulator variables: count0, count1
Javascript program:
function missingnumber ( n , arr ) { let mn = 10000 ; let mx = - 10000 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i > 0 && arr [ i ] == - 1 && arr [ i - 1 ] != - 1 ) { mn = Math . min ( mn , arr [ i - 1 ] ) ; mx = Math . max ( mx , arr [ i - 1 ] ) ; } if ( i < ( n - 1 ) && arr [ i ] == - 1 && arr [ i + 1 ] != - 1 ) { mn = Math . min ( mn , arr [ i + 1 ] ) ; mx = Math . max ( mx , arr [ i + 1 ] ) ; } } let res = ( mx + mn ) / 2 ; return res ; } let n = 5 ; let arr = [ - 1 , 10 , - 1 , 12 , - 1 ] ; let res = missingnumber ( n , arr ) ; document . write ( res ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LCSubStr ( A , B , m , n ) { let LCSuff = Array ( m + 1 ) . fill ( Array ( n + 1 ) ) ; let result = 0 ; for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) LCSuff [ i ] [ j ] = 0 ; else if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) { LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ; if ( LCSuff [ i ] [ j ] > result ) { result = LCSuff [ i ] [ j ] ; } } else LCSuff [ i ] [ j ] = 0 ; } } result ++ ; return result ; } let A = " " ; let B = " " ; let M = A . length ; let N = B . length ; document . write ( LCSubStr ( A , B , M , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j
Javascript program:
var maxN = 20 ; var maxSum = 50 ; var minSum = 50 ; var base = 50 ; var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxSum + minSum ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxSum + minSum ) ) ; function findCnt ( arr , i , required_sum , n ) { if ( i == n ) { if ( required_sum == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ required_sum + base ] ) return dp [ i ] [ required_sum + base ] ; v [ i ] [ required_sum + base ] = 1 ; dp [ i ] [ required_sum + base ] = findCnt ( arr , i + 1 , required_sum , n ) + findCnt ( arr , i + 1 , required_sum - arr [ i ] , n ) ; return dp [ i ] [ required_sum + base ] ; } function countSubsets ( arr , K , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } var S1 = ( sum + K ) / 2 ; document . write ( findCnt ( arr , 0 , S1 , n ) ) ; } var arr = [ 1 , 1 , 2 , 3 ] ; var N = arr . length ; var K = 1 ; countSubsets ( arr , K , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
var dp = Array ( 105 ) . fill ( ) . map ( ( ) => Array ( 605 ) . fill ( 0.0 ) ) ; function find ( N , sum ) { if ( N < 0 sum < 0 ) return 0 ; if ( dp [ N ] [ sum ] > 0 ) return dp [ N ] [ sum ] ; if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return ( 1.0 / 6 ) ; else return 0 ; } for ( var i = 1 ; i <= 6 ; i ++ ) dp [ N ] [ sum ] = dp [ N ] [ sum ] + find ( N - 1 , sum - i ) / 6 ; return dp [ N ] [ sum ] ; } var N = 4 , a = 13 , b = 17 ; var probability = 0.0 ; for ( sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; document . write ( probability . toFixed ( 6 ) ) ;

Index/key variables: N, sum
Accumulator variables: i, sum
Iterator variables: i, sum
Javascript program:
function find_minimum_operations ( n , b , k ) { let d = new Array ( n + 1 ) ; d . fill ( 0 ) ; let i , operations = 0 , need ; for ( i = 0 ; i < n ; i ++ ) { if ( i > 0 ) { d [ i ] += d [ i - 1 ] ; } if ( b [ i ] > d [ i ] ) { operations += b [ i ] - d [ i ] ; need = b [ i ] - d [ i ] ; d [ i ] += need ; if ( i + k <= n ) { d [ i + k ] -= need ; } } } document . write ( operations ) ; } let n = 5 ; let b = [ 1 , 2 , 3 , 4 , 5 ] ; let k = 2 ; find_minimum_operations ( n , b , k ) ;

Index/key variables: i
Accumulator variables: i, operations
Iterator variables: i
Javascript program:
function ways ( arr , K ) { let R = arr . length ; let C = arr [ 0 ] . length ; let preSum = new Array ( R ) ; for ( let i = 0 ; i < R ; i ++ ) { preSum [ i ] = new Array ( C ) ; for ( let j = 0 ; j < C ; j ++ ) { preSum [ i ] [ j ] = 0 ; } } for ( let r = R - 1 ; r >= 0 ; r -- ) { for ( let c = C - 1 ; c >= 0 ; c -- ) { preSum [ r ] = arr [ r ] ; if ( r + 1 < R ) preSum [ r ] += preSum [ r + 1 ] ; if ( c + 1 < C ) preSum [ r ] += preSum [ r ] ; if ( r + 1 < R && c + 1 < C ) preSum [ r ] -= preSum [ r + 1 ] ; } } let dp = new Array ( K + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( R ) ; for ( let j = 0 ; j < R ; j ++ ) { dp [ i ] [ j ] = new Array ( C ) ; for ( let k = 0 ; k < C ; k ++ ) { dp [ i ] [ j ] [ k ] = 0 ; } } } for ( let k = 1 ; k <= K ; k ++ ) { for ( let r = R - 1 ; r >= 0 ; r -- ) { for ( let c = C - 1 ; c >= 0 ; c -- ) { if ( k == 1 ) { dp [ k ] [ r ] = ( preSum [ r ] > 0 ) ? 1 : 0 ; } else { dp [ k ] [ r ] = 0 ; for ( let r1 = r + 1 ; r1 < R ; r1 ++ ) { if ( preSum [ r ] - preSum [ r1 ] > 0 ) dp [ k ] [ r ] += dp [ k - 1 ] [ r1 ] ; } for ( let c1 = c + 1 ; c1 < C ; c1 ++ ) { if ( preSum [ r ] - preSum [ r ] [ c1 ] > 0 ) dp [ k ] [ r ] += dp [ k - 1 ] [ r ] [ c1 ] ; } } } } } return dp [ K ] [ 0 ] [ 0 ] ; } let arr = [ [ 1 , 0 , 0 ] , [ 1 , 1 , 1 ] , [ 0 , 0 , 0 ] ] ; let k = 3 ; document . write ( ways ( arr , k ) ) ;

Index/key variables: K, c1, i, j, k, r, r1
Accumulator variables: c, c1, i, j, k, r, r1
Iterator variables: c, c1, i, j, k, r, r1
Javascript program:
let p = 1000000007 ; function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } function nCr ( n , p , f , m ) { for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= m ; j ++ ) { if ( j > i ) { f [ i ] [ j ] = 0 ; } else if ( j == 0 j == i ) { f [ i ] [ j ] = 1 ; } else { f [ i ] [ j ] = ( f [ i - 1 ] [ j ] + f [ i - 1 ] [ j - 1 ] ) % p ; } } } } function ProductOfSubsets ( arr , n , m ) { let f = new Array ( n + 1 ) ; for ( var i = 0 ; i < f . length ; i ++ ) { f [ i ] = new Array ( 2 ) ; } nCr ( n , p - 1 , f , m ) ; arr . sort ( ) ; let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) { let x = 0 ; for ( let j = 1 ; j <= m ; j ++ ) { if ( m % j == 0 ) { x = ( x + ( f [ n - i - 1 ] [ m - j ] * f [ i ] [ j - 1 ] ) % ( p - 1 ) ) % ( p - 1 ) ; } } ans = ( ( ans * power ( arr [ i ] , x , p ) ) % p ) ; } document . write ( ans + " " ) ; } let arr = [ 4 , 5 , 7 , 9 , 3 ] ; let K = 4 ; let N = arr . length ; ProductOfSubsets ( arr , N , K ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countWays ( n , m ) { var dp = Array . from ( Array ( m + 1 ) , ( ) => Array ( n + 1 ) ) ; for ( var i = 0 ; i <= n ; i ++ ) { dp [ 1 ] [ i ] = 1 ; } var sum ; for ( var i = 2 ; i <= m ; i ++ ) { for ( var j = 0 ; j <= n ; j ++ ) { sum = 0 ; for ( var k = 0 ; k <= j ; k ++ ) { sum += dp [ i - 1 ] [ k ] ; } dp [ i ] [ j ] = sum ; } } return dp [ m ] [ n ] ; } var N = 2 , K = 3 ; document . write ( countWays ( N , K ) ) ;

Index/key variables: i, j, k, m, n
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
function countWays ( n , m ) { let dp = new Array ( m + 1 ) ; for ( let i = 0 ; i < m + 1 ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = 0 ; i <= n ; i ++ ) { dp [ 1 ] [ i ] = 1 ; if ( i != 0 ) { dp [ 1 ] [ i ] += dp [ 1 ] [ i - 1 ] ; } } for ( let i = 2 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( j == 0 ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } else { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; if ( i == m && j == n ) { return dp [ i ] [ j ] ; } dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } } } return Number . MIN_VALUE ; } let N = 2 , K = 3 ; document . write ( countWays ( N , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function SieveOfEratosthenes ( MAX , primes ) { let prime = new Array ( MAX + 1 ) . fill ( true ) ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] ) primes . push ( i ) ; } } function findLongest ( A , n ) { let mpp = new Map ( ) ; let primes = new Array ( ) ; SieveOfEratosthenes ( A [ n - 1 ] , primes ) ; let dp = new Array ( n ) ; dp . fill ( 0 ) dp [ n - 1 ] = 1 ; mpp . set ( A [ n - 1 ] , n - 1 ) ; for ( let i = n - 2 ; i >= 0 ; i -- ) { let num = A [ i ] ; dp [ i ] = 1 ; let maxi = 0 ; for ( let it of primes ) { let xx = num * it ; if ( xx > A [ n - 1 ] ) break ; else if ( mpp . get ( xx ) ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ mpp . get ( xx ) ] ) ; } } mpp . set ( A [ i ] , i ) ; } let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } let a = [ 1 , 2 , 5 , 6 , 12 , 35 , 60 , 385 ] ; let n = a . length ; document . write ( findLongest ( a , n ) ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, it, p
Javascript program:
function waysToKAdjacentSetBits ( n , k , currentIndex , adjacentSetBits , lastBit ) { if ( currentIndex == n ) { if ( adjacentSetBits == k ) return 1 ; return 0 ; } let noOfWays = 0 ; if ( lastBit == 1 ) { noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits + 1 , 1 ) ; noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } else if ( ! lastBit ) { noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 1 ) ; noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } return noOfWays ; } let n = 5 , k = 2 ; let totalWays = waysToKAdjacentSetBits ( n , k , 1 , 0 , 1 ) + waysToKAdjacentSetBits ( n , k , 1 , 0 , 0 ) ; document . write ( " " + totalWays ) ;

Accumulator variables: noOfWays
Javascript program:
function postfix ( a , n ) { for ( let i = n - 1 ; i > 0 ; i -- ) { a [ i - 1 ] = a [ i - 1 ] + a [ i ] ; } } function modify ( a , n ) { for ( let i = 1 ; i < n ; i ++ ) { a [ i - 1 ] = i * a [ i ] ; } } function allCombination ( a , n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { sum += i ; } document . write ( " " + sum + " " ) ; for ( let i = 1 ; i < n ; i ++ ) { postfix ( a , n - i + 1 ) ; sum = 0 ; for ( let j = 1 ; j <= n - i ; j ++ ) { sum += ( j * a [ j ] ) ; } document . write ( " " + ( i + 1 ) + " " + sum + " " ) ; modify ( a , n ) ; } } let n = 5 ; let a = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; } allCombination ( a , n ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function isSubsetSum ( arr , n , sum ) { if ( sum == 0 ) return true ; if ( n == 0 && sum != 0 ) return false ; if ( arr [ n - 1 ] > sum ) return isSubsetSum ( arr , n - 1 , sum ) ; return isSubsetSum ( arr , n - 1 , sum ) || isSubsetSum ( arr , n - 1 , sum - arr [ n - 1 ] ) ; } function findPartition ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; return isSubsetSum ( arr , n , Math . floor ( sum / 2 ) ) ; } let arr = [ 3 , 1 , 5 , 9 , 12 ] ; let n = arr . length ; if ( findPartition ( arr , n ) == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function binomialCoeff ( n , r ) { if ( r > n ) return 0 ; let m = 1000000007 ; let inv = new Array ( r + 1 ) . fill ( 0 ) ; inv [ 0 ] = 1 ; if ( r + 1 >= 2 ) inv [ 1 ] = 1 ; for ( let i = 2 ; i <= r ; i ++ ) { inv [ i ] = m - Math . floor ( m / i ) * inv [ m % i ] % m ; } let ans = 1 ; for ( let i = 2 ; i <= r ; i ++ ) { ans = ( ( ans % m ) * ( inv [ i ] % m ) ) % m ; } for ( let i = n ; i >= ( n - r + 1 ) ; i -- ) { ans = ( ( ans % m ) * ( i % m ) ) % m ; } return ans ; } let n = 5 , r = 2 ; document . write ( " " + n + " " + r + " " + binomialCoeff ( n , r ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function MinValue ( N , X ) { let len = N . length ; let position = len + 1 ; if ( N [ 0 ] == ' ' ) { for ( let i = len - 1 ; i >= 1 ; i -- ) { if ( ( N [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) < X ) { position = i ; } } } else { for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( ( N [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) > X ) { position = i ; } } } const c = String . fromCharCode ( X + ' ' . charCodeAt ( 0 ) ) ; let str = N . slice ( 0 , position ) + c + N . slice ( position ) ; return str ; } let N = " " ; let X = 1 ; document . write ( MinValue ( N , X ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function divisibleByk ( s , n , k ) { let poweroftwo = new Array ( n ) ; poweroftwo [ 0 ] = 1 % k ; for ( let i = 1 ; i < n ; i ++ ) { poweroftwo [ i ] = ( poweroftwo [ i - 1 ] * ( 2 % k ) ) % k ; } let rem = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ n - i - 1 ] == ' ' ) { rem += ( poweroftwo [ i ] ) ; rem %= k ; } } if ( rem == 0 ) { return " " ; } else return " " ; } let s = " " ; let k = 9 ; let n = s . length ; document . write ( divisibleByk ( s , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, rem
Iterator variables: i
Javascript program:
function maxSumbySplittingstring ( str , N ) { var cntOne = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { cntOne ++ ; } } var zero = 0 ; var one = 0 ; var res = 0 ; for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( str [ i ] == ' ' ) { zero ++ ; } else { one ++ ; } res = Math . max ( res , zero + cntOne - one ) ; } return res ; } var str = " " ; var N = str . length ; document . write ( maxSumbySplittingstring ( str , N ) ) ;

Index/key variables: i
Accumulator variables: cntOne, i, one, zero
Iterator variables: i
Javascript program:
function cntBalancedParenthesis ( s , N ) { var cntPairs = 0 ; var cntCurly = 0 ; var cntSml = 0 ; var cntSqr = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { cntCurly ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSml ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSqr ++ ; } else if ( s . charAt ( i ) == ' ' && cntCurly > 0 ) { cntCurly -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSml > 0 ) { cntSml -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSqr > 0 ) { cntSqr -- ; cntPairs ++ ; } } document . write ( cntPairs ) ; } var s = " " ; var N = s . length ; cntBalancedParenthesis ( s , N ) ;

Accumulator variables: cntCurly, cntPairs, cntSml, cntSqr, i
Iterator variables: i