dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function find_distinct ( a , n , q , queries ) { let MAX = 100001 ; let check = new Array ( MAX ) . fill ( 0 ) ; let idx = new Array ( MAX ) . fill ( 0 ) ; let cnt = 1 ; let i = n - 1 ; while ( i >= 0 ) { if ( check [ a [ i ] ] == 0 ) { idx [ i ] = cnt ; check [ a [ i ] ] = 1 ; cnt ++ ; } else { idx [ i ] = cnt - 1 ; } i -- ; } for ( let i = 0 ; i < q ; i ++ ) { let m = queries [ i ] ; document . write ( idx [ m ] + " " ) ; } } let a = [ 1 , 2 , 3 , 1 , 2 , 3 , 4 , 5 ] ; let n = a . length ; let queries = [ 0 , 3 , 5 , 7 ] ; let q = queries . length ; find_distinct ( a , n , q , queries ) ;

Index/key variables: i, m
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
const MAX = 24 ; function countOp ( x ) { let arr = new Array ( MAX ) ; arr [ 0 ] = 1 ; for ( let i = 1 ; i < MAX ; i ++ ) arr [ i ] = arr [ i - 1 ] * 2 ; let temp = x ; let flag = true ; let ans ; let operations = 0 ; let flag2 = false ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( arr [ i ] - 1 == x ) flag2 = true ; if ( arr [ i ] > x ) { ans = i ; break ; } } if ( flag2 ) return 0 ; while ( flag ) { if ( arr [ ans ] < x ) ans ++ ; operations ++ ; for ( let i = 0 ; i < MAX ; i ++ ) { let take = x ^ ( arr [ i ] - 1 ) ; if ( take <= arr [ ans ] - 1 ) { if ( take > temp ) temp = take ; } } if ( temp == arr [ ans ] - 1 ) { flag = false ; break ; } temp ++ ; operations ++ ; x = temp ; if ( x == arr [ ans ] - 1 ) flag = false ; } return operations ; } let x = 39 ; document . write ( countOp ( x ) ) ;

Index/key variables: ans, i
Accumulator variables: ans, i, operations, temp
Iterator variables: i
Boolean variables: flag, flag2
Javascript program:
function minOperations ( arr , n ) { let maxi , result = 0 ; let freq = new Array ( 1000001 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { let x = arr [ i ] ; freq [ x ] ++ ; } maxi = Math . max ( ... arr ) ; for ( let i = 1 ; i <= maxi ; i ++ ) { if ( freq [ i ] != 0 ) { for ( let j = i * 2 ; j <= maxi ; j = j + i ) { freq [ j ] = 0 ; } result ++ ; } } return result ; } let arr = [ 2 , 4 , 2 , 4 , 4 , 4 ] ; let n = arr . length ; document . write ( minOperations ( arr , n ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, result
Iterator variables: i, j
Javascript program:
function __gcd ( a , b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } function minGCD ( arr , n ) { var minGCD = 0 ; for ( i = 0 ; i < n ; i ++ ) minGCD = __gcd ( minGCD , arr [ i ] ) ; return minGCD ; } function minLCM ( arr , n ) { var minLCM = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) minLCM = Math . min ( minLCM , arr [ i ] ) ; return minLCM ; } var arr = [ 2 , 66 , 14 , 521 ] ; var n = arr . length ; document . write ( " " + minLCM ( arr , n ) + " " + minGCD ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function formStringMinOperations ( s ) { var count = new Array ( 3 ) . fill ( 0 ) ; for ( const c of s ) { count += 1 ; } var processed = new Array ( 3 ) . fill ( 0 ) ; var reqd = parseInt ( s . length / 3 ) ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( count [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] === reqd ) { continue ; } if ( s [ i ] === " " && count [ 0 ] > reqd && processed [ 0 ] >= reqd ) { if ( count [ 1 ] < reqd ) { s [ i ] = " " ; count [ 1 ] ++ ; count [ 0 ] -- ; } else if ( count [ 2 ] < reqd ) { s [ i ] = " " ; count [ 2 ] ++ ; count [ 0 ] -- ; } } if ( s [ i ] === " " && count [ 1 ] > reqd ) { if ( count [ 0 ] < reqd ) { s [ i ] = " " ; count [ 0 ] ++ ; count [ 1 ] -- ; } else if ( count [ 2 ] < reqd && processed [ 1 ] >= reqd ) { s [ i ] = " " ; count [ 2 ] ++ ; count [ 1 ] -- ; } } if ( s [ i ] === " " && count [ 2 ] > reqd ) { if ( count [ 0 ] < reqd ) { s [ i ] = " " ; count [ 0 ] ++ ; count [ 2 ] -- ; } else if ( count [ 1 ] < reqd ) { s [ i ] = " " ; count [ 1 ] ++ ; count [ 2 ] -- ; } } processed [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } return s . join ( " " ) ; } var s = " " ; document . write ( formStringMinOperations ( s . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: c, i
Javascript program:
function findMinimumAdjacentSwaps ( arr , N ) { let visited = Array ( N + 1 ) . fill ( false ) ; let minimumSwaps = 0 ; for ( let i = 0 ; i < 2 * N ; i ++ ) { if ( visited [ arr [ i ] ] == false ) { visited [ arr [ i ] ] = true ; let count = 0 ; for ( let j = i + 1 ; j < 2 * N ; j ++ ) { if ( visited [ arr [ j ] ] == false ) count ++ ; else if ( arr [ i ] == arr [ j ] ) minimumSwaps += count ; } } } return minimumSwaps ; } let arr = [ 1 , 2 , 3 , 3 , 1 , 2 ] ; let N = arr . length ; N = Math . floor ( N / 2 ) ; document . write ( findMinimumAdjacentSwaps ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, minimumSwaps
Iterator variables: i, j
Javascript program:
function possibility ( m , length , s ) { var countodd = 0 ; for ( var i = 0 ; i < length ; i ++ ) { if ( m . get ( s . charCodeAt ( i ) - 48 ) & 1 ) countodd ++ ; if ( countodd > 1 ) return false ; } return true ; } function largestPalindrome ( s ) { var l = s . length ; var m = new Map ( ) ; for ( var i = 0 ; i < l ; i ++ ) { if ( m . has ( s . charCodeAt ( i ) - 48 ) ) m . set ( s . charCodeAt ( i ) - 48 , m . get ( s . charCodeAt ( i ) - 48 ) + 1 ) ; else m . set ( s . charCodeAt ( i ) - 48 , 1 ) ; } if ( possibility ( m , l , s ) == false ) { document . write ( " " ) ; return ; } var largest = new Array ( l ) ; var front = 0 ; for ( var i = 9 ; i >= 0 ; i -- ) { if ( m . has ( i ) & 1 ) { largest [ Math . floor ( l / 2 ) ] = String . fromCharCode ( i + 48 ) ; m . set ( i , m . get ( i ) - 1 ) ; while ( m . get ( i ) > 0 ) { largest [ front ] = String . fromCharCode ( i + 48 ) ; largest [ l - front - 1 ] = String . fromCharCode ( i + 48 ) ; m . set ( i , m . get ( i ) - 2 ) ; front ++ ; } } else { while ( m . get ( i ) > 0 ) { largest [ front ] = String . fromCharCode ( i + 48 ) ; largest [ l - front - 1 ] = String . fromCharCode ( i + 48 ) ; m . set ( i , m . get ( i ) - 2 ) ; front ++ ; } } } for ( var i = 0 ; i < l ; i ++ ) document . write ( largest [ i ] ) ; } var s = " " ; largestPalindrome ( s ) ;

Index/key variables: front, i
Accumulator variables: countodd, front, i
Iterator variables: i
Javascript program:
function swapCount ( s ) { let pos = [ ] ; for ( let i = 0 ; i < s . length ; ++ i ) if ( s [ i ] == ' ' ) pos . push ( i ) ; let count = 0 ; let p = 0 ; let sum = 0 ; let S = s . split ( ' ' ) ; for ( let i = 0 ; i < s . length ; ++ i ) { if ( S [ i ] == ' ' ) { ++ count ; ++ p ; } else if ( S [ i ] == ' ' ) -- count ; if ( count < 0 ) { sum += pos [ p ] - i ; let temp = S [ i ] ; S [ i ] = S [ pos [ p ] ] ; S [ pos [ p ] ] = temp ; ++ p ; count = 1 ; } } return sum ; } let s = " " ; document . write ( swapCount ( s ) + " " ) ; s = " " ; document . write ( swapCount ( s ) ) ;

Index/key variables: i, p
Accumulator variables: sum
Iterator variables: i
Javascript program:
function minimumCostOfBreaking ( X , Y , m , n ) { let res = 0 ; X . sort ( ) ; X . reverse ( ) ; Y . sort ( ) ; Y . reverse ( ) ; let hzntl = 1 , vert = 1 ; let i = 0 , j = 0 ; while ( i < m && j < n ) { if ( X [ i ] > Y [ j ] ) { res += X [ i ] * vert ; hzntl ++ ; i ++ ; } else { res += Y [ j ] * hzntl ; vert ++ ; j ++ ; } } let total = 0 ; while ( i < m ) total += X [ i ++ ] ; res += total * vert ; total = 0 ; while ( j < n ) total += Y [ j ++ ] ; res += total * hzntl ; return res ; } let m = 6 , n = 4 ; let X = [ 2 , 1 , 3 , 1 , 4 ] ; let Y = [ 4 , 1 , 2 ] ; document . write ( minimumCostOfBreaking ( X , Y , m - 1 , n - 1 ) ) ;

Index/key variables: i, j
Accumulator variables: hzntl, i, j, res, total, vert
Javascript program:
function getMin ( x , y , z ) { return Math . min ( Math . min ( x , y ) , z ) ; } function editDistance ( str1 , str2 , m , n ) { let dp = new Array ( m + 1 ) . fill ( new Array ( n + 1 ) ) ; for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) dp [ i ] [ j ] = j ; else if ( j == 0 ) dp [ i ] [ j ] = i ; else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ; else { dp [ i ] [ j ] = 1 + getMin ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ; } } } return dp [ m ] [ n ] ; } function minimumSteps ( S , N ) { let ans = Number . MAX_VALUE ; for ( let i = 1 ; i < N ; i ++ ) { let S1 = S . substring ( 0 , i ) ; let S2 = S . substring ( i ) ; let count = editDistance ( S1 , S2 , S1 . length , S2 . length ) ; ans = Math . min ( ans , count ) ; } document . write ( ans - 1 ) ; } let S = " " ; let N = S . length ; minimumSteps ( S , N ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minimumOperations ( N ) { let dp = new Array ( N + 1 ) ; let i ; for ( i = 0 ; i <= N ; i ++ ) { dp [ i ] = 1e9 ; } dp [ 2 ] = 0 ; for ( i = 2 ; i <= N ; i ++ ) { if ( dp [ i ] == 1e9 ) continue ; if ( i * 5 <= N ) { dp [ i * 5 ] = Math . min ( dp [ i * 5 ] , dp [ i ] + 1 ) ; } if ( i + 3 <= N ) { dp [ i + 3 ] = Math . min ( dp [ i + 3 ] , dp [ i ] + 1 ) ; } } if ( dp [ N ] == 1e9 ) return - 1 ; return dp [ N ] ; } let N = 25 ; document . write ( minimumOperations ( N ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function MaxProfit ( arr , n , transactionFee ) { let buy = - arr [ 0 ] ; let sell = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let temp = buy ; buy = Math . max ( buy , sell - arr [ i ] ) ; sell = Math . max ( sell , temp + arr [ i ] - transactionFee ) ; } return Math . max ( sell , buy ) ; } let arr = [ 6 , 1 , 7 , 2 , 8 , 4 ] ; let n = arr . length ; let transactionFee = 2 ; document . write ( MaxProfit ( arr , n , transactionFee ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var start = Array . from ( Array ( 3 ) , ( ) => Array ( 3 ) ) ; var ending = Array . from ( Array ( 3 ) , ( ) => Array ( 3 ) ) ; function calculateStart ( n , m ) { for ( var i = 1 ; i < m ; ++ i ) { start [ 0 ] [ i ] += start [ 0 ] [ i - 1 ] ; } for ( var i = 1 ; i < n ; ++ i ) { start [ i ] [ 0 ] += start [ i - 1 ] [ 0 ] ; } for ( var i = 1 ; i < n ; ++ i ) { for ( var j = 1 ; j < m ; ++ j ) { start [ i ] [ j ] += Math . max ( start [ i - 1 ] [ j ] , start [ i ] [ j - 1 ] ) ; } } } function calculateEnd ( n , m ) { for ( var i = n - 2 ; i >= 0 ; -- i ) { ending [ i ] [ m - 1 ] += ending [ i + 1 ] [ m - 1 ] ; } for ( var i = m - 2 ; i >= 0 ; -- i ) { ending [ n - 1 ] [ i ] += ending [ n - 1 ] [ i + 1 ] ; } for ( var i = n - 2 ; i >= 0 ; -- i ) { for ( var j = m - 2 ; j >= 0 ; -- j ) { ending [ i ] [ j ] += Math . max ( ending [ i + 1 ] [ j ] , ending [ i ] [ j + 1 ] ) ; } } } function maximumPathSum ( mat , n , m , q , coordinates ) { for ( var i = 0 ; i < n ; ++ i ) { for ( var j = 0 ; j < m ; ++ j ) { start [ i ] [ j ] = mat [ i ] [ j ] ; ending [ i ] [ j ] = mat [ i ] [ j ] ; } } calculateStart ( n , m ) ; calculateEnd ( n , m ) ; var ans = 0 ; for ( var i = 0 ; i < q ; ++ i ) { var X = coordinates [ i ] [ 0 ] - 1 ; var Y = coordinates [ i ] [ 1 ] - 1 ; ans = Math . max ( ans , start [ X ] [ Y ] + ending [ X ] [ Y ] - mat [ X ] [ Y ] ) ; } document . write ( ans ) ; } var mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; var N = 3 ; var M = 3 ; var Q = 2 ; var coordinates = [ [ 1 , 2 ] , [ 2 , 2 ] ] ; maximumPathSum ( mat , N , M , Q , coordinates ) ;

Index/key variables: X, Y, i, j
Iterator variables: i, j
Javascript program:
function MaxSubsetlength ( arr , A , B ) { var dp = Array . from ( Array ( A + 1 ) , ( ) => Array ( B + 1 ) . fill ( 0 ) ) ; arr . forEach ( str => { var zeros = [ ... str ] . filter ( x => x == ' ' ) . length ; var ones = [ ... str ] . filter ( x => x == ' ' ) . length ; for ( var i = A ; i >= zeros ; i -- ) for ( var j = B ; j >= ones ; j -- ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - zeros ] [ j - ones ] + 1 ) ; } ) ; return dp [ A ] [ B ] ; } var arr = [ " " , " " , " " , " " , " " ] ; var A = 5 , B = 3 ; document . write ( MaxSubsetlength ( arr , A , B ) ) ;

Index/key variables: A, B, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function numOfWays ( a , n , i , blue ) { if ( i == n ) return 1 ; let count = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( a [ i ] [ j ] == 1 && ! blue . has ( j ) ) { blue . add ( j ) ; count += numOfWays ( a , n , i + 1 , blue ) ; blue . delete ( j ) ; } } return count ; } let n = 3 ; let mat = [ [ 0 , 1 , 1 ] , [ 1 , 0 , 1 ] , [ 1 , 1 , 1 ] ] ; let mpp = new Set ( ) ; document . write ( numOfWays ( mat , n , 0 , mpp ) ) ;

Index/key variables: i, j
Accumulator variables: count, j
Iterator variables: j
Javascript program:
function minCost ( arr , n ) { if ( n < 3 ) { document . write ( arr [ 0 ] ) ; return ; } let dp = [ ] ; dp [ 0 ] = arr [ 0 ] ; dp [ 1 ] = dp [ 0 ] + arr [ 1 ] + arr [ 2 ] ; for ( let i = 2 ; i < n - 1 ; i ++ ) dp [ i ] = Math . min ( dp [ i - 2 ] + arr [ i ] , dp [ i - 1 ] + arr [ i ] + arr [ i + 1 ] ) ; dp [ n - 1 ] = Math . min ( dp [ n - 2 ] , dp [ n - 3 ] + arr [ n - 1 ] ) ; document . write ( dp [ n - 1 ] ) ; } let arr = [ 9 , 4 , 6 , 8 , 5 ] ; let N = arr . length ; minCost ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
M = 1000000007 ; function power ( X , Y ) { var res = 1 ; X = X % M ; if ( X == 0 ) return 0 ; while ( Y > 0 ) { if ( ( Y & 1 ) != 0 ) { res = ( res * X ) % M ; } Y = Y >> 1 ; X = ( X * X ) % M ; } return res ; } function findValue ( n ) { var X = 0 ; var pow_10 = 1 ; while ( n != 0 ) { if ( ( n & 1 ) != 0 ) { X += pow_10 ; } pow_10 *= 10 ; n /= 2 ; } X = ( X * 2 ) % M ; var res = power ( 2 , X ) ; return res ; } var n = 2 ; document . write ( findValue ( n ) ) ;

Accumulator variables: X, n, pow_10
Javascript program:
function findWays ( N ) { if ( N == 0 ) { return 1 ; } var cnt = 0 ; for ( var i = 1 ; i <= 6 ; i ++ ) { if ( N - i >= 0 ) { cnt = cnt + findWays ( N - i ) ; } } return cnt ; } var N = 4 ; document . write ( findWays ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 , j ) { if ( j == N ) { if ( sm1 == sm2 && sm2 == sm3 ) return 1 ; else return 0 ; } else { let l = checkEqualSumUtil ( arr , N , sm1 + arr [ j ] , sm2 , sm3 , j + 1 ) ; let m = checkEqualSumUtil ( arr , N , sm1 , sm2 + arr [ j ] , sm3 , j + 1 ) ; let r = checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 + arr [ j ] , j + 1 ) ; return Math . max ( Math . max ( l , m ) , r ) ; } } function checkEqualSum ( arr , N ) { let sum1 , sum2 , sum3 ; sum1 = sum2 = sum3 = 0 ; if ( checkEqualSumUtil ( arr , N , sum1 , sum2 , sum3 , 0 ) == 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ 17 , 34 , 59 , 23 , 17 , 67 , 57 , 2 , 18 , 59 , 1 ] ; let N = arr . length ; checkEqualSum ( arr , N ) ;

Index/key variables: j
Javascript program:
var dp = new Map ( ) ; function checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 , j ) { var s = ( sm1 . toString ( ) ) + " " + ( sm2 . toString ( ) ) + ( j . toString ( ) ) ; if ( j == N ) { if ( sm1 == sm2 && sm2 == sm3 ) return 1 ; else return 0 ; } if ( dp . has ( s ) ) return dp [ s ] ; else { var l = checkEqualSumUtil ( arr , N , sm1 + arr [ j ] , sm2 , sm3 , j + 1 ) ; var m = checkEqualSumUtil ( arr , N , sm1 , sm2 + arr [ j ] , sm3 , j + 1 ) ; var r = checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 + arr [ j ] , j + 1 ) ; return dp [ s ] = Math . max ( Math . max ( l , m ) , r ) ; } } function checkEqualSum ( arr , N ) { var sum1 , sum2 , sum3 ; sum1 = sum2 = sum3 = 0 ; if ( checkEqualSumUtil ( arr , N , sum1 , sum2 , sum3 , 0 ) == 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var arr = [ 17 , 34 , 59 , 23 , 17 , 67 , 57 , 2 , 18 , 59 , 1 ] ; var N = arr . length ; checkEqualSum ( arr , N ) ;

Index/key variables: j, s
Javascript program:
function precompute ( nextpos , arr , N ) { nextpos [ N - 1 ] = N ; for ( var i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == arr [ i + 1 ] ) nextpos [ i ] = nextpos [ i + 1 ] ; else nextpos [ i ] = i + 1 ; } } function findIndex ( query , arr , N , Q ) { var nextpos = Array ( N ) ; precompute ( nextpos , arr , N ) ; for ( var i = 0 ; i < Q ; i ++ ) { var l , r , x ; l = query [ i ] [ 0 ] ; r = query [ i ] [ 1 ] ; x = query [ i ] [ 2 ] ; var ans = - 1 ; if ( arr [ l ] != x ) ans = l ; else { var d = nextpos [ l ] ; if ( d <= r ) ans = d ; } document . write ( ans + " " ) ; } } var N , Q ; N = 6 ; Q = 3 ; var arr = [ 1 , 2 , 1 , 1 , 3 , 5 ] ; var query = [ [ 0 , 3 , 1 ] , [ 1 , 5 , 2 ] , [ 2 , 3 , 1 ] ] ; findIndex ( query , arr , N , Q ) ;

Index/key variables: i, l
Accumulator variables: i
Iterator variables: i
Javascript program:
let mod = 10000000007 ; function countWays ( s , t , k ) { let n = s . length ; let a = 0 , b = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let p = s . substr ( i , n - i ) + s . substr ( 0 , i ) ; if ( p == t ) a ++ ; else b ++ ; } let dp1 = Array . from ( { length : k + 1 } , ( _ , i ) => 0 ) ; let dp2 = Array . from ( { length : k + 1 } , ( _ , i ) => 0 ) ; if ( s == t ) { dp1 [ 0 ] = 1 ; dp2 [ 0 ] = 0 ; } else { dp1 [ 0 ] = 0 ; dp2 [ 0 ] = 1 ; } for ( let i = 1 ; i <= k ; i ++ ) { dp1 [ i ] = ( ( dp1 [ i - 1 ] * ( a - 1 ) ) % mod + ( dp2 [ i - 1 ] * a ) % mod ) % mod ; dp2 [ i ] = ( ( dp1 [ i - 1 ] * ( b ) ) % mod + ( dp2 [ i - 1 ] * ( b - 1 ) ) % mod ) % mod ; } return dp1 [ k ] ; } let S = " " , T = " " ; let K = 2 ; document . write ( countWays ( S , T , K ) ) ;

Index/key variables: i, k
Accumulator variables: a, b, i
Iterator variables: i
Javascript program:
function minOperation ( k ) { let dp = Array . from ( { length : k + 1 } , ( _ , i ) => 0 ) ; for ( let i = 1 ; i <= k ; i ++ ) { dp [ i ] = dp [ i - 1 ] + 1 ; if ( i % 2 == 0 ) { dp [ i ] = Math . min ( dp [ i ] , dp [ i / 2 ] + 1 ) ; } } return dp [ k ] ; } let K = 12 ; document . write ( minOperation ( K ) ) ;

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( p0 , p1 , a , pos , n ) { if ( pos == n ) { if ( p0 == p1 ) return p0 ; else return 0 ; } var ans = maxSum ( p0 , p1 , a , pos + 1 , n ) ; ans = Math . max ( ans , maxSum ( p0 + a [ pos ] , p1 , a , pos + 1 , n ) ) ; ans = Math . max ( ans , maxSum ( p0 , p1 + a [ pos ] , a , pos + 1 , n ) ) ; return ans ; } var n = 4 ; var a = [ 1 , 2 , 3 , 6 ] ; document . write ( maxSum ( 0 , 0 , a , 0 , n ) ) ;

Index/key variables: pos
Javascript program:
function maxSum ( a , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += a [ i ] ; var limit = 2 * sum + 1 ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( limit ) ) ; for ( var i = 0 ; i < n + 1 ; i ++ ) { for ( var j = 0 ; j < limit ; j ++ ) dp [ i ] [ j ] = - 1000000000 ; } dp [ 0 ] [ sum ] = 0 ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 0 ; j < limit ; j ++ ) { if ( ( j - a [ i - 1 ] ) >= 0 && dp [ i - 1 ] [ j - a [ i - 1 ] ] != - 1000000000 ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - a [ i - 1 ] ] + a [ i - 1 ] ) ; if ( ( j + a [ i - 1 ] ) < limit && dp [ i - 1 ] [ j + a [ i - 1 ] ] != - 1000000000 ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j + a [ i - 1 ] ] ) ; if ( dp [ i - 1 ] [ j ] != - 1000000000 ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ sum ] ; } var n = 4 ; var a = [ 1 , 2 , 3 , 6 ] ; document . write ( maxSum ( a , n ) ) ;

Index/key variables: i, j, n, sum
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
fib = Array ( 100005 ) . fill ( 0 ) ; function computeFibonacci ( ) { fib [ 0 ] = 1 ; fib [ 1 ] = 1 ; for ( i = 2 ; i < 100005 ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } function countString ( str ) { var ans = 1 ; var cnt = 1 ; for ( i = 1 ; i < str . length ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( i - 1 ) ) { cnt ++ ; } else { ans = ans * fib [ cnt ] ; cnt = 1 ; } } ans = ans * fib [ cnt ] ; return ans ; } var str = " " ; computeFibonacci ( ) ; document . write ( countString ( str ) ) ;

Index/key variables: cnt, i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
var MAX = 100001 ; function printGolombSequence ( N ) { var arr = Array ( MAX ) ; var cnt = 0 ; arr [ 0 ] = 0 ; arr [ 1 ] = 1 ; var M = new Map ( ) ; M . set ( 2 , 2 ) ; for ( var i = 2 ; i <= N ; i ++ ) { if ( cnt == 0 ) { arr [ i ] = 1 + arr [ i - 1 ] ; cnt = M . get ( arr [ i ] ) ; cnt -- ; } else { arr [ i ] = arr [ i - 1 ] ; cnt -- ; } M . set ( i , arr [ i ] ) ; } for ( var i = 1 ; i <= N ; i ++ ) { document . write ( arr [ i ] + ' ' ) ; } } var N = 11 ; printGolombSequence ( N ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function number_of_ways ( n ) { let includes_3 = new Uint8Array ( n + 1 ) ; let not_includes_3 = new Uint8Array ( n + 1 ) ; includes_3 [ 3 ] = 1 ; not_includes_3 [ 1 ] = 1 ; not_includes_3 [ 2 ] = 2 ; not_includes_3 [ 3 ] = 3 ; for ( let i = 4 ; i <= n ; i ++ ) { includes_3 [ i ] = includes_3 [ i - 1 ] + includes_3 [ i - 2 ] + not_includes_3 [ i - 3 ] ; not_includes_3 [ i ] = not_includes_3 [ i - 1 ] + not_includes_3 [ i - 2 ] ; } return includes_3 [ n ] ; } let n = 7 ; document . write ( number_of_ways ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
const MAX = 100000 ; var divisors = new Array ( MAX ) . fill ( 0 ) ; function generateDivisors ( n ) { for ( var i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { divisors [ i ] ++ ; } else { divisors [ i ] ++ ; divisors [ n / i ] ++ ; } } } } function findMaxMultiples ( arr , n ) { var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { ans = Math . max ( divisors [ arr [ i ] ] , ans ) ; generateDivisors ( arr [ i ] ) ; } return ans ; } var arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] ; var n = arr . length ; document . write ( findMaxMultiples ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var n = 3 ; var maxV = 20 ; var dp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { dp [ i ] = new Array ( n ) ; for ( var j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = new Array ( maxV ) ; } } var v = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { v [ i ] = new Array ( n ) ; for ( var j = 0 ; j < n ; j ++ ) { v [ i ] [ j ] = new Array ( maxV ) ; } } function countWays ( i , j , x , arr ) { if ( i == n j == n ) return 0 ; x = ( x & arr [ i ] [ j ] ) ; if ( x == 0 ) return 0 ; if ( i == n - 1 && j == n - 1 ) return 1 ; if ( v [ i ] [ j ] [ x ] ) return dp [ i ] [ j ] [ x ] ; v [ i ] [ j ] [ x ] = 1 ; dp [ i ] [ j ] [ x ] = countWays ( i + 1 , j , x , arr ) + countWays ( i , j + 1 , x , arr ) ; return dp [ i ] [ j ] [ x ] ; } var arr = [ [ 1 , 2 , 1 ] , [ 1 , 1 , 0 ] , [ 2 , 1 , 1 ] ] ; document . write ( countWays ( 0 , 0 , arr [ 0 ] [ 0 ] , arr ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var N = 3 ; function FindMaximumSum ( ind , kon , a , b , c , n , dp ) { if ( ind == n ) return 0 ; if ( dp [ ind ] [ kon ] != - 1 ) return dp [ ind ] [ kon ] ; var ans = - 1000000005 ; if ( kon == 0 ) { ans = Math . max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 1 ) { ans = Math . max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 2 ) { ans = Math . max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; } return dp [ ind ] [ kon ] = ans ; } var a = [ 6 , 8 , 2 , 7 , 4 , 2 , 7 ] ; var b = [ 7 , 8 , 5 , 8 , 6 , 3 , 5 ] ; var c = [ 8 , 3 , 2 , 6 , 8 , 4 , 1 ] ; var n = a . length ; var dp = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( - 1 ) ) ; var x = FindMaximumSum ( 0 , 0 , a , b , c , n , dp ) ; var y = FindMaximumSum ( 0 , 1 , a , b , c , n , dp ) ; var z = FindMaximumSum ( 0 , 2 , a , b , c , n , dp ) ; document . write ( Math . max ( x , Math . max ( y , z ) ) ) ;

Index/key variables: ind, kon