dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function mElementsWithMaxSum ( matrix , M , block , dp ) { if ( block == matrix . length ) return 0 ; if ( dp [ block ] [ M ] != - 1 ) return dp [ block ] [ M ] ; var ans = mElementsWithMaxSum ( matrix , M , block + 1 , dp ) ; for ( var i = 0 ; i < matrix [ block ] . length ; i ++ ) { for ( var j = i ; j < matrix [ block ] . length ; j ++ ) { if ( j - i + 1 <= M ) { ans = Math . max ( ans , matrix [ block ] [ j ] - ( ( i - 1 ) >= 0 ? matrix [ block ] [ i - 1 ] : 0 ) + mElementsWithMaxSum ( matrix , M - j + i - 1 , block + 1 , dp ) ) ; } } } return dp [ block ] [ M ] = ans ; } function preComputing ( matrix , N ) { for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < matrix [ i ] . length ; j ++ ) { matrix [ i ] [ j ] = ( j > 0 ? matrix [ i ] [ j - 1 ] : 0 ) + matrix [ i ] [ j ] ; } } } function mElementsWithMaxSumUtil ( matrix , M , N ) { preComputing ( matrix , N ) ; var dp = Array . from ( Array ( N + 5 ) , ( ) => Array ( M + 5 ) . fill ( - 1 ) ) ; var sum = mElementsWithMaxSum ( matrix , M , 0 , dp ) ; document . write ( sum ) ; } var N = 3 ; var M = 4 ; var matrix = [ [ 2 , 3 , 5 ] , [ - 1 , 7 ] , [ 8 , 10 ] ] ; mElementsWithMaxSumUtil ( matrix , M , N ) ;

Index/key variables: M, block, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function lastRemaining ( n , dp ) { if ( dp . hasOwnProperty ( n ) ) return dp [ n ] ; if ( n === 1 ) return 1 ; else dp [ n ] = 2 * ( 1 + parseInt ( n / 2 ) - lastRemaining ( parseInt ( n / 2 ) , dp ) ) ; return dp [ n ] ; } var N = 5 ; var dp = { } ; document . write ( lastRemaining ( N , dp ) ) ;

Index/key variables: n
Javascript program:
let dp = new Array ( 1005 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } function maximumSumUtil ( a , index , count , n ) { if ( index > n count > n + 1 ) { return 0 ; } if ( dp [ index ] [ count ] != - 1 ) return dp [ index ] [ count ] ; let ans1 = maximumSumUtil ( a , index + 1 , count + 1 , n ) + a [ index ] * count ; let ans2 = maximumSumUtil ( a , index + 1 , count , n ) ; return ( dp [ index ] [ count ] = Math . max ( ans1 , ans2 ) ) ; } function maximumSum ( arr , N ) { for ( let i = 0 ; i < 1005 ; i ++ ) { for ( let j = 0 ; j < 1005 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( maximumSumUtil ( arr , 0 , 1 , N - 1 ) ) ; } let arr = [ - 1 , 2 , - 10 , 4 , - 20 ] ; let N = arr . length ; maximumSum ( arr , N ) ;

Index/key variables: count, i, index, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var n , t ; function FindNoOfFullVessels ( n , t ) { var Matrix = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( 0 ) ) ; Matrix [ 0 ] [ 0 ] = t * 1.0 ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { var exceededwater = Matrix [ i ] [ j ] - 1 ; if ( exceededwater < 0 ) continue ; ans ++ ; if ( i + 1 < n ) Matrix [ i + 1 ] [ j ] += ( exceededwater / 2 ) ; if ( i + 1 < n && j + 1 < n ) Matrix [ i + 1 ] [ j + 1 ] += ( exceededwater / 2 ) ; } } return ans ; } var N = 3 ; var T = 4 ; document . write ( FindNoOfFullVessels ( N , T ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function swap ( arr , x , y ) { let temp = arr [ x ] ; arr [ x ] = arr [ y ] ; arr [ y ] = temp } function sortInWave ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n - 1 ; i += 2 ) swap ( arr , i , i + 1 ) ; } let arr = [ 10 , 90 , 49 , 2 , 1 , 5 , 23 ] ; let n = arr . length ; sortInWave ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, x, y
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaxTimes ( S ) { var arr = Array ( 26 ) . fill ( 0 ) ; var dp = Array . from ( Array ( 26 ) , ( ) => Array ( 26 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < S . length ; i ++ ) { var now = S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; for ( var j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ now ] += arr [ j ] ; } arr [ now ] ++ ; } var ans = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) ans = Math . max ( ans , arr [ i ] ) ; for ( var i = 0 ; i < 26 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) { ans = Math . max ( ans , dp [ i ] [ j ] ) ; } } return ans ; } var S = " " ; document . write ( findMaxTimes ( S ) ) ;

Index/key variables: i, j, now
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function swap ( arr , a , b ) { let temp = arr [ a ] ; arr [ a ] = arr [ b ] ; arr [ b ] = temp ; } function sortInWave ( arr , n ) { for ( let i = 0 ; i < n ; i += 2 ) { if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ; if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ; } } let arr = [ 10 , 90 , 49 , 2 , 1 , 5 , 23 ] ; let n = arr . length ; sortInWave ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function count_unique_sum ( n ) { let i ; let ans = 1 ; let ar = new Array ( n + 1 ) ; let fsum = new Array ( n + 1 ) ; let rsum = new Array ( n + 1 ) ; fsum . fill ( 0 ) ; rsum . fill ( 0 ) ; for ( i = 0 ; i <= n ; i ++ ) { ar [ i ] = i ; } fsum [ 0 ] = ar [ 0 ] ; rsum [ n ] = ar [ n ] ; for ( i = 1 ; i <= n ; i ++ ) { fsum [ i ] = ar [ i ] + fsum [ i - 1 ] ; } for ( i = n - 1 ; i >= 0 ; i -- ) { rsum [ i ] = ar [ i ] + rsum [ i + 1 ] ; } for ( let k = 2 ; k <= n ; k ++ ) { ans += 1 + rsum [ n + 1 - k ] - fsum [ k - 1 ] ; } return ans ; } let N = 4 ; document . write ( count_unique_sum ( N ) ) ;

Index/key variables: i, n
Accumulator variables: ans, i, k
Iterator variables: i, k
Javascript program:
function moveToEnd ( mPlusN , size ) { let i = 0 ; let j = size - 1 ; for ( i = size - 1 ; i >= 0 ; i -- ) { if ( mPlusN [ i ] != - 1 ) { mPlusN [ j ] = mPlusN [ i ] ; j -- ; } } } function merge ( mPlusN , N , m , n ) { let i = n ; let j = 0 ; let k = 0 ; while ( k < ( m + n ) ) { if ( ( i < ( m + n ) && mPlusN [ i ] <= N [ j ] ) || ( j == n ) ) { mPlusN [ k ] = mPlusN [ i ] ; k ++ ; i ++ ; } else { mPlusN [ k ] = N [ j ] ; k ++ ; j ++ ; } } } function printArray ( arr , size ) { let i = 0 ; for ( i = 0 ; i < size ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let mPlusN = [ 2 , 8 , - 1 , - 1 , - 1 , 13 , - 1 , 15 , 20 ] ; let N = [ 5 , 7 , 9 , 25 ] let n = N . length ; let m = mPlusN . length - n ; moveToEnd ( mPlusN , m + n ) ; merge ( mPlusN , N , m , n ) ; printArray ( mPlusN , m + n ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function max ( num1 , num2 ) { return ( num1 > num2 ) ? num1 : num2 ; } function min ( num1 , num2 ) { return ( num1 > num2 ) ? num2 : num1 ; } function getCount ( n , k ) { if ( n == 1 ) return 10 ; var dp = Array ( 11 ) . fill ( 0 ) ; var next = Array ( 11 ) . fill ( 0 ) ; for ( var i = 1 ; i <= 9 ; i ++ ) dp [ i ] = 1 ; for ( var i = 2 ; i <= n ; i ++ ) { for ( var j = 0 ; j <= 9 ; j ++ ) { var l = Math . max ( 0 , ( j - k ) ) ; var r = Math . min ( 9 , ( j + k ) ) ; next [ l ] += dp [ j ] ; next [ r + 1 ] -= dp [ j ] ; } for ( var j = 1 ; j <= 9 ; j ++ ) next [ j ] += next [ j - 1 ] ; for ( var j = 0 ; j < 10 ; j ++ ) { dp [ j ] = next [ j ] ; next [ j ] = 0 ; } } var count = 0 ; for ( var i = 0 ; i <= 9 ; i ++ ) count += dp [ i ] ; return count ; } var n = 2 , k = 1 ; document . write ( getCount ( n , k ) ) ;

Index/key variables: i, j, l
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function sortedAfterSwap ( A , B , n ) { let i , j ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] ) { j = i ; while ( B [ j ] ) { j ++ ; } A . sort ( ) ; i = j ; } } for ( i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) { return false ; } } return true ; } let A = [ 1 , 2 , 5 , 3 , 4 , 6 ] ; let B = [ false , true , true , true , false ] ; let n = A . length ; if ( sortedAfterSwap ( A , B , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function sortedAfterSwap ( A , B , n ) { let t = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] != 0 ) { if ( A [ i ] != i + 1 ) t = A [ i ] ; A [ i ] = A [ i + 1 ] ; A [ i + 1 ] = t ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) return 0 ; } return 1 ; } let A = [ 1 , 2 , 5 , 3 , 4 , 6 ] ; let B = [ 0 , 1 , 1 , 1 , 0 ] ; let n = A . length ; if ( sortedAfterSwap ( A , B , n ) == 0 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function segregate0and1 ( arr , n ) { let type0 = 0 ; let type1 = n - 1 ; while ( type0 < type1 ) { if ( arr [ type0 ] == 1 ) { arr [ type0 ] = arr [ type0 ] + arr [ type1 ] ; arr [ type1 ] = arr [ type0 ] - arr [ type1 ] ; arr [ type0 ] = arr [ type0 ] - arr [ type1 ] ; type1 -- ; } else { type0 ++ ; } } } let arr = [ 1 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 1 ] ; segregate0and1 ( arr , arr . length ) ; for ( let i = 0 ; i < arr . length ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, type0, type1
Accumulator variables: i, type0, type1
Iterator variables: i
Javascript program:
function getInvCount ( arr ) { let inv_count = 0 ; for ( let i = 0 ; i < arr . length - 1 ; i ++ ) { for ( let j = i + 1 ; j < arr . length ; j ++ ) { if ( arr [ i ] > arr [ j ] ) inv_count ++ ; } } return inv_count ; } arr = [ 1 , 20 , 6 , 4 , 5 ] ; document . write ( " " + getInvCount ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: i, inv_count, j
Iterator variables: i, j
Javascript program:
function findResultUtil ( arr , L , R ) { var result = 0 ; var flag = false ; for ( var i = L ; i <= R ; i ++ ) { if ( flag == false ) { result = result + arr [ i ] ; flag = true ; } else { result = result - arr [ i ] ; flag = false ; } } return result ; } function findResult ( arr , n , q , m ) { for ( var i = 0 ; i < m ; i ++ ) { document . write ( findResultUtil ( arr , q [ i ] [ 0 ] , q [ i ] [ 1 ] ) + " " ) ; } } var arr = [ 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 ] ; var n = arr . length ; var q = [ [ 2 , 5 ] , [ 6 , 8 ] , [ 1 , 7 ] , [ 4 , 8 ] , [ 0 , 5 ] ] ; var m = q . length ; findResult ( arr , n , q , m ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function minAbsSumPair ( arr , arr_size ) { var inv_count = 0 ; var l , r , min_sum , sum , min_l , min_r ; if ( arr_size < 2 ) { document . write ( " " ) ; return ; } min_l = 0 ; min_r = 1 ; min_sum = arr [ 0 ] + arr [ 1 ] ; for ( l = 0 ; l < arr_size - 1 ; l ++ ) { for ( r = l + 1 ; r < arr_size ; r ++ ) { sum = arr [ l ] + arr [ r ] ; if ( Math . abs ( min_sum ) > Math . abs ( sum ) ) { min_sum = sum ; min_l = l ; min_r = r ; } } } document . write ( " " + arr [ min_l ] + " " + arr [ min_r ] ) ; } arr = new Array ( 1 , 60 , - 10 , 70 , - 80 , 85 ) ; minAbsSumPair ( arr , 6 ) ;

Index/key variables: l, min_l, min_r, r
Accumulator variables: l, r
Iterator variables: l, r
Javascript program:
function maximumSum ( S , M , N , stacks ) { var dp = Array . from ( Array ( S + 1 ) , ( ) => Array ( N + 1 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < S ; i ++ ) { for ( var j = 0 ; j <= N ; j ++ ) { for ( var k = 0 ; k <= Math . min ( j , M ) ; k ++ ) { dp [ i + 1 ] [ j ] = Math . max ( dp [ i + 1 ] [ j ] , stacks [ i ] [ k ] + dp [ i ] [ j - k ] ) ; } } } var result = - 1000000000 ; for ( var i = 0 ; i <= N ; i ++ ) { result = Math . max ( result , dp [ S ] [ i ] ) ; } return result ; } var S = 2 ; var M = 4 ; var stacks = [ [ 2 , 6 , 4 , 5 ] , [ 1 , 6 , 15 , 10 ] ] ; var N = 3 ; document . write ( maximumSum ( S , M , N , stacks ) ) ;

Index/key variables: S, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findMinSum ( arr , n ) { for ( let i = 1 ; i < n ; i ++ ) { if ( ! ( Math . abs ( arr [ i - 1 ] ) < Math . abs ( arr [ i ] ) ) ) { let temp = arr [ i - 1 ] ; arr [ i - 1 ] = arr [ i ] ; arr [ i ] = temp ; } } let min = Number . MAX_VALUE ; let x = 0 , y = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( Math . abs ( arr [ i - 1 ] + arr [ i ] ) <= min ) { min = Math . abs ( arr [ i - 1 ] + arr [ i ] ) ; x = i - 1 ; y = i ; } } document . write ( " " + " " + arr [ x ] + " " + arr [ y ] ) ; } let arr = [ 1 , 60 , - 10 , 70 , - 80 , 85 ] ; let n = arr . length ; findMinSum ( arr , n ) ;

Index/key variables: i, x, y
Accumulator variables: i
Iterator variables: i
Javascript program:
function dicesSum ( n ) { let dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < dp . length ; i ++ ) { for ( var j = 0 ; j < 6 * n + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= 6 ; i ++ ) dp [ 1 ] [ i ] = 1 / 6.0 ; for ( let i = 2 ; i <= n ; i ++ ) for ( let j = i - 1 ; j <= 6 * ( i - 1 ) ; j ++ ) for ( let k = 1 ; k <= 6 ; k ++ ) { dp [ i ] [ j + k ] += ( dp [ i - 1 ] [ j ] * dp [ 1 ] [ k ] ) ; } for ( let i = n ; i <= 6 * n ; i ++ ) { document . write ( i + " " + Math . round ( dp [ n ] [ i ] * 1000.0 ) / 1000.0 + " " ) ; } } let n = 2 ; dicesSum ( n ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let ans ; let flag = 1 ; function dfs ( adj , order , bridge_detect , mark , v , l ) { mark [ v ] = true ; order [ v ] = order [ l ] + 1 ; bridge_detect [ v ] = order [ v ] ; for ( let i = 0 ; i < adj [ v ] . length ; i ++ ) { let u = adj [ v ] [ i ] ; if ( u == l ) { continue ; } if ( order [ v ] < order [ u ] ) { continue ; } if ( mark [ u ] ) { bridge_detect [ v ] = Math . min ( order [ u ] , bridge_detect [ v ] ) ; } else { dfs ( adj , order , bridge_detect , mark , u , v ) ; } bridge_detect [ v ] = Math . min ( bridge_detect [ u ] , bridge_detect [ v ] ) ; ans . push ( [ v , u ] ) ; } if ( bridge_detect [ v ] == order [ v ] && l != 0 ) { flag = 0 ; } return flag ; } function convert ( adj , n ) { let order = new Array ( n ) ; let bridge_detect = new Array ( n ) ; let mark = new Array ( n ) ; let flag = dfs ( adj , order , bridge_detect , mark , 1 , 0 ) ; if ( flag == 0 ) { document . write ( " " ) ; } else { for ( let it = 0 ; it < ans . length - 1 ; it ++ ) { document . write ( ans [ it ] [ 0 ] + " " + ans [ it ] [ 1 ] + " " ) ; } } } function createGraph ( Edges , adj , M ) { for ( let i = 0 ; i < M ; i ++ ) { let u = Edges [ i ] [ 0 ] ; let v = Edges [ i ] [ 1 ] ; adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } } let N = 5 , M = 6 ; let Edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 2 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 3 , 4 ] ] ; let adj = [ ] ; ans = [ ] ; for ( let i = 0 ; i < N ; i ++ ) adj . push ( [ ] ) ; createGraph ( Edges , adj , M ) ; convert ( adj , N ) ;

Index/key variables: i, it, l, u, v
Accumulator variables: i, it
Iterator variables: i, it
Javascript program:
function increasing ( a , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] >= a [ i + 1 ] ) return false ; return true ; } function decreasing ( arr , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] < arr [ i + 1 ] ) return false ; return true ; } function shortestUnsorted ( a , n ) { if ( increasing ( a , n ) == true || decreasing ( a , n ) == true ) return 0 ; else return 3 ; } let ar = [ 7 , 9 , 10 , 8 , 11 ] ; let n = ar . length ; document . write ( shortestUnsorted ( ar , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function swap ( arr , i , j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } function indexOf ( arr , ele ) { for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == ele ) { return i ; } } return - 1 ; } function minSwaps ( arr , N ) { let ans = 0 ; let temp = [ ... arr ] ; temp . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != temp [ i ] ) { ans ++ ; swap ( arr , i , indexOf ( arr , temp [ i ] ) ) ; } } return ans ; } let a = [ 101 , 758 , 315 , 730 , 472 , 619 , 460 , 479 ] ; let n = a . length ; document . write ( minSwaps ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var kPowKform = new Set ( ) ; var dp = Array ( 100005 ) ; function func ( n ) { if ( n <= 0 ) return 0 ; if ( kPowKform . has ( n ) ) return 1 ; if ( dp [ n ] != - 1 ) return dp [ n ] ; var answer = 0 ; var x = n ; while ( x > 0 ) { var d = x % 10 ; if ( d != 0 ) { if ( func ( n - d * d ) ) { answer = 1 ; break ; } } x /= 10 ; } return dp [ n ] = answer ; } function canBeConverted ( n ) { dp = Array ( 100005 ) . fill ( - 1 ) ; if ( func ( n ) ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 13 ; for ( var i = 1 ; i <= 8 ; i ++ ) { var val = 1 ; for ( var j = 1 ; j <= i ; j ++ ) val *= i ; kPowKform . add ( val ) ; } canBeConverted ( N ) ;

Index/key variables: n
Accumulator variables: i, j, val, x
Iterator variables: i, j
Javascript program:
function isPowerOfTwo ( N ) { let number = Math . log ( N ) / Math . log ( 2 ) ; let checker = Math . floor ( number ) ; return number - checker == 0 ; } function isSeriesFour ( N , digits ) { let upperBound = Math . floor ( Math . pow ( 2 , digits ) + Math . pow ( 2 , digits - 1 ) - 1 ) ; let lowerBound = Math . floor ( Math . pow ( 2 , digits ) - 1 ) ; return ( N >= lowerBound ) && ( N < upperBound ) ; } function getPureNumber ( N ) { let numbers = new Array ( N + 1 ) ; numbers [ 0 ] = " " ; let blocks = 0 ; let displacement = 0 ; for ( let i = 1 ; i < N + 1 ; i ++ ) { if ( isPowerOfTwo ( i + 1 ) ) { blocks = blocks + 1 ; } if ( isSeriesFour ( i , blocks ) ) { displacement = Math . floor ( Math . pow ( 2 , blocks - 1 ) ) ; numbers [ i ] = " " + numbers [ i - displacement ] + " " ; } else { displacement = Math . floor ( Math . pow ( 2 , blocks ) ) ; numbers [ i ] = " " + numbers [ i - displacement ] + " " ; } } return numbers [ N ] ; } let N = 5 ; let pure = getPureNumber ( N ) ; document . write ( pure + " " ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 15 ) , ( ) => Array ( 2 ) . fill ( - 1 ) ) ; function calculate ( pos , tight , D , sz , num ) { if ( pos == num . length ) return 1 ; if ( dp [ pos ] [ tight ] != - 1 ) return dp [ pos ] [ tight ] ; var val = 0 ; if ( tight == 0 ) { for ( var i = 0 ; i < sz ; i ++ ) { if ( D [ i ] < ( num [ pos ] - ' ' ) ) { val += calculate ( pos + 1 , 1 , D , sz , num ) ; } else if ( D [ i ] == num [ pos ] - ' ' ) val += calculate ( pos + 1 , tight , D , sz , num ) ; } } else { for ( var i = 0 ; i < sz ; i ++ ) { val += calculate ( pos + 1 , tight , D , sz , num ) ; } } return dp [ pos ] [ tight ] = val ; } function countNumbers ( D , N , sz ) { var num = ( N . toString ( ) ) ; var len = num . length ; var ans = calculate ( 0 , 0 , D , sz , num ) ; for ( var i = 1 ; i < len ; i ++ ) ans += calculate ( i , 1 , D , sz , num ) ; return ans ; } var sz = 3 ; var D = [ 1 , 4 , 9 ] ; var N = 10 ; document . write ( countNumbers ( D , N , sz ) ) ;

Index/key variables: i, pos, tight
Accumulator variables: ans, i, val
Iterator variables: i
Javascript program:
let dp = new Array ( 1000 + 1 ) ; function find_max ( i , sum , v , k ) { if ( i == v . length ) return 0 ; if ( dp [ i ] [ sum ] != - 1 ) return dp [ i ] [ sum ] ; let ans = 0 ; if ( ( sum + find_max ( i + 1 , sum , v , k ) ) % k == 0 ) ans = find_max ( i + 1 , sum , v , k ) ; if ( ( sum + v [ i ] + find_max ( i + 1 , ( sum + v [ i ] ) % k , v , k ) ) % k == 0 ) ans = Math . max ( ans , v [ i ] + find_max ( i + 1 , ( sum + v [ i ] ) % k , v , k ) ) ; return dp [ i ] [ sum ] = ans ; } let arr = [ 43 , 1 , 17 , 26 , 15 ] ; let k = 16 ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < dp . length ; i ++ ) { for ( var j = 0 ; j < dp . length ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( find_max ( 0 , 0 , arr , k ) ) ;

Index/key variables: i, j, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printUnion ( arr1 , arr2 , m , n ) { if ( m > n ) { let tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; let temp = m ; m = n ; n = temp ; } arr1 . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < m ; i ++ ) document . write ( arr1 [ i ] + " " ) ; for ( let i = 0 ; i < n ; i ++ ) if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) == - 1 ) document . write ( arr2 [ i ] + " " ) ; } function printIntersection ( arr1 , arr2 , m , n ) { if ( m > n ) { let tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; let temp = m ; m = n ; n = temp ; } arr1 . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n ; i ++ ) if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) != - 1 ) document . write ( arr2 [ i ] + " " ) ; } function binarySearch ( arr , l , r , x ) { if ( r >= l ) { let mid = l + Math . floor ( ( r - l ) / 2 ) ; if ( arr [ mid ] == x ) return mid ; if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ; return binarySearch ( arr , mid + 1 , r , x ) ; } return - 1 ; } let arr1 = [ 7 , 1 , 5 , 2 , 3 , 6 ] ; let arr2 = [ 3 , 8 , 6 , 20 , 7 ] ; let m = arr1 . length ; let n = arr2 . length ; document . write ( " " ) ; printUnion ( arr1 , arr2 , m , n ) ; document . write ( " " ) ; printIntersection ( arr1 , arr2 , m , n ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function intersection ( a , b , n , m ) { let i = 0 , j = 0 ; while ( i < n && j < m ) { if ( a [ i ] > b [ j ] ) { j ++ ; } else if ( b [ j ] > a [ i ] ) { i ++ ; } else { document . write ( a [ i ] + " " ) ; i ++ ; j ++ ; } } } let a = [ 1 , 3 , 2 , 3 , 4 , 5 , 5 , 6 ] ; let b = [ 3 , 3 , 5 ] let n = a . length ; let m = b . length ; a . sort ( ) ; b . sort ( ) ; intersection ( a , b , n , m ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
class Node { constructor ( ) { this . left = null ; this . data = 0 ; this . right = null ; } } ; var res = 0 ; function newNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; newNode . left = newNode . right = null ; return ( newNode ) ; } function countUntil ( root ) { if ( root == null ) return 0 ; var l = countUntil ( root . left ) ; var r = countUntil ( root . right ) ; var maxCount ; if ( root . data == 1 ) maxCount = l + r + 1 ; else maxCount = l + r ; res = Math . max ( res , maxCount ) ; if ( root . data == 1 ) return Math . max ( l , r ) + 1 ; else return Math . max ( l , r ) ; } function findMaxCount ( root ) { res = - 1000000000 ; countUntil ( root ) ; return res ; } var root = newNode ( 1 ) ; root . left = newNode ( 0 ) ; root . right = newNode ( 1 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 1 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 0 ) ; document . write ( findMaxCount ( root ) ) ;

Class/struct names: Node
Javascript program:
function findCount ( N ) { let list = [ ] ; let sum = 0 ; let i ; for ( i = 0 ; i < 20 ; i ++ ) { sum += parseInt ( Math . pow ( 2 , i ) , 10 ) ; list . push ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( list [ i ] >= N ) return ( i + 1 ) ; } return 0 ; } let N = 10 ; document . write ( findCount ( N ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function sort012 ( a , arr_size ) { let lo = 0 ; let hi = arr_size - 1 ; let mid = 0 ; let temp = 0 ; while ( mid <= hi ) { if ( a [ mid ] == 0 ) { temp = a [ lo ] ; a [ lo ] = a [ mid ] ; a [ mid ] = temp ; lo ++ ; mid ++ ; } else if ( a [ mid ] == 1 ) { mid ++ ; } else { temp = a [ mid ] ; a [ mid ] = a [ hi ] ; a [ hi ] = temp ; hi -- ; } } } function printArray ( arr , arr_size ) { let i ; for ( i = 0 ; i < arr_size ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let arr = [ 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 ] ; let arr_size = arr . length ; sort012 ( arr , arr_size ) ; document . write ( " " ) printArray ( arr , arr_size ) ;

Index/key variables: hi, i, lo, mid
Accumulator variables: hi, i, lo, mid
Iterator variables: i