dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function bellNumber ( n ) { let bell = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { bell [ i ] = new Array ( n + 1 ) ; } bell [ 0 ] [ 0 ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ] ; for ( let j = 1 ; j <= i ; j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ] ; } return bell [ n ] [ 0 ] ; } for ( let n = 0 ; n <= 5 ; n ++ ) document . write ( " " + n + " " + bellNumber ( n ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, n
Iterator variables: i, j, n
Javascript program:
function printCountDP ( dist ) { let count = new Array ( dist + 1 ) ; count [ 0 ] = 1 ; if ( dist >= 1 ) count [ 1 ] = 1 ; if ( dist >= 2 ) count [ 2 ] = 2 ; for ( let i = 3 ; i <= dist ; i ++ ) count [ i ] = count [ i - 1 ] + count [ i - 2 ] + count [ i - 3 ] ; return count [ dist ] ; } let dist = 4 ; document . write ( printCountDP ( dist ) ) ;

Index/key variables: dist, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSeq ( n ) { let nCr = 1 , res = 1 ; for ( let r = 1 ; r <= n ; r ++ ) { nCr = ( nCr * ( n + 1 - r ) ) / r ; res += nCr * nCr ; } return res ; } let n = 2 ; document . write ( " " ) ; document . write ( countSeq ( n ) ) ;

Accumulator variables: r, res
Iterator variables: r
Javascript program:
function minq ( a , b ) { return ( a < b ) ? a : b ; } function min ( arr , l , h ) { var mn = arr [ l ] ; for ( i = l + 1 ; i <= h ; i ++ ) { if ( mn > arr [ i ] ) { mn = arr [ i ] ; } } return parseInt ( mn ) ; } function max ( arr , l , h ) { var mx = arr [ l ] ; for ( i = l + 1 ; i <= h ; i ++ ) { if ( mx < arr [ i ] ) { mx = arr [ i ] ; } } return parseInt ( mx ) ; } function minRemovalsDP ( arr , n ) { var table = Array ( n ) ; var gap , i , j , mn , mx ; for ( i = 0 ; i < n ; i ++ ) table [ i ] = Array ( n ) . fill ( 0 ) ; for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { mn = min ( arr , i , j ) ; mx = max ( arr , i , j ) ; table [ i ] [ j ] = parseInt ( ( 2 * mn > mx ) ? 0 : minq ( table [ i ] [ j - 1 ] + 1 , table [ i + 1 ] [ j ] + 1 ) ) ; } } return table [ 0 ] [ n - 1 ] ; } var arr = [ 20 , 4 , 1 , 3 ] ; var n = arr . length ; document . write ( minRemovalsDP ( arr , n ) ) ;

Index/key variables: i, j, l
Accumulator variables: i
Iterator variables: gap, i
Javascript program:
function numberOfPaths ( m , n ) { var path = 1 ; for ( i = n ; i < ( m + n - 1 ) ; i ++ ) { path *= i ; path = parseInt ( path / ( i - n + 1 ) ) ; } return path ; } document . write ( numberOfPaths ( 3 , 3 ) ) ;

Accumulator variables: i, path
Iterator variables: i
Javascript program:
function lenghtOfLongestAP ( set , n ) { if ( n <= 2 ) return n ; let L = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { L [ i ] = new Array ( n ) ; } let llap = 2 ; for ( let i = 0 ; i < n ; i ++ ) { L [ i ] [ n - 1 ] = 2 ; } for ( let j = n - 2 ; j >= 1 ; j -- ) { let i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ; else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) { L [ i ] [ j ] = 2 ; i -- ; } else { L [ i ] [ j ] = L [ j ] [ k ] + 1 ; llap = Math . max ( llap , L [ i ] [ j ] ) ; i -- ; k ++ ; } } while ( i >= 0 ) { L [ i ] [ j ] = 2 ; i -- ; } } return llap ; } let set1 = [ 1 , 7 , 10 , 13 , 14 , 19 ] ; let n1 = set1 . length ; document . write ( lenghtOfLongestAP ( set1 , n1 ) + " " ) ; let set2 = [ 1 , 7 , 10 , 15 , 27 , 29 ] ; let n2 = set2 . length ; document . write ( lenghtOfLongestAP ( set2 , n2 ) + " " ) ; let set3 = [ 2 , 4 , 6 , 8 , 10 ] ; let n3 = set3 . length ; document . write ( lenghtOfLongestAP ( set3 , n3 ) + " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
function optCost ( freq , i , j ) { return 0 ; if ( j == i ) return freq [ i ] ; var fsum = sum ( freq , i , j ) ; var min = Number . MAX_SAFE_INTEGER ; for ( var r = i ; r <= j ; ++ r ) { var cost = optCost ( freq , i , r - 1 ) + optCost ( freq , r + 1 , j ) ; if ( cost < min ) min = cost ; } return min + fsum ; } function optimalSearchTree ( keys , freq , n ) { return optCost ( freq , 0 , n - 1 ) ; } function sum ( freq , i , j ) { var s = 0 ; for ( var k = i ; k <= j ; k ++ ) s += freq [ k ] ; return s ; } var keys = [ 10 , 12 , 20 ] ; var freq = [ 34 , 8 , 50 ] ; var n = keys . length ; document . write ( " " + optimalSearchTree ( keys , freq , n ) ) ;

Index/key variables: i, k
Accumulator variables: k, s
Iterator variables: k, r
Javascript program:
let MAX = Number . MAX_VALUE ; function printSolution ( p , n ) { let k ; if ( p [ n ] == 1 ) k = 1 ; else k = printSolution ( p , p [ n ] - 1 ) + 1 ; document . write ( " " + " " + k + " " + " " + " " + p [ n ] + " " + " " + " " + n + " " ) ; return k ; } function solveWordWrap ( l , n , M ) { let extras = new Array ( n + 1 ) ; let lc = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { extras [ i ] = new Array ( n + 1 ) ; lc [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) { extras [ i ] [ j ] = 0 ; lc [ i ] [ j ] = 0 ; } } let c = new Array ( n + 1 ) ; let p = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) { extras [ i ] [ i ] = M - l [ i - 1 ] ; for ( let j = i + 1 ; j <= n ; j ++ ) extras [ i ] [ j ] = extras [ i ] [ j - 1 ] - l [ j - 1 ] - 1 ; } for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = i ; j <= n ; j ++ ) { if ( extras [ i ] [ j ] < 0 ) lc [ i ] [ j ] = MAX ; else if ( j == n && extras [ i ] [ j ] >= 0 ) lc [ i ] [ j ] = 0 ; else lc [ i ] [ j ] = extras [ i ] [ j ] * extras [ i ] [ j ] ; } } c [ 0 ] = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { c [ j ] = MAX ; for ( let i = 1 ; i <= j ; i ++ ) { if ( c [ i - 1 ] != MAX && lc [ i ] [ j ] != MAX && ( c [ i - 1 ] + lc [ i ] [ j ] < c [ j ] ) ) { c [ j ] = c [ i - 1 ] + lc [ i ] [ j ] ; p [ j ] = i ; } } } printSolution ( p , n ) ; } let l = [ 3 , 2 , 2 , 5 ] ; let n = l . length ; let M = 6 ; solveWordWrap ( l , n , M ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPalindrome ( String , i , j ) { while ( i < j ) { if ( String [ i ] != String [ j ] ) return false ; i ++ ; j -- ; } return true ; } function minPalPartion ( String , i , j ) { if ( i >= j || isPalindrome ( String , i , j ) ) return 0 ; let ans = Number . MAX_VALUE , count ; for ( let k = i ; k < j ; k ++ ) { count = minPalPartion ( String , i , k ) + minPalPartion ( String , k + 1 , j ) + 1 ; ans = Math . min ( ans , count ) ; } return ans ; } let str = " " ; document . write ( " " + " " + minPalPartion ( str , 0 , str . length - 1 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: k
Javascript program:
function minCut ( a ) { var cut = new Array ( a . length ) ; var palindrome = new Array ( a . length ) ; for ( var i = 0 ; i < a . length ; i ++ ) { var minCut = i ; for ( var j = 0 ; j <= i ; j ++ ) { if ( a . charAt ( i ) == a . charAt ( j ) && ( i - j < 5 palindrome [ j + 1 ] [ i - 1 ] ) ) { palindrome [ j , i ] = true ; minCut = Math . min ( minCut , j == 0 ? 0 : ( cut [ j - 1 ] + 1 ) ) ; } } cut [ i ] = minCut ; } return cut [ a . length - 1 ] ; } document . write ( minCut ( " " ) + " " ) ; document . write ( minCut ( " " ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function lbs ( arr , n ) { let i , j ; let lis = new Array ( n ) for ( i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; let lds = new Array ( n ) ; for ( i = 0 ; i < n ; i ++ ) lds [ i ] = 1 ; for ( i = n - 2 ; i >= 0 ; i -- ) for ( j = n - 1 ; j > i ; j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; let max = lis [ 0 ] + lds [ 0 ] - 1 ; for ( i = 1 ; i < n ; i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ; return max ; } let arr = [ 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 ] let n = arr . length ; document . write ( " " + lbs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function max ( a , b ) { return ( a > b ) ? a : b ; } function eggDrop ( n , k ) { let eggFloor = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { eggFloor [ i ] = new Array ( k + 1 ) ; } let res ; let i , j , x ; for ( i = 1 ; i <= n ; i ++ ) { eggFloor [ i ] [ 1 ] = 1 ; eggFloor [ i ] [ 0 ] = 0 ; } for ( j = 1 ; j <= k ; j ++ ) eggFloor [ 1 ] [ j ] = j ; for ( i = 2 ; i <= n ; i ++ ) { for ( j = 2 ; j <= k ; j ++ ) { eggFloor [ i ] [ j ] = Number . MAX_VALUE ; for ( x = 1 ; x <= j ; x ++ ) { res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ; if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ; } } } return eggFloor [ n ] [ k ] ; } let n = 2 , k = 36 ; document . write ( " " + " " + n + " " + k + " " + eggDrop ( n , k ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j, x
Iterator variables: i, j, x
Javascript program:
var row = 3 ; var col = 3 ; function minCost ( cost ) { for ( i = 1 ; i < row ; i ++ ) { cost [ i ] [ 0 ] += cost [ i - 1 ] [ 0 ] ; } for ( j = 1 ; j < col ; j ++ ) { cost [ 0 ] [ j ] += cost [ 0 ] [ j - 1 ] ; } for ( i = 1 ; i < row ; i ++ ) { for ( j = 1 ; j < col ; j ++ ) { cost [ i ] [ j ] += Math . min ( cost [ i - 1 ] [ j - 1 ] , Math . min ( cost [ i - 1 ] [ j ] , cost [ i ] [ j - 1 ] ) ) ; } } return cost [ row - 1 ] [ col - 1 ] ; } var cost = [ [ 1 , 2 , 3 ] , [ 4 , 8 , 2 ] , [ 1 , 5 , 3 ] ] ; document . write ( minCost ( cost ) + ' ' ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let max_ref ; function _lis ( arr , n ) { if ( n == 1 ) return 1 ; let res , max_ending_here = 1 ; for ( let i = 1 ; i < n ; i ++ ) { res = _lis ( arr , i ) ; if ( arr [ i - 1 ] < arr [ n - 1 ] && res + 1 > max_ending_here ) max_ending_here = res + 1 ; } if ( max_ref < max_ending_here ) max_ref = max_ending_here ; return max_ending_here ; } function lis ( arr , n ) { max_ref = 1 ; _lis ( arr , n ) ; return max_ref ; } let arr = [ 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 ] let n = arr . length ; document . write ( " " + lis ( arr , n ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { let res = 1 ; for ( let i = 1 ; i <= n ; ++ i ) { res *= i ; } return res ; } function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function catalan ( n ) { let c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } function countBST ( n ) { let count = catalan ( n ) ; return count ; } function countBT ( n ) { let count = catalan ( n ) ; return count * factorial ( n ) ; } let count1 , count2 , n = 5 ; count1 = countBST ( n ) ; count2 = countBT ( n ) ; document . write ( " " + n + " " + count1 + " " ) ; document . write ( " " + " " + n + " " + count2 ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function getMissingNumbers ( arr ) { for ( let num of arr ) arr [ Math . abs ( num ) - 1 ] = - ( Math . abs ( arr [ Math . abs ( num ) - 1 ] ) ) for ( pos in arr ) if ( arr [ pos ] > 0 ) document . write ( ` ${ parseInt ( pos ) + 1 } ` ) } let arr = [ 5 , 5 , 4 , 4 , 2 ] getMissingNumbers ( arr )

Index/key variables: pos
Iterator variables: num
Javascript program:
function PosCheck ( a , n , m , check ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] == " " ) { continue ; } else { if ( ( i + j ) & 1 && a [ i ] [ j ] != check ) { return false ; } if ( ! ( ( i + j ) & 1 ) && a [ i ] [ j ] == check ) { return false ; } } } } return true ; } function fill ( a , n , m , odd , even ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( ( i + j ) & 1 ) { a [ i ] [ j ] = odd ; } else { a [ i ] [ j ] = even ; } } } } function findPossibleGrid ( n , m , a ) { let flag = true ; let k = - 1 , o = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] != " " ) { k = i ; o = j ; break ; } } if ( k != - 1 ) { break ; } } if ( k != - 1 ) { flag = PosCheck ( a , n , m , " " ) ; if ( flag ) { fill ( a , n , m , " " , " " ) ; } else { flag = PosCheck ( a , n , m , " " ) ; if ( flag ) { fill ( a , n , m , " " , " " ) ; } } } else { let h = " " ; for ( let i = 0 ; i < m ; i ++ ) { a [ 0 ] [ i ] = h ; if ( h == " " ) { h = " " ; } else { h = " " ; } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( i - 1 < 0 ) { continue ; } if ( a [ i - 1 ] [ j ] == " " ) { a [ i ] [ j ] = " " ; } else { a [ i ] [ j ] = " " ; } } } flag = true ; } if ( ! flag ) { document . write ( " " ) ; } else { document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { document . write ( a [ i ] [ j ] ) ; } document . write ( " " ) ; } } } let n = 4 , m = 4 ; let grid = [ [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , ] ; findPossibleGrid ( n , m , grid ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function count ( S , N ) { let ch = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; let j = 0 ; let res = 0 ; let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < N ; ++ i ) { if ( S [ i ] == ch [ j ] ) { ++ count ; mp . set ( S [ i ] , " " ) ; if ( mp . size == 5 ) { res = Math . max ( res , count ) ; } } else if ( j + 1 < 5 && S [ i ] == ch [ j + 1 ] ) { mp . set ( S [ i ] , " " ) ; ++ count ; j ++ ; if ( mp . size == 5 ) { res = Math . max ( res , count ) ; } } else { mp . clear ( ) ; if ( S [ i ] == ' ' ) { mp . set ( ' ' , " " ) ; j = 0 ; count = 1 ; } else { j = 0 ; count = 0 ; } } } return res ; } let S = " " ; let N = S . length ; document . write ( count ( S , N ) ) ;

Index/key variables: i, j
Accumulator variables: j
Iterator variables: i
Javascript program:
function maxSubsequenceLen ( s , K ) { var N = s . length ; var start = 0 , end = 0 ; var S = s . split ( ' ' ) ; S . sort ( ) ; var ans = Number . MIN_VALUE , sum = 0 ; for ( end = 0 ; end < N ; end ++ ) { sum = sum + ( S [ end ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; while ( sum + K < ( S [ end ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * ( end - start + 1 ) ) { sum = sum - ( S [ start ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; start ++ ; } ans = Math . max ( ans , end - start + 1 ) ; } document . write ( ans ) ; } var S = " " ; var K = 1 ; maxSubsequenceLen ( S , K ) ;

Index/key variables: end, start
Accumulator variables: end, start
Iterator variables: end
Javascript program:
function checkPro ( n , k ) { var exp = 1.0 / k ; var KthRoot = parseInt ( Math . pow ( n , exp ) ) ; var product = 1 ; for ( i = 1 ; i < k + 1 ; i ++ ) { product = product * i ; } if ( product == n ) return " " ; else { for ( j = 2 ; j < KthRoot + 1 ; j ++ ) { product = product * ( j + k - 1 ) ; product = product / ( j - 1 ) ; if ( product == n ) return " " ; } } return " " ; } var N = 210 ; var K = 3 ; document . write ( checkPro ( N , K ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minOperations ( s1 , s2 , n ) { var a = s1 . split ( " " ) ; var b = s2 . split ( " " ) ; var ops = [ ] ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] !== b [ i ] ) { if ( a [ 0 ] === b [ i ] ) { ops . push ( 1 ) ; a [ 0 ] = a [ 0 ] === " " ? " " : " " ; } reverse ( a , 0 , i ) ; for ( var j = 0 ; j <= i ; j ++ ) { a [ j ] = a [ j ] === " " ? " " : " " ; } ops . push ( i + 1 ) ; } } document . write ( ops . length + " " ) ; for ( const x of ops ) { document . write ( x + " " ) ; } } function reverse ( a , start , end ) { while ( start < end ) { var temp = a [ start ] ; a [ start ] = a [ end ] ; a [ end ] = temp ; start ++ ; end -- ; } } var a = " " , b = " " ; var N = a . length ; minOperations ( a , b , N ) ;

Index/key variables: end, i, j, start
Accumulator variables: end, i, j, start
Iterator variables: i, j, x
Javascript program:
function findCount0th ( arr , N , K ) { let oddsum = 0 , evensum = 0 ; for ( let i = 1 ; i < N ; i += 2 ) { oddsum += arr [ i ] ; } for ( let i = 2 ; i < N ; i += 2 ) { evensum += arr [ i ] ; } if ( Math . abs ( oddsum - evensum ) == K ) return 1 ; else return 0 ; } function findCount1st ( arr , N , K ) { let evensum = arr [ 0 ] , oddsum = 0 ; for ( let i = 3 ; i < N ; i += 2 ) { evensum += arr [ i ] ; } for ( let i = 2 ; i < N ; i += 2 ) { oddsum += arr [ i ] ; } if ( Math . abs ( oddsum - evensum ) == K ) return 1 ; else return 0 ; } function countTimes ( arr , K ) { let N = arr . length ; if ( N == 1 ) return 1 ; if ( N < 3 ) return 0 ; if ( N == 3 ) { let cnt = 0 ; cnt += ( Math . abs ( arr [ 0 ] - arr [ 1 ] ) == K ? 1 : 0 ) + ( Math . abs ( arr [ 2 ] - arr [ 1 ] ) == K ? 1 : 0 ) + ( Math . abs ( arr [ 0 ] - arr [ 2 ] ) == K ? 1 : 0 ) ; return cnt ; } let prefix = new Array ( N + 2 ) ; let suffix = new Array ( N + 2 ) ; for ( let i = 0 ; i < N + 2 ; i ++ ) { prefix [ i ] = 0 ; } for ( let i = 0 ; i < N + 2 ; i ++ ) { suffix [ i ] = 0 ; } prefix [ 0 ] = arr [ 0 ] ; prefix [ 1 ] = arr [ 1 ] ; suffix [ N - 1 ] = arr [ N - 1 ] ; suffix [ N - 2 ] = arr [ N - 2 ] ; for ( let i = 2 ; i < N ; i += 2 ) { prefix [ i ] = arr [ i ] + prefix [ i - 2 ] ; } for ( let i = 3 ; i < N ; i += 2 ) { prefix [ i ] = arr [ i ] + prefix [ i - 2 ] ; } for ( let i = N - 3 ; i >= 0 ; i -= 2 ) { suffix [ i ] = arr [ i ] + suffix [ i + 2 ] ; } for ( let i = N - 4 ; i >= 0 ; i -= 2 ) { suffix [ i ] = arr [ i ] + suffix [ i + 2 ] ; } let count = 0 ; for ( let i = 2 ; i < N ; i ++ ) { if ( Math . abs ( prefix [ i - 1 ] + suffix [ i + 2 ] - prefix [ i - 2 ] - suffix [ i + 1 ] ) == K ) { count ++ ; } } count += findCount0th ( arr , N , K ) ; count += findCount1st ( arr , N , K ) ; return count ; } let arr = [ 1 , 2 , 4 , 5 , 6 ] ; let K = 2 ; document . write ( countTimes ( arr , K ) ) ;

Index/key variables: i
Accumulator variables: cnt, count, evensum, i, oddsum
Iterator variables: i
Javascript program:
function changeString ( S ) { let s = S . split ( " " ) ; let N = S . length ; if ( s [ 0 ] == ' ' ) { s [ 0 ] = ' ' ; if ( s [ 0 ] == s [ 1 ] ) { s [ 0 ] = String . fromCharCode ( s [ 0 ] . charCodeAt ( 0 ) + 1 ) ; } } for ( let i = 1 ; i < N - 1 ; i ++ ) { if ( s [ i ] == ' ' ) { s [ i ] = ' ' ; if ( s [ i ] == s [ i - 1 ] ) { s [ i ] = String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) + 1 ) ; } if ( s [ i ] == s [ i + 1 ] ) { s [ i ] = String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) + 1 ) ; } if ( s [ i ] == s [ i - 1 ] ) { s [ i ] = String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) + 1 ) ; } } } if ( s [ N - 1 ] == ' ' ) { s [ N - 1 ] = ' ' ; if ( s [ N - 1 ] == s [ N - 2 ] ) { s [ N - 1 ] ++ ; } } let ans = " " ; for ( let i = 0 ; i < s . length ; i ++ ) { ans += s [ i ] ; } return ans ; } let S = " " ; document . write ( changeString ( S ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function checkReverseBitonic ( s ) { var i , j ; for ( i = 1 ; i < s . length ; i ++ ) { if ( s [ i ] < s [ i - 1 ] ) continue ; if ( s [ i ] >= s [ i - 1 ] ) break ; } if ( i == s . length - 1 ) return 1 ; for ( j = i + 1 ; j < s . length ; j ++ ) { if ( s [ j ] > s [ j - 1 ] ) continue ; if ( s [ j ] <= s [ j - 1 ] ) break ; } i = j ; if ( i != s . length ) return 0 ; return 1 ; } var s = " " ; ( checkReverseBitonic ( s ) == 1 ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countKCountdown ( arr , N , K ) { var flag = - 1 ; var count = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == K ) flag = K ; if ( arr [ i ] == flag ) flag -- ; else flag = - 1 ; if ( flag == 0 ) count ++ ; } return count ; } var N = 8 ; var K = 3 ; var arr = [ 4 , 3 , 2 , 1 , 5 , 3 , 2 , 1 ] ; document . write ( countKCountdown ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, flag, i
Iterator variables: i
Javascript program:
function decToHexa ( n ) { let hexaDeciNum = Array . from ( { length : 2 } , ( _ , i ) => 0 ) ; let i = 0 ; while ( n != 0 ) { let temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = String . fromCharCode ( temp + 48 ) ; i ++ ; } else { hexaDeciNum [ i ] = String . fromCharCode ( temp + 55 ) ; i ++ ; } n = Math . floor ( n / 16 ) ; } let hexCode = " " ; if ( i == 2 ) { hexCode += hexaDeciNum [ 0 ] ; hexCode += hexaDeciNum [ 1 ] ; } else if ( i == 1 ) { hexCode = " " ; hexCode += hexaDeciNum [ 0 ] ; } else if ( i == 0 ) hexCode = " " ; return hexCode ; } function convertRGBtoHex ( R , G , B ) { if ( ( R >= 0 && R <= 255 ) && ( G >= 0 && G <= 255 ) && ( B >= 0 && B <= 255 ) ) { let hexCode = " " ; hexCode += decToHexa ( R ) ; hexCode += decToHexa ( G ) ; hexCode += decToHexa ( B ) ; return hexCode ; } else return " " ; } let R = 0 , G = 0 , B = 0 ; document . write ( convertRGBtoHex ( R , G , B ) + " " ) ; R = 255 ; G = 255 ; B = 255 ; document . write ( convertRGBtoHex ( R , G , B ) + " " ) ; R = 25 ; G = 56 ; B = 123 ; document . write ( convertRGBtoHex ( R , G , B ) + " " ) ; R = 2 ; G = 3 ; B = 4 ; document . write ( convertRGBtoHex ( R , G , B ) + " " ) ; R = 255 ; G = 255 ; B = 256 ; document . write ( convertRGBtoHex ( R , G , B ) + " " ) ;

Index/key variables: i
Accumulator variables: hexCode, i
Javascript program:
function q1 ( s , i ) { if ( i == s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] == ' ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } function q2 ( s , i ) { if ( i == s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] == ' ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } function q3 ( s , i ) { if ( i == s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] == ' ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } function q4 ( s , i ) { if ( i == s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] == ' ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } function q0 ( s , i ) { if ( i == s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] == ' ' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } var s = " " ; q0 ( s , 0 ) ;

Index/key variables: i
Javascript program:
function prefix ( str ) { let k = 1 , j ; let n = str . length ; let g = [ ] ; let flag = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) { g . push ( i ) ; flag = 1 ; } } if ( flag == 0 ) { document . write ( ( str . join ( " " ) ) ) ; } else { let len = g . length ; while ( k < g [ 0 ] ) { let cnt = 0 ; for ( j = 0 ; j < len ; j ++ ) { if ( ( g [ j ] + k ) < n && str [ g [ j ] + k ] == str [ k ] ) { cnt ++ ; } } if ( cnt == len ) { k ++ ; } else { break ; } } for ( let i = 0 ; i < k ; i ++ ) { document . write ( str [ i ] ) ; } document . write ( " " ) ; } } let str = " " ; prefix ( str ) ;

Index/key variables: i, j, k
Accumulator variables: cnt, i, j, k
Iterator variables: i, j
Javascript program:
function printPermutation ( N , K ) { var res = [ ] ; var l = 1 , r = N , flag = 0 ; for ( var i = 0 ; i < K ; i ++ ) { if ( ! flag ) { res . push ( l ) ; l ++ ; } else { res . push ( r ) ; r -- ; } flag ^= 1 ; } if ( ! flag ) { for ( var i = r ; i >= l ; i -- ) res . push ( i ) ; } else { for ( var i = l ; i <= r ; i ++ ) res . push ( i ) ; } for ( var i = 0 ; i < res . length ; i ++ ) { document . write ( res [ i ] + " " ) ; } } var N = 10 , K = 4 ; printPermutation ( N , K ) ;

Index/key variables: i
Accumulator variables: flag, i, l, r
Iterator variables: i
Javascript program:
function fact ( N ) { let i , product = 1 ; for ( i = 1 ; i <= N ; i ++ ) product = product * i ; return product ; } function nthTerm ( N ) { return ( N * N ) * fact ( N ) ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;

Accumulator variables: i
Iterator variables: i