dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let MAXL = 17 ; let N ; let v = [ ] function findN ( D ) { if ( D % 9 != 0 ) return 0 ; D /= 9 ; let B = new Array ( MAXL ) . fill ( 0 ) ; B [ 0 ] = 1 ; for ( let i = 1 ; i < MAXL ; i ++ ) { B [ i ] = B [ i - 1 ] * 10 ; } let ans = 0 ; for ( let i = 1 ; i <= MAXL ; i ++ ) { N = Math . floor ( ( i + 1 ) / 2 ) ; v = new Array ( N ) . fill ( 0 ) ; for ( let j = 0 ; j < N ; j ++ ) for ( let k = j ; k < i - j ; k ++ ) v [ j ] += B [ k ] ; ans += count ( D , i , 0 , new Array ( N ) ) ; } return ans ; } function count ( D , l , t , x ) { if ( t == N ) { if ( D != 0 ) return 0 ; let ans = 1 ; for ( let i = 0 ; i < N ; i ++ ) { ans *= ( i == 0 ? 9 : 10 ) - Math . abs ( x [ i ] ) ; } if ( l % 2 == 0 ) { ans *= 10 ; } return ans ; } let ans = 0 ; for ( let m = - 9 ; m <= 9 ; m ++ ) { if ( - v [ t ] < D + v [ t ] * m && D + v [ t ] * m < v [ t ] ) { x [ t ] = m ; ans += count ( D + v [ t ] * m , l , t + 1 , x ) ; } } return ans ; } let D = 63 ; document . write ( findN ( D ) ) ;

Index/key variables: i, j, k, t
Accumulator variables: D, ans, i, j, k, m
Iterator variables: i, j, k, m
Javascript program:
function findPeak ( arr ) { var left = 0 ; var right = arr . length - 1 ; while ( left < right ) { var mid = left + parseInt ( ( right - left ) / 2 ) ; if ( arr [ mid ] < arr [ mid + 1 ] ) { left = mid + 1 ; } else { right = mid ; } } return left ; } function BS ( X , left , right , arr ) { while ( left <= right ) { var mid = left + parseInt ( ( right - left ) / 2 ) ; if ( arr [ mid ] == X ) { return mid ; } else if ( X > arr [ mid ] ) { left = mid + 1 ; } else { right = mid - 1 ; } } return - 1 ; } function reverseBS ( X , left , right , arr ) { while ( left <= right ) { var mid = left + parseInt ( ( right - left ) / 2 ) ; if ( arr [ mid ] == X ) { return mid ; } else if ( X > arr [ mid ] ) { right = mid - 1 ; } else { left = mid + 1 ; } } return - 1 ; } function findInMA ( X , mountainArr ) { var peakIndex = findPeak ( mountainArr ) ; var res = - 1 ; if ( X >= mountainArr [ 0 ] && X <= mountainArr [ peakIndex ] ) { res = BS ( X , 0 , peakIndex , mountainArr ) ; } if ( res == - 1 ) { res = reverseBS ( X , peakIndex + 1 , mountainArr . length - 1 , mountainArr ) ; } document . write ( res + " " ) ; } var X = 3 ; var X = 3 ; var list = [ 1 , 2 , 3 , 4 , 5 , 3 , 1 ] ; findInMA ( X , list ) ;

Index/key variables: mid, peakIndex
Javascript program:
function count ( a ) { let counter = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] == 0 ) { counter ++ ; } } return counter ; } function rearrange ( a , n , x ) { for ( let i = 0 ; i < n ; i ++ ) a [ i ] = Math . abs ( a [ i ] ) ; a . sort ( ) ; x = n - x ; let z = count ( a ) ; if ( x > n - z ) { document . write ( " " ) ; return ; } for ( let i = 0 ; i < n && x > 0 ; i += 2 ) { a [ i ] = - a [ i ] ; x -- ; } for ( let i = n - 1 ; i >= 0 && x > 0 ; i -- ) { if ( a [ i ] > 0 ) { a [ i ] = - a [ i ] ; x -- ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let arr = [ 0 , - 2 , 4 , 5 , - 3 ] ; let K = 3 ; let N = arr . length ; rearrange ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: counter, i, x
Iterator variables: i
Javascript program:
function maxSubarrayProduct ( arr , n ) { var max_ending_here = 1 ; var min_ending_here = 1 ; var max_so_far = 0 ; var flag = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { max_ending_here = max_ending_here * arr [ i ] ; min_ending_here = Math . min ( min_ending_here * arr [ i ] , 1 ) ; flag = 1 ; } else if ( arr [ i ] == 0 ) { max_ending_here = 1 ; min_ending_here = 1 ; } else { var temp = max_ending_here ; max_ending_here = Math . max ( min_ending_here * arr [ i ] , 1 ) ; min_ending_here = temp * arr [ i ] ; } if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } if ( flag == 0 && max_so_far == 0 ) return 0 ; return max_so_far ; } function findMaxProduct ( a , n ) { var i = 0 ; var maxProd = - 1e9 ; while ( i < n ) { var v = [ ] ; v . push ( a [ i ] ) ; if ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { v . push ( a [ i + 1 ] ) ; i += 1 ; } } else if ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { v . push ( a [ i + 1 ] ) ; i += 1 ; } } var prod = maxSubarrayProduct ( v , v . length ) ; maxProd = Math . max ( maxProd , prod ) ; i ++ ; } return maxProd ; } var arr = [ 1 , 2 , 10 , 8 , 1 , 100 , 101 ] ; var N = arr . length ; document . write ( findMaxProduct ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var parent = Array ( 1000000 ) ; function root ( a ) { if ( a == parent [ a ] ) { return a ; } return parent [ a ] = root ( parent [ a ] ) ; } function connect ( a , b ) { a = root ( a ) ; b = root ( b ) ; if ( a != b ) { parent [ b ] = a ; } } function connectedComponents ( n ) { var s = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { s . add ( parent [ i ] ) ; } document . write ( s . size + " " ) ; } function printAnswer ( N , edges ) { for ( var i = 0 ; i <= N ; i ++ ) { parent [ i ] = i ; } for ( var i = 0 ; i < edges . length ; i ++ ) { connect ( edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; } connectedComponents ( N ) ; } var N = 8 ; var edges = [ [ 1 , 0 ] , [ 0 , 2 ] , [ 5 , 3 ] , [ 3 , 4 ] , [ 6 , 7 ] ] ; printAnswer ( N , edges ) ;

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function removeZeroRowCol ( arr ) { let n = arr . length ; let col = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; let row = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; ++ i ) { let count = 0 ; for ( let j = 0 ; j < n ; ++ j ) { if ( arr [ i ] [ j ] == 1 ) col [ j ] += 1 ; else col [ j ] += 0 ; if ( arr [ i ] [ j ] == 1 ) count += 1 ; else count += 0 ; } row [ i ] = count ; } for ( let i = 0 ; i < n ; ++ i ) { if ( row [ i ] == 0 ) { continue ; } for ( let j = 0 ; j < n ; ++ j ) { if ( col [ j ] != 0 ) document . write ( arr [ i ] [ j ] ) ; } document . write ( " " ) ; } } let arr = [ [ 1 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 1 ] ] ; removeZeroRowCol ( arr ) ;

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Javascript program:
function findOverlapSegement ( N , a , b ) { var tup = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { var x , y ; x = a [ i ] ; y = b [ i ] ; tup . push ( [ [ x , y ] , i ] ) ; } tup . sort ( ( a , b ) => { if ( a [ 0 ] [ 0 ] == b [ 0 ] [ 0 ] ) { return a [ 0 ] [ 1 ] - b [ 0 ] [ 1 ] ; } var tmp = ( a [ 0 ] [ 0 ] - b [ 0 ] [ 0 ] ) ; console . log ( tmp ) ; return ( a [ 0 ] [ 0 ] - b [ 0 ] [ 0 ] ) } ) ; var curr = tup [ 0 ] [ 0 ] [ 1 ] ; var currPos = tup [ 0 ] [ 1 ] ; for ( var i = 1 ; i < N ; i ++ ) { var Q = tup [ i - 1 ] [ 0 ] [ 0 ] ; var R = tup [ i ] [ 0 ] [ 0 ] ; if ( Q == R ) { if ( tup [ i - 1 ] [ 0 ] [ 1 ] < tup [ i ] [ 0 ] [ 1 ] ) { document . write ( tup [ i - 1 ] [ 1 ] + " " + tup [ i ] [ 1 ] ) ; return ; } else { document . write ( tup [ i ] [ 1 ] + " " + tup [ i - 1 ] [ 1 ] ) ; return ; } } var T = tup [ i ] [ 0 ] [ 1 ] ; if ( T <= curr ) { document . write ( tup [ i ] [ 1 ] + " " + currPos ) ; return ; } else { curr = T ; currPos = tup [ i ] [ 1 ] ; } } document . write ( " " ) ; } let a = [ 1 , 2 , 3 , 2 , 2 ] ; let b = [ 5 , 10 , 10 , 2 , 15 ] ; let N = a . length ; findOverlapSegement ( N , a , b ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class TreeNode { constructor ( x ) { this . left = null ; this . right = null ; this . val = x ; } } let diagMap = new Map ( ) ; function replaceDiag ( root , d ) { if ( root == null ) return ; if ( diagMap . has ( d ) ) root . val = diagMap . get ( d ) ; replaceDiag ( root . left , d + 1 ) ; replaceDiag ( root . right , d ) ; } function getDiagSum ( root , d ) { if ( root == null ) return ; if ( diagMap . has ( d ) ) diagMap . set ( d , diagMap . get ( d ) + root . val ) ; else diagMap . set ( d , root . val ) ; getDiagSum ( root . left , d + 1 ) ; getDiagSum ( root . right , d ) ; } function levelOrder ( root ) { let q = [ ] ; q . push ( root ) ; while ( true ) { let length = q . length ; if ( ! length ) break ; while ( length ) { let temp = q [ 0 ] ; q . shift ( ) ; document . write ( temp . val + " " ) ; if ( temp . left != null ) q . push ( temp . left ) ; if ( temp . right != null ) q . push ( temp . right ) ; length -= 1 ; } } } let root = new TreeNode ( 5 ) ; root . left = new TreeNode ( 6 ) ; root . right = new TreeNode ( 3 ) ; root . left . left = new TreeNode ( 4 ) ; root . left . right = new TreeNode ( 9 ) ; root . right . right = new TreeNode ( 2 ) ; getDiagSum ( root , 0 ) ; replaceDiag ( root , 0 ) ; levelOrder ( root ) ;

Class/struct names: TreeNode
Javascript program:
function countDivBy3InArray ( arr ) { let ans = 0 ; let taken = new Array ( arr . length ) ; taken . fill ( false ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( taken [ i ] == true ) { continue ; } for ( let j = i + 1 ; j < arr . length ; j ++ ) { if ( taken [ j ] == true ) { continue ; } if ( parseInt ( ( arr [ i ] ) . toString ( ) + ( arr [ j ] ) . toString ( ) , 10 ) % 3 == 0 || parseInt ( ( arr [ j ] ) . toString ( ) + ( arr [ i ] ) . toString ( ) , 10 ) % 3 == 0 ) { ans += 1 ; taken [ i ] = true ; taken [ j ] = true ; } } } return ans ; } let arr = [ 5 , 3 , 2 , 8 , 7 ] ; document . write ( countDivBy3InArray ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function findMaxLengthSequence ( N , arr ) { let rightmost_element = - 1 ; let i = 0 ; let j = N - 1 ; let sequence = [ ] ; while ( i <= j ) { if ( arr [ i ] > arr [ j ] ) { if ( arr [ j ] > rightmost_element ) { sequence . push ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else if ( arr [ i ] > rightmost_element ) { sequence . push ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else break ; } else if ( arr [ i ] < arr [ j ] ) { if ( arr [ i ] > rightmost_element ) { sequence . push ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else if ( arr [ j ] > rightmost_element ) { sequence . push ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else break ; } else if ( arr [ i ] == arr [ j ] ) { if ( i == j ) { if ( arr [ i ] > rightmost_element ) { sequence . push ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } break ; } else { sequence . push ( arr [ i ] ) ; let k = i + 1 ; let max_left = [ ] ; while ( k < j && arr [ k ] > arr [ k - 1 ] ) { max_left . push ( arr [ k ] ) ; k ++ ; } let l = j - 1 ; let max_right = [ ] ; while ( l > i && arr [ l ] > arr [ l + 1 ] ) { max_right . push ( arr [ l ] ) ; l -- ; } if ( max_left . length > max_right . length ) for ( let element = 0 ; element < max_left . length ; element ++ ) sequence . push ( max_left [ element ] ) ; else for ( let element = 0 ; element < max_right . length ; element ++ ) sequence . push ( max_right [ element ] ) ; break ; } } } for ( let element = 0 ; element < sequence . length ; element ++ ) document . write ( sequence [ element ] + " " ) ; } let N = 4 ; let arr = [ 1 , 3 , 2 , 1 ] ; findMaxLengthSequence ( N , arr ) ;

Index/key variables: element, i, j, k, l
Accumulator variables: element, i, j, k, l
Iterator variables: element
Javascript program:
class TreeNode { constructor ( v ) { this . val = v ; this . children = [ ] ; } } let ans = 0.0 ; function MaxAverage ( root ) { if ( root . children != null && root . children . length == 0 ) { ans = Math . max ( ans , root . val ) ; return [ root . val , 1 ] ; } let childResult = new Array ( 2 ) ; for ( let i = 0 ; i < childResult . length ; i ++ ) { childResult [ i ] = 0 ; } for ( let child = 0 ; child < root . children . length ; child ++ ) { let childTotal = MaxAverage ( root . children [ child ] ) ; childResult [ 0 ] = childResult [ 0 ] + childTotal [ 0 ] ; childResult [ 1 ] = childResult [ 1 ] + childTotal [ 1 ] ; } let sum = childResult [ 0 ] + root . val ; let count = childResult [ 1 ] + 1 ; ans = Math . max ( ans , sum / count ) ; return [ sum , count ] ; } let root = new TreeNode ( 20 ) ; let left = new TreeNode ( 12 ) ; let right = new TreeNode ( 18 ) ; root . children . push ( left ) ; root . children . push ( right ) ; left . children . push ( new TreeNode ( 11 ) ) ; left . children . push ( new TreeNode ( 3 ) ) ; right . children . push ( new TreeNode ( 15 ) ) ; right . children . push ( new TreeNode ( 8 ) ) ; MaxAverage ( root ) ; document . write ( ans . toFixed ( 1 ) ) ;

Index/key variables: child, i
Accumulator variables: child, i
Iterator variables: child, i
Class/struct names: TreeNode
Javascript program:
function canTransformStrings ( A , B ) { let n1 = A . length ; let n2 = B . length ; let count1A = 0 , count1B = 0 ; let odd1A = 0 , odd1B = 0 ; let even1A = 0 , even1B = 0 ; for ( let i = 0 ; i < n1 ; i ++ ) { if ( A [ i ] == ' ' ) count1A ++ ; else { if ( ( count1A & 1 ) == 1 ) odd1A ++ ; else even1A ++ ; } } for ( let i = 0 ; i < n2 ; i ++ ) { if ( B [ i ] == ' ' ) count1B ++ ; else { if ( ( count1B & 1 ) == 1 ) odd1B ++ ; else even1B ++ ; } } if ( count1A == count1B && odd1A == odd1B && even1A == even1B ) { document . write ( " " ) ; } else document . write ( " " ) ; } let A = " " , B = " " ; canTransformStrings ( A , B ) ;

Index/key variables: i
Accumulator variables: count1A, count1B, even1A, even1B, i, odd1A, odd1B
Iterator variables: i
Javascript program:
function printAnswer ( answer , N ) { for ( let i = 1 ; i <= N ; i ++ ) { document . write ( answer [ i ] + " " ) ; } } function updateAnswerArray ( answer , N ) { let i = 0 ; while ( answer [ i ] == - 1 ) i ++ ; let minimum = answer [ i ] ; while ( i <= N ) { if ( answer [ i ] == - 1 ) answer [ i ] = minimum ; else answer [ i ] = Math . min ( minimum , answer [ i ] ) ; minimum = Math . min ( minimum , answer [ i ] ) ; i ++ ; } } function lengthOfSubarray ( indices , st , N ) { let answer = new Array ( N + 1 ) . fill ( - 1 ) ; for ( let itr of st ) { let start = - 1 ; let gap = - 1 ; indices [ itr ] . push ( N ) ; for ( let i = 0 ; i < indices [ itr ] . length ; i ++ ) { gap = Math . max ( gap , indices [ itr ] [ i ] - start ) ; start = indices [ itr ] [ i ] ; } if ( answer [ gap ] == - 1 ) answer [ gap ] = itr ; } updateAnswerArray ( answer , N ) ; printAnswer ( answer , N ) ; } function smallestPresentNumber ( arr , N ) { let indices = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => [ ] ) ; let elements = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { indices [ arr [ i ] ] . push ( i ) ; elements . add ( arr [ i ] ) ; } lengthOfSubarray ( indices , elements , N ) ; } let arr = [ 2 , 3 , 5 , 3 , 2 , 3 , 1 , 3 , 2 , 7 ] ; let N = arr . length ; smallestPresentNumber ( arr , N ) ;

Index/key variables: gap, i, itr
Accumulator variables: i
Iterator variables: i, itr
Javascript program:
let M = 6 ; let N = 7 ; function smallestLeft ( arr , total , sum , i , dp ) { if ( i == 0 ) { return Math . abs ( total - 2 * sum ) ; } if ( dp [ i ] [ sum ] != - 1 ) return dp [ i ] [ sum ] ; let X = smallestLeft ( arr , total , sum + arr [ i - 1 ] , i - 1 , dp ) ; let Y = smallestLeft ( arr , total , sum , i - 1 , dp ) ; return dp [ i ] [ sum ] = Math . min ( X , Y ) ; } function UtilSmallestElement ( arr , N ) { let total = 0 ; for ( let i = 0 ; i < N ; i ++ ) { total += arr [ i ] ; } 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 < dp . length ; j ++ ) { dp [ i ] [ j ] = 1 ; } } document . write ( smallestLeft ( arr , total , 0 , N , dp ) ) ; } let arr = [ 2 , 7 , 4 , 1 , 8 , 1 ] ; let n = arr . length ; UtilSmallestElement ( arr , n ) ;

Index/key variables: i, j, sum
Accumulator variables: i, j, total
Iterator variables: i, j
Javascript program:
function SmallestElementLeft ( arr , N ) { var totalSum = 0 ; for ( i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } var req = totalSum / 2 ; var dp = Array ( req + 1 ) . fill ( false ) ; dp [ 0 ] = true ; var reach = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = req ; j - arr [ i ] >= 0 ; j -- ) { dp [ j ] = dp [ j ] || dp [ j - arr [ i ] ] ; if ( dp [ j ] ) { reach = Math . max ( reach , j ) ; } } } return totalSum - ( 2 * reach ) ; } var arr = [ 2 , 2 , 2 ] ; var N = arr . length ; document . write ( SmallestElementLeft ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, totalSum
Iterator variables: i, j
Javascript program:
function min_Operations ( str1 , str2 ) { var N = str1 . length ; var cntOp = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( str1 . charCodeAt ( i ) == str2 . charCodeAt ( i ) ) { continue ; } var ptr = i ; while ( ptr < N && str1 [ ptr ] != str2 [ ptr ] ) { str1 = str1 . substring ( 0 , ptr ) + str2 [ ptr ] + str1 . substring ( ptr + 1 ) ; ptr += 2 ; } cntOp ++ ; } return cntOp ; } str1 = " " ; str2 = " " ; document . write ( min_Operations ( str1 , str2 ) ) ;

Index/key variables: ptr
Accumulator variables: cntOp, i, ptr
Iterator variables: i
Javascript program:
function __gcd ( a , b ) { if ( ! b ) { return a ; } return __gcd ( b , a % b ) ; } function isComposite ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; var i ; for ( i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } function isPerfectSquare ( x ) { var s = Math . sqrt ( x ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function ifgcdFibonacci ( a , n , k ) { var compositeset = [ ] ; var i ; for ( i = 0 ; i < n ; i ++ ) { if ( isComposite ( a [ i ] ) && a [ i ] % k == 0 ) { compositeset . push ( a [ i ] ) ; } } var gcd = compositeset [ 0 ] ; for ( i = 1 ; i < compositeset . length ; i ++ ) { gcd = __gcd ( gcd , compositeset [ i ] ) ; if ( gcd == 1 ) { break ; } } if ( isFibonacci ( gcd ) ) { document . write ( " " ) ; return ; } document . write ( " " ) ; return ; } var arr = [ 34 , 2 , 4 , 8 , 5 , 7 , 11 ] ; var n = arr . length ; var k = 2 ; ifgcdFibonacci ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function find_longest_subarray ( A , N , K ) { let MaxLen = 0 ; let Len = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( K % A [ i ] == 0 ) { Len ++ ; MaxLen = Math . max ( MaxLen , Len ) ; } else { Len = 0 ; } } return MaxLen ; } let A = [ 2 , 8 , 3 , 10 , 6 , 7 , 4 , 9 ] ; let N = A . length ; let K = 60 ; document . write ( find_longest_subarray ( A , N , K ) ) ;

Index/key variables: i
Accumulator variables: Len, i
Iterator variables: i
Javascript program:
let exit = [ ] ; function minTime ( meeting , n , entrance , m , p ) { let ans = Number . MAX_VALUE ; ( entrance ) . sort ( function ( a , b ) { return a - b ; } ) ; ( exit ) . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { let u = meeting [ i ] [ 0 ] ; let v = meeting [ i ] [ 1 ] ; let it1 = upper_bound ( entrance , 0 , entrance . length , u ) ; let it2 = lowerBound ( exit , 0 , exit . length , v ) ; let start = it1 - 1 ; let end = it2 ; if ( start >= 0 && start < m && end >= 0 && end < p ) ans = Math . min ( ans , exit [ end ] - entrance [ start ] ) ; } return ans >= Number . MAX_VALUE ? - 1 : ans ; } function upper_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + Math . floor ( ( high - low ) / 2 ) ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } function lowerBound ( vec , low , high , element ) { let array = new Array ( vec . length ) ; let k = 0 ; for ( let val = 0 ; val < vec . length ; val ++ ) { array [ k ] = vec [ val ] ; k ++ ; } while ( low < high ) { let middle = low + Math . floor ( ( high - low ) / 2 ) ; if ( element > array [ middle ] ) { low = middle + 1 ; } else { high = middle ; } } return low ; } let meeting = [ [ 15 , 19 ] , [ 5 , 10 ] , [ 7 , 25 ] ] ; let entrance = [ 4 , 13 , 25 , 2 ] ; exit . push ( 10 ) ; exit . push ( 25 ) ; let n = meeting . length ; let m = entrance . length ; let p = exit . length ; document . write ( minTime ( meeting , n , entrance , m , p ) + " " ) ;

Index/key variables: end, i, k, middle, start, val
Accumulator variables: i, k, val
Iterator variables: i, val
Javascript program:
function splitArray ( a , n , k ) { let first = [ ] ; let second = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= parseInt ( k / 2 ) ) first . push ( a [ i ] ) ; else second . push ( a [ i ] ) ; } for ( let i = 0 ; i < first . length ; i ++ ) { document . write ( first [ i ] + " " ) ; } document . write ( " " ) ; for ( let i = 0 ; i < second . length ; i ++ ) { document . write ( second [ i ] + " " ) ; } } let k = 5 ; let a = [ 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; let n = a . length ; splitArray ( a , n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 1001 function sieve ( ) { let spf = new Array ( MAX ) ; spf [ 0 ] = spf [ 1 ] = - 1 ; for ( let i = 2 ; i < MAX ; i ++ ) { spf [ i ] = i ; } for ( let i = 4 ; i < MAX ; i = i + 2 ) { spf [ i ] = 2 ; } for ( let i = 3 ; i * i < MAX ; i ++ ) { if ( spf [ i ] == i ) { for ( let j = i * i ; j < MAX ; j = j + i ) { if ( spf [ j ] == j ) { spf [ j ] = i ; } } } } return spf ; } function countFactors ( spf , num ) { let count = 0 ; while ( num > 1 ) { count ++ ; num = num / spf [ num ] ; } return count ; } function precalculateSum ( spf ) { let sum = new Array ( MAX ) ; sum [ 0 ] = 0 ; for ( let i = 1 ; i < MAX ; i ++ ) { let prime_factor = countFactors ( spf , i ) ; if ( spf [ prime_factor ] == prime_factor ) { sum [ i ] = sum [ i - 1 ] + 1 ; } else { sum [ i ] = sum [ i - 1 ] ; } } return sum ; } let spf = sieve ( ) ; let sum = precalculateSum ( spf ) ; let Q = [ [ 4 , 8 ] , [ 30 , 32 ] ] ; for ( let i = 0 ; i < 2 ; i ++ ) { document . write ( ( sum [ Q [ i ] [ 1 ] ] - sum [ Q [ i ] [ 0 ] - 1 ] ) + " " ) ; }

Index/key variables: i, j, num, prime_factor
Accumulator variables: count, i
Iterator variables: i, j
Javascript program:
function isPerfect ( N ) { let sum = 1 ; for ( let i = 2 ; i < Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( i == N / i ) { sum += i ; } else { sum += i + N / i ; } } } if ( sum == N && N != 1 ) return 1 ; return 0 ; } function maxSum ( arr , N , K ) { if ( N < K ) { document . write ( " " ) ; return - 1 ; } let res = 0 ; for ( let i = 0 ; i < K ; i ++ ) { res += arr [ i ] ; } let curr_sum = res ; for ( let i = K ; i < N ; i ++ ) { curr_sum += arr [ i ] - arr [ i - K ] ; res = Math . max ( res , curr_sum ) ; } return res ; } function max_PerfectNumbers ( arr , N , K ) { for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = isPerfect ( arr [ i ] ) == 1 ? 1 : 0 ; } return maxSum ( arr , N , K ) ; } let arr = [ 28 , 2 , 3 , 6 , 496 , 99 , 8128 , 24 ] ; let K = 4 ; let N = arr . length ; document . write ( max_PerfectNumbers ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: curr_sum, i, res, sum
Iterator variables: i
Javascript program:
function display ( countLeftGreater , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( countLeftGreater [ i ] , " " ) ; } } function countGreater ( arr , N ) { let St = new Set ( ) ; let countLeftGreater = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { St . add ( arr [ i ] ) ; let it = 0 ; for ( let st of St ) { if ( arr [ i ] < st ) it += 1 ; } countLeftGreater [ i ] = Math . abs ( it ) ; } display ( countLeftGreater , N ) ; } let arr = [ 12 , 1 , 2 , 3 , 0 , 11 , 4 ] ; let N = arr . length ; countGreater ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, it
Iterator variables: i, st
Javascript program:
function minCost ( A , B ) { var n = A . length ; var i = 0 ; var maxlen = 0 ; while ( i < n ) { var length = 0 ; for ( var j = 0 ; j < n ; ++ j ) { if ( A [ i ] == B [ j ] ) { ++ i ; ++ length ; if ( i == n ) break ; } } maxlen = Math . max ( maxlen , length ) ; } return n - maxlen ; } var A = " " ; var B = " " ; document . write ( minCost ( A , B ) ) ;

Index/key variables: i, j
Iterator variables: j