dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function constructLowerArray ( arr , countSmaller , n ) { let i , j ; for ( i = 0 ; i < n ; i ++ ) countSmaller [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < arr [ i ] ) countSmaller [ i ] ++ ; } } } function printArray ( arr , size ) { let i ; for ( i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 12 , 10 , 5 , 4 , 2 , 20 , 6 , 1 , 0 , 2 ] ; let n = arr . length ; let low = new Array ( n ) ; constructLowerArray ( arr , low , n ) ; printArray ( low , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function segregate ( arr , size ) { let j = 0 , i ; for ( i = 0 ; i < size ; i ++ ) { if ( arr [ i ] <= 0 ) { let temp ; temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; j ++ ; } } return j ; } function findMissingPositive ( arr , size ) { let i ; for ( i = 0 ; i < size ; i ++ ) { let x = Math . abs ( arr [ i ] ) ; if ( x - 1 < size && arr [ x - 1 ] > 0 ) arr [ x - 1 ] = - arr [ x - 1 ] ; } for ( i = 0 ; i < size ; i ++ ) if ( arr [ i ] > 0 ) return i + 1 ; return size + 1 ; } function findMissing ( arr , size ) { let shift = segregate ( arr , size ) ; let arr2 = new Array ( size - shift ) ; let j = 0 ; for ( let i = shift ; i < size ; i ++ ) { arr2 [ j ] = arr [ i ] ; j ++ ; } return findMissingPositive ( arr2 , j ) ; } let arr = [ 0 , 10 , 2 , - 10 , - 20 ] ; let arr_size = arr . length ; let missing = findMissing ( arr , arr_size ) ; document . write ( " " + missing ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function firstMissingPositive ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { while ( arr [ i ] >= 1 && arr [ i ] <= n && arr [ i ] != arr [ arr [ i ] - 1 ] ) { let temp = arr [ arr [ i ] - 1 ] ; arr [ arr [ i ] - 1 ] = arr [ i ] ; arr [ i ] = temp ; } } for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] != i + 1 ) return ( i + 1 ) ; return ( n + 1 ) ; } let arr = [ 2 , 3 , - 7 , 6 , 8 , 1 , - 10 , 15 ] ; let n = arr . length ; let ans = firstMissingPositive ( arr , n ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function max ( x , y ) { return ( x > y ) ? x : y ; } function maxPathSum ( ar1 , ar2 , m , n ) { let i = 0 , j = 0 ; let result = 0 , sum1 = 0 , sum2 = 0 ; while ( i < m && j < n ) { if ( ar1 [ i ] < ar2 [ j ] ) sum1 += ar1 [ i ++ ] ; else if ( ar1 [ i ] > ar2 [ j ] ) sum2 += ar2 [ j ++ ] ; else { result += Math . max ( sum1 , sum2 ) + ar1 [ i ] ; sum1 = 0 ; sum2 = 0 ; i ++ ; j ++ ; } } while ( i < m ) sum1 += ar1 [ i ++ ] ; while ( j < n ) sum2 += ar2 [ j ++ ] ; result += Math . max ( sum1 , sum2 ) ; return result ; } let ar1 = [ 2 , 3 , 7 , 10 , 12 , 15 , 30 , 34 ] ; let ar2 = [ 1 , 5 , 7 , 8 , 10 , 15 , 16 , 19 ] ; let m = ar1 . length ; let n = ar2 . length ; document . write ( " " + maxPathSum ( ar1 , ar2 , m , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, result, sum1, sum2
Javascript program:
function smallestGreater ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { let diff = Number . MAX_VALUE ; let closest = - 1 ; for ( let j = 0 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] && arr [ j ] - arr [ i ] < diff ) { diff = arr [ j ] - arr [ i ] ; closest = j ; } } if ( closest == - 1 ) document . write ( " " ) ; else document . write ( arr [ closest ] + " " ) ; } } let ar = [ 6 , 3 , 9 , 8 , 10 , 2 , 1 , 15 , 7 ] ; let n = ar . length ; smallestGreater ( ar , n ) ;

Index/key variables: closest, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function smallestGreater ( arr , n ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; let newAr = [ ] ; for ( let p of s . values ( ) ) { newAr . push ( p ) ; } newAr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { let temp = lowerBound ( newAr , 0 , newAr . length , arr [ i ] ) ; if ( temp < n ) document . write ( newAr [ temp ] + " " ) ; else document . write ( " " ) ; } } function lowerBound ( vec , low , high , element ) { let array = [ ... vec ] ; while ( low < high ) { let middle = Math . floor ( low + ( high - low ) / 2 ) ; if ( element > array [ middle ] ) { low = middle + 1 ; } else { high = middle ; } } return low + 1 ; } let ar = [ 6 , 3 , 9 , 8 , 10 , 2 , 1 , 15 , 7 ] ; let n = ar . length ; smallestGreater ( ar , n ) ;

Index/key variables: i, middle, temp
Accumulator variables: i
Iterator variables: i, p
Javascript program:
function findZeroes ( arr , n , m ) { let wL = 0 ; let wR = 0 ; let bestL = 0 ; let bestWindow = 0 ; let zeroCount = 0 ; while ( wR < n ) { if ( zeroCount <= m ) { if ( arr [ wR ] == 0 ) zeroCount ++ ; wR ++ ; } if ( zeroCount > m ) { if ( arr [ wL ] == 0 ) zeroCount -- ; wL ++ ; } if ( ( wR - wL > bestWindow ) && ( zeroCount <= m ) ) { bestWindow = wR - wL ; bestL = wL ; } } for ( let i = 0 ; i < bestWindow ; i ++ ) { if ( arr [ bestL + i ] == 0 ) document . write ( bestL + i + " " ) ; } } let arr = new Array ( 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ) ; let m = 2 ; let n = arr . length ; document . write ( " " ) ; findZeroes ( arr , n , m ) ;

Index/key variables: wL, wR
Accumulator variables: i, wL, wR, zeroCount
Iterator variables: i
Javascript program:
function countIncreasing ( arr , n ) { let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ j - 1 ] ) cnt ++ ; else break ; } } return cnt ; } let arr = [ 1 , 2 , 2 , 4 ] ; let n = arr . length ; document . write ( " " + " " + countIncreasing ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
let arr = [ 1 , 2 , 2 , 4 ] ; function countIncreasing ( n ) { let cnt = 0 ; let len = 1 ; for ( let i = 0 ; i < n - 1 ; ++ i ) { if ( arr [ i + 1 ] > arr [ i ] ) len ++ ; else { cnt += ( ( ( len - 1 ) * len ) / 2 ) ; len = 1 ; } } if ( len > 1 ) cnt += ( ( ( len - 1 ) * len ) / 2 ) ; return cnt ; } document . write ( " " + " " + countIncreasing ( arr . length ) ) ;

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Javascript program:
function arraySum ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum ; } function maxDiff ( arr , n , k ) { arr . sort ( ( a , b ) => a - b ) ; var arraysum = arraySum ( arr , n ) ; var diff1 = Math . abs ( arraysum - 2 * arraySum ( arr , k ) ) ; arr . reverse ( ) ; var diff2 = Math . abs ( arraysum - 2 * arraySum ( arr , k ) ) ; return ( Math . max ( diff1 , diff2 ) ) ; } var arr = [ 1 , 7 , 4 , 8 , - 1 , 5 , 2 , 1 ] ; var n = arr . length ; var k = 3 ; document . write ( " " + maxDiff ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minNumber ( a , n , x ) { a . sort ( ) ; let k ; for ( k = 0 ; a [ parseInt ( ( n - 1 ) / 2 , 10 ) ] != x ; k ++ ) { a [ n ++ ] = x ; a . sort ( ) ; } return k ; } let x = 10 ; let a = [ 10 , 20 , 30 ] ; let n = 3 ; document . write ( minNumber ( a , n , x ) ) ;

Accumulator variables: k, n
Iterator variables: k
Javascript program:
function minNumber ( a , n , x ) { let l = 0 , h = 0 , e = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == x ) e ++ ; else if ( a [ i ] > x ) h ++ ; else if ( a [ i ] < x ) l ++ ; } let ans = 0 ; if ( l > h ) ans = l - h ; else if ( l < h ) ans = h - l - 1 ; return ans + 1 - e ; } let x = 10 ; let a = [ 10 , 20 , 30 ] ; let n = a . length ; document . write ( minNumber ( a , n , x ) ) ;

Index/key variables: i
Accumulator variables: e, h, i, l
Iterator variables: i
Javascript program:
function preprocess ( arr , N , left , right ) { left [ 0 ] = 0 ; let lastIncr = 0 ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) lastIncr = i ; left [ i ] = lastIncr ; } right [ N - 1 ] = N - 1 ; let firstDecr = N - 1 ; for ( let i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) firstDecr = i ; right [ i ] = firstDecr ; } } function isSubarrayMountainForm ( arr , left , right , L , R ) { return ( right [ L ] >= left [ R ] ) ; } let arr = [ 2 , 3 , 2 , 4 , 4 , 6 , 3 , 2 ] ; let N = arr . length ; let left = new Array ( N ) ; let right = new Array ( N ) ; preprocess ( arr , N , left , right ) ; let L = 0 ; let R = 2 ; if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) document . write ( " " + " " + " " ) ; else document . write ( " " + " " + " " ) ; L = 1 ; R = 3 ; if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: L, R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let pre = new Array ( 1000 , 0 ) ; function preCompute ( arr , n ) { pre [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) pre [ i ] = arr [ i ] + pre [ i - 1 ] ; } function rangeSum ( i , j , pre ) { if ( i == 0 ) return pre [ j ] ; return pre [ j ] - pre [ i - 1 ] ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; preCompute ( arr , n ) ; document . write ( rangeSum ( 1 , 3 , pre ) + " " ) ; document . write ( rangeSum ( 2 , 4 , pre ) ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 1000 ; function sieveOfEratosthenes ( isPrime ) { isPrime [ 1 ] = false ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX ; i += p ) isPrime [ i ] = false ; } } } function getMid ( s , e ) { return Math . floor ( s + ( e - s ) / 2 ) ; } function queryPrimesUtil ( st , ss , se , qs , qe , index ) { if ( qs <= ss && qe >= se ) return st [ index ] ; if ( se < qs ss > qe ) return 0 ; let mid = getMid ( ss , se ) ; return queryPrimesUtil ( st , ss , mid , qs , qe , 2 * index + 1 ) + queryPrimesUtil ( st , mid + 1 , se , qs , qe , 2 * index + 2 ) ; } function updateValueUtil ( st , ss , se , i , diff , si ) { if ( i < ss i > se ) return ; st [ si ] = st [ si ] + diff ; if ( se != ss ) { let mid = getMid ( ss , se ) ; updateValueUtil ( st , ss , mid , i , diff , 2 * si + 1 ) ; updateValueUtil ( st , mid + 1 , se , i , diff , 2 * si + 2 ) ; } } function updateValue ( arr , st , n , i , new_val , isPrime ) { if ( i < 0 i > n - 1 ) { document . write ( " " ) ; return ; } let diff = 0 ; let oldValue ; oldValue = arr [ i ] ; arr [ i ] = new_val ; if ( isPrime [ oldValue ] && isPrime [ new_val ] ) return ; if ( ( ! isPrime [ oldValue ] ) && ( ! isPrime [ new_val ] ) ) return ; if ( isPrime [ oldValue ] && ! isPrime [ new_val ] ) { diff = - 1 ; } if ( ! isPrime [ oldValue ] && isPrime [ new_val ] ) { diff = 1 ; } updateValueUtil ( st , 0 , n - 1 , i , diff , 0 ) ; } function queryPrimes ( st , n , qs , qe ) { let primesInRange = queryPrimesUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; document . write ( " " + qs + " " + qe + " " + primesInRange + " " ) ; } function constructSTUtil ( arr , ss , se , st , si , isPrime ) { if ( ss == se ) { if ( isPrime [ arr [ ss ] ] ) st [ si ] = 1 ; else st [ si ] = 0 ; return st [ si ] ; } let mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 , isPrime ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 , isPrime ) ; return st [ si ] ; } function constructST ( arr , n , isPrime ) { let x = ( Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) ) ; let max_size = 2 * Math . pow ( 2 , x ) - 1 ; let st = new Array ( max_size ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 , isPrime ) ; return st ; } let arr = [ 1 , 2 , 3 , 5 , 7 , 9 ] ; let n = arr . length ; let isPrime = new Array ( MAX + 1 ) ; isPrime . fill ( true ) ; sieveOfEratosthenes ( isPrime ) ; let st = constructST ( arr , n , isPrime ) ; let start = 0 ; let end = 4 ; queryPrimes ( st , n , start , end ) ; let i = 3 ; let x = 6 ; updateValue ( arr , st , n , i , x , isPrime ) ; start = 0 ; end = 4 ; queryPrimes ( st , n , start , end ) ;

Index/key variables: i, index, new_val, oldValue, p, si, ss
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function checkEVENodd ( arr , n , l , r ) { if ( arr [ r ] == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 1 , 1 , 0 , 1 ] ; let n = arr . length ; checkEVENodd ( arr , n , 1 , 3 ) ;

Index/key variables: r
Javascript program:
function findMean ( arr , l , r ) { let sum = 0 , count = 0 ; for ( let i = l ; i <= r ; i ++ ) { sum += arr [ i ] ; count ++ ; } let mean = Math . floor ( sum / count ) ; return mean ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; document . write ( findMean ( arr , 0 , 2 ) + " " ) ; document . write ( findMean ( arr , 1 , 3 ) + " " ) ; document . write ( findMean ( arr , 0 , 4 ) + " " ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
let MAX = 1000005 ; let prefixSum = new Array ( MAX ) ; prefixSum . fill ( 0 ) ; function calculatePrefixSum ( arr , n ) { prefixSum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; } function findMean ( l , r ) { if ( l == 0 ) return parseInt ( Math . floor ( prefixSum [ r ] / ( r + 1 ) ) , 10 ) ; return parseInt ( Math . floor ( ( prefixSum [ r ] - prefixSum [ l - 1 ] ) / ( r - l + 1 ) ) , 10 ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; calculatePrefixSum ( arr , n ) ; document . write ( findMean ( 1 , 2 ) + " " ) ; document . write ( findMean ( 1 , 3 ) + " " ) ; document . write ( findMean ( 1 , 4 ) + " " ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function updateQuery ( arr , n , q , l , r , k ) { if ( q == 0 ) { arr [ l - 1 ] += k ; arr [ r ] += - k ; } else { arr [ l - 1 ] += - k ; arr [ r ] += k ; } return ; } function generateArray ( arr , n ) { for ( i = 1 ; i < n ; ++ i ) arr [ i ] += arr [ i - 1 ] ; } var n = 5 ; var arr = Array ( n + 1 ) . fill ( 0 ) ; var q = 0 , l = 1 , r = 3 , k = 2 ; updateQuery ( arr , n , q , l , r , k ) ; q = 1 ; l = 3 ; r = 5 ; k = 3 ; updateQuery ( arr , n , q , l , r , k ) ; q = 0 ; l = 2 ; r = 5 ; k = 1 ; updateQuery ( arr , n , q , l , r , k ) ; generateArray ( arr , n ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateProduct ( A , L , R , P ) { L = L - 1 ; R = R - 1 ; let ans = 1 ; for ( let i = L ; i <= R ; i ++ ) { ans = ans * A [ i ] ; ans = ans % P ; } return ans ; } let A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let P = 229 ; let L = 2 , R = 5 ; document . write ( calculateProduct ( A , L , R , P ) + " " ) ; L = 1 ; R = 3 ; document . write ( calculateProduct ( A , L , R , P ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 100 ; let pre_product = new Array ( MAX ) ; let inverse_product = new Array ( MAX ) ; function modInverse ( a , m ) { let m0 = m , t , q ; let x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = parseInt ( a / m , 10 ) ; t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } function calculate_Pre_Product ( A , N , P ) { pre_product [ 0 ] = A [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { pre_product [ i ] = pre_product [ i - 1 ] * A [ i ] ; pre_product [ i ] = pre_product [ i ] % P ; } } function calculate_inverse_product ( A , N , P ) { inverse_product [ 0 ] = modInverse ( pre_product [ 0 ] , P ) ; for ( let i = 1 ; i < N ; i ++ ) inverse_product [ i ] = modInverse ( pre_product [ i ] , P ) ; } function calculateProduct ( A , L , R , P ) { L = L - 1 ; R = R - 1 ; let ans ; if ( L == 0 ) ans = pre_product [ R ] ; else ans = pre_product [ R ] * inverse_product [ L - 1 ] ; return ans ; } let A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let P = 113 ; calculate_Pre_Product ( A , A . length , P ) ; calculate_inverse_product ( A , A . length , P ) ; let L = 2 , R = 5 ; document . write ( calculateProduct ( A , L , R , P ) + " " ) ; L = 1 ; R = 3 ; document . write ( calculateProduct ( A , L , R , P ) ) ;

Index/key variables: R, i
Accumulator variables: i, x1
Iterator variables: i
Javascript program:
let MAX = 10000 ; let prefix = [ ] ; function buildPrefix ( ) { let prime = [ ] ; for ( let p = 1 ; p <= MAX + 1 ; p ++ ) { prime [ p ] = true ; } for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( let p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] ) prefix [ p ] ++ ; } } function query ( L , R ) { return prefix [ R ] - prefix [ L - 1 ] ; } buildPrefix ( ) ; let L = 5 , R = 10 ; document . write ( query ( L , R ) + " " ) ; L = 1 ; R = 10 ; document . write ( query ( L , R ) ) ;

Index/key variables: R, i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function command ( arr , a , b ) { arr [ a ] ^= 1 ; arr [ b + 1 ] ^= 1 ; } function process ( arr , n ) { for ( var k = 1 ; k <= n ; k ++ ) arr [ k ] ^= arr [ k - 1 ] ; } function result ( arr , n ) { for ( var k = 1 ; k <= n ; k ++ ) document . write ( arr [ k ] + " " ) ; } var n = 5 , m = 3 ; var arr = Array ( n + 2 ) . fill ( 0 ) ; command ( arr , 1 , 5 ) ; command ( arr , 2 , 5 ) ; command ( arr , 3 , 5 ) ; process ( arr , n ) ; result ( arr , n ) ;

Index/key variables: a, k
Accumulator variables: k
Iterator variables: k
Javascript program:
class Interval { constructor ( start , end ) { this . start = start ; this . end = end ; } } function isIntersect ( arr , n ) { arr . sort ( function ( i1 , i2 ) { return i1 . start - i2 . start ; } ) ; for ( let i = 1 ; i < n ; i ++ ) if ( arr [ i - 1 ] . end > arr [ i ] . start ) return true ; return false ; } let arr1 = [ new Interval ( 1 , 3 ) , new Interval ( 7 , 9 ) , new Interval ( 4 , 6 ) , new Interval ( 10 , 13 ) ] ; let n1 = arr1 . length ; if ( isIntersect ( arr1 , n1 ) ) document . write ( " " ) ; else document . write ( " " ) ; let arr2 = [ new Interval ( 6 , 8 ) , new Interval ( 1 , 3 ) , new Interval ( 2 , 4 ) , new Interval ( 4 , 7 ) ] ; let n2 = arr2 . length ; if ( isIntersect ( arr2 , n2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Interval
Javascript program:
class Interval { constructor ( start , end ) { this . start = start ; this . end = end ; } } function isIntersect ( arr , n ) { let max_ele = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( max_ele < arr [ i ] . end ) max_ele = arr [ i ] . end ; } let aux = new Array ( max_ele + 1 ) ; for ( let i = 0 ; i < ( max_ele + 1 ) ; i ++ ) { aux [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let x = arr [ i ] . start ; let y = arr [ i ] . end ; aux [ x ] ++ ; aux [ y ] -- ; } for ( let i = 1 ; i <= max_ele ; i ++ ) { aux [ i ] += aux [ i - 1 ] ; if ( aux [ i ] > 1 ) return true ; } return false ; } let arr1 = [ new Interval ( 1 , 3 ) , new Interval ( 7 , 9 ) , new Interval ( 4 , 6 ) , new Interval ( 10 , 13 ) ] ; let n1 = arr1 . length ; if ( isIntersect ( arr1 , n1 ) ) document . write ( " " ) ; else document . write ( " " ) ; let arr2 = [ new Interval ( 6 , 8 ) , new Interval ( 1 , 3 ) , new Interval ( 2 , 4 ) , new Interval ( 4 , 7 ) ] ; let n2 = arr2 . length ; if ( isIntersect ( arr2 , n2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, x, y
Accumulator variables: i
Iterator variables: i
Class/struct names: Interval
Javascript program:
class query { constructor ( start , end ) { this . start = start ; this . end = end ; } } function incrementByD ( arr , q_arr , n , m , d ) { let sum = new Array ( n ) ; for ( let i = 0 ; i < sum . length ; i ++ ) { sum [ i ] = 0 ; } for ( let i = 0 ; i < m ; i ++ ) { sum [ q_arr [ i ] . start ] += d ; if ( ( q_arr [ i ] . end + 1 ) < n ) sum [ q_arr [ i ] . end + 1 ] -= d ; } arr [ 0 ] += sum [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; arr [ i ] += sum [ i ] ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 3 , 5 , 4 , 8 , 6 , 1 ] ; let q_arr = new Array ( 5 ) ; q_arr [ 0 ] = new query ( 0 , 3 ) ; q_arr [ 1 ] = new query ( 4 , 5 ) ; q_arr [ 2 ] = new query ( 1 , 4 ) ; q_arr [ 3 ] = new query ( 0 , 1 ) ; q_arr [ 4 ] = new query ( 2 , 5 ) ; let n = arr . length ; let m = q_arr . length ; let d = 2 ; document . write ( " " ) ; printArray ( arr , n ) ; incrementByD ( arr , q_arr , n , m , d ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: query
Javascript program:
let MAX = 100000 ; let tree = new Array ( MAX ) ; let lazy = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { tree [ i ] = 0 ; lazy [ i ] = false ; } function toggle ( node , st , en , us , ue ) { if ( lazy [ node ] ) { lazy [ node ] = false ; tree [ node ] = en - st + 1 - tree [ node ] ; if ( st < en ) { lazy [ node << 1 ] = ! lazy [ node << 1 ] ; lazy [ 1 + ( node << 1 ) ] = ! lazy [ 1 + ( node << 1 ) ] ; } } if ( st > en us > en ue < st ) { return ; } if ( us <= st && en <= ue ) { tree [ node ] = en - st + 1 - tree [ node ] ; if ( st < en ) { lazy [ node << 1 ] = ! lazy [ node << 1 ] ; lazy [ 1 + ( node << 1 ) ] = ! lazy [ 1 + ( node << 1 ) ] ; } return ; } let mid = Math . floor ( ( st + en ) / 2 ) ; toggle ( ( node << 1 ) , st , mid , us , ue ) ; toggle ( ( node << 1 ) + 1 , mid + 1 , en , us , ue ) ; if ( st < en ) { tree [ node ] = tree [ node << 1 ] + tree [ ( node << 1 ) + 1 ] ; } } function countQuery ( node , st , en , qs , qe ) { if ( st > en qs > en qe < st ) { return 0 ; } if ( lazy [ node ] ) { lazy [ node ] = false ; tree [ node ] = en - st + 1 - tree [ node ] ; if ( st < en ) { lazy [ node << 1 ] = ! lazy [ node << 1 ] ; lazy [ ( node << 1 ) + 1 ] = ! lazy [ ( node << 1 ) + 1 ] ; } } if ( qs <= st && en <= qe ) { return tree [ node ] ; } let mid = Math . floor ( ( st + en ) / 2 ) ; return countQuery ( ( node << 1 ) , st , mid , qs , qe ) + countQuery ( ( node << 1 ) + 1 , mid + 1 , en , qs , qe ) ; } let n = 5 ; toggle ( 1 , 0 , n - 1 , 1 , 2 ) ; toggle ( 1 , 0 , n - 1 , 2 , 4 ) ; document . write ( countQuery ( 1 , 0 , n - 1 , 2 , 3 ) + " " ) ; toggle ( 1 , 0 , n - 1 , 2 , 4 ) ; document . write ( countQuery ( 1 , 0 , n - 1 , 1 , 4 ) + " " ) ;

Index/key variables: i, node
Accumulator variables: i
Iterator variables: i
Javascript program:
function probability ( a , b , size1 , size2 ) { let max1 = Number . MIN_VALUE , count1 = 0 ; for ( let i = 0 ; i < size1 ; i ++ ) { if ( a [ i ] > max1 ) { max1 = a [ i ] ; count1 = 1 ; } else if ( a [ i ] == max1 ) { count1 ++ ; } } let max2 = Number . MIN_VALUE , count2 = 0 ; for ( let i = 0 ; i < size2 ; i ++ ) { if ( b [ i ] > max2 ) { max2 = b [ i ] ; count2 = 1 ; } else if ( b [ i ] == max2 ) { count2 ++ ; } } return ( count1 * count2 ) / ( size1 * size2 ) ; } let a = [ 1 , 2 , 3 ] ; let b = [ 1 , 3 , 3 ] ; let size1 = a . length ; let size2 = b . length ; document . write ( probability ( a , b , size1 , size2 ) ) ;

Index/key variables: i
Accumulator variables: count1, count2, i
Iterator variables: i
Javascript program:
function countDe ( arr , n ) { let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) v [ i ] = arr [ i ] ; arr . sort ( ) ; let count1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] != v [ i ] ) count1 ++ ; arr . reverse ( ) ; let count2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] != v [ i ] ) count2 ++ ; return ( Math . min ( count1 , count2 ) ) ; } let arr = [ 5 , 9 , 21 , 17 , 13 ] ; let n = 5 ; document . write ( " " + countDe ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count1, count2, i
Iterator variables: i