dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function lenOfLongZigZagArr ( a , n ) { var max = 1 , len = 1 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( i % 2 == 0 && ( a [ i ] < a [ i + 1 ] ) ) len ++ ; else if ( i % 2 == 1 && ( a [ i ] > a [ i + 1 ] ) ) len ++ ; else { if ( max < len ) max = len ; len = 1 ; } } if ( max < len ) max = len ; return max ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; document . write ( lenOfLongZigZagArr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Javascript program:
function minpoint ( arr , n , k ) { let min_point = 0 ; for ( let i = 1 ; i < k - 1 ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) min_point += 1 ; } let final_point = min_point ; for ( let i = k ; i < n ; i ++ ) { if ( arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) + 1 ] && arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) - 1 ] ) min_point -= 1 ; if ( arr [ i - 1 ] < arr [ i ] && arr [ i - 1 ] < arr [ i - 2 ] ) min_point += 1 ; if ( min_point > final_point ) final_point = min_point ; } document . write ( final_point ) ; } let arr = [ 2 , 1 , 4 , 2 , 3 , 4 , 1 , 2 ] ; let n = arr . length ; let k = 4 ; minpoint ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i, min_point
Iterator variables: i
Javascript program:
function findSubArray ( a , n , k ) { let pref = new Array ( n ) ; pref [ 0 ] = 0 ; for ( let i = 1 ; i < n - 1 ; ++ i ) { pref [ i ] = pref [ i - 1 ] ; if ( a [ i ] > a [ i - 1 ] && a [ i ] > a [ i + 1 ] ) pref [ i ] ++ ; } let peak = 0 , left = 0 ; for ( let i = 0 ; i + k - 1 < n ; ++ i ) if ( pref [ i + k - 2 ] - pref [ i ] > peak ) { peak = pref [ i + k - 2 ] - pref [ i ] ; left = i ; } document . write ( " " + ( left + 1 ) + " " ) ; document . write ( " " + ( left + k ) + " " ) ; document . write ( " " + peak + " " ) ; } let arr = [ 3 , 2 , 3 , 2 , 1 ] ; let n = arr . length ; let k = 3 ; findSubArray ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function countTriplets ( a , n , x ) { var answer = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { for ( var k = j + 1 ; k < n ; k ++ ) { var temp = [ ] ; temp . push ( a [ i ] ) ; temp . push ( a [ j ] ) ; temp . push ( a [ k ] ) ; temp . sort ( ( a , b ) => a - b ) if ( temp [ 0 ] < temp [ 1 ] && temp [ 1 ] < temp [ 2 ] && temp [ 0 ] * temp [ 1 ] * temp [ 2 ] <= x ) answer ++ ; } } } return answer ; } var A = [ 3 , 2 , 5 , 7 ] ; var N = A . length ; var X = 42 ; document . write ( countTriplets ( A , N , X ) ) ;

Index/key variables: i, j, k
Accumulator variables: answer, i, j, k
Iterator variables: i, j, k
Javascript program:
function findMaxMatrixSize ( arr , K ) { let i , j ; let n = arr . length ; let m = arr [ 0 ] . length ; let sum = [ ] ; for ( i = 0 ; i < n + 1 ; i ++ ) { sum [ i ] = [ ] ; for ( j = 0 ; j < m + 1 ; j ++ ) { sum [ i ] [ j ] = 0 ; } } for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= m ; j ++ ) { if ( i == 0 j == 0 ) { sum [ i ] [ j ] = 0 ; continue ; } sum [ i ] [ j ] = arr [ i - 1 ] [ j - 1 ] + sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] ; } } let ans = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { if ( i + ans - 1 > n j + ans - 1 > m ) break ; let mid , lo = ans ; let hi = Math . min ( n - i + 1 , m - j + 1 ) ; while ( lo < hi ) { mid = Math . floor ( ( hi + lo + 1 ) / 2 ) ; if ( sum [ i + mid - 1 ] [ j + mid - 1 ] + sum [ i - 1 ] [ j - 1 ] - sum [ i + mid - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j + mid - 1 ] <= K ) { lo = mid ; } else { hi = mid - 1 ; } } ans = Math . max ( ans , lo ) ; } } document . write ( ans , ' ' ) ; } let arr = [ [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] , [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] , [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] ] ; let K = 4 ; findMaxMatrixSize ( arr , K ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function FindRank ( arr , length ) { document . write ( " " + " " ) ; for ( i = 1 ; i < arr . length ; i ++ ) { var rank = 1 ; for ( j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) rank ++ ; } document . write ( rank + " " ) ; } } var arr = [ 88 , 14 , 69 , 30 , 29 , 89 ] ; var len = arr . length ; FindRank ( arr , len ) ;

Index/key variables: i, j
Accumulator variables: i, j, rank
Iterator variables: i, j
Javascript program:
function longestPermutation ( arr , n ) { let freq = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } let len = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( ! freq . has ( i ) ) { break ; } len ++ ; } return len ; } let arr = [ 3 , 2 , 1 , 6 , 5 ] ; let n = arr . length ; document . write ( longestPermutation ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Javascript program:
let MAX = 1000005 ; let fib = new Set ( ) ; function fibonacci ( ) { let prev = 0 , curr = 1 , len = 2 ; fib . add ( prev ) ; fib . add ( curr ) ; while ( len <= MAX ) { let temp = curr + prev ; fib . add ( temp ) ; prev = curr ; curr = temp ; len ++ ; } } function findFibonacci ( N ) { for ( let i = Math . floor ( N / 2 ) ; i > 1 ; i -- ) { if ( fib . has ( i ) && fib . has ( N - i ) ) { document . write ( i + " " + ( N - i ) ) ; return ; } } document . write ( " " ) ; } fibonacci ( ) ; let sum = 199 ; findFibonacci ( sum ) ;

Accumulator variables: i, len
Iterator variables: i
Javascript program:
let MAX = 100005 ; let fibonacci = new Set ( ) ; function createHash ( ) { let prev = 0 , curr = 1 ; fibonacci . add ( prev ) ; fibonacci . add ( curr ) ; while ( curr <= MAX ) { let temp = curr + prev ; fibonacci . add ( temp ) ; prev = curr ; curr = temp ; } } function checkArray ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( fibonacci . has ( arr [ i ] ) ) sum += arr [ i ] ; if ( fibonacci . has ( sum ) ) return true ; return false ; } let arr = [ 1 , 2 , 4 , 8 , 2 ] ; let n = arr . length ; createHash ( ) ; if ( checkArray ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let MAX = 1000005 ; let fibUpto = new Array ( MAX + 1 ) ; function compute ( sz ) { let isFib = new Array ( sz + 1 ) ; let prev = 0 , curr = 1 ; isFib [ prev ] = isFib [ curr ] = true ; while ( curr <= sz ) { let temp = curr + prev ; if ( temp <= sz ) isFib [ temp ] = true ; prev = curr ; curr = temp ; } fibUpto [ 0 ] = 1 ; for ( let i = 1 ; i <= sz ; i ++ ) { fibUpto [ i ] = fibUpto [ i - 1 ] ; if ( isFib [ i ] ) fibUpto [ i ] ++ ; } } function countOfNumbers ( N , K ) { compute ( N ) ; let low = 1 , high = N , ans = 0 ; while ( low <= high ) { let mid = ( low + high ) >> 1 ; if ( mid - fibUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ( ans > 0 ? N - ans + 1 : 0 ) ; } let N = 10 , K = 3 ; document . write ( countOfNumbers ( N , K ) ) ;

Index/key variables: curr, i, mid, prev, temp
Accumulator variables: i
Iterator variables: i
Javascript program:
var N = 100001 ; var f = Array . from ( Array ( 26 ) , ( ) => Array ( N ) . fill ( 0 ) ) ; function precompute ( s , n ) { for ( var i = 0 ; i < n ; i ++ ) { f [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ i ] ++ ; } for ( var i = 0 ; i < 26 ; i ++ ) { for ( var j = 1 ; j < n ; j ++ ) { f [ i ] [ j ] += f [ i ] [ j - 1 ] ; } } } function palindromicSubsequencesUtil ( L , R ) { var c , ok = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) { var cnt = f [ i ] [ R ] ; if ( L > 0 ) cnt -= f [ i ] [ L - 1 ] ; if ( cnt > 1 ) { ok = 1 ; c = i ; break ; } } if ( ok == 0 ) { return - 1 ; } return c ; } function palindromicSubsequences ( Q , l ) { for ( var i = 0 ; i < l ; i ++ ) { var x = palindromicSubsequencesUtil ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; if ( x == - 1 ) { document . write ( - 1 + " " ) ; } else { var c = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + x ) ; document . write ( c + c + " " ) ; } } } var str = " " ; var Q = [ [ 0 , 5 ] , [ 1 , 5 ] , [ 1 , 3 ] ] ; var n = str . length ; var l = Q . length ; precompute ( str , n ) ; palindromicSubsequences ( Q , l ) ;

Index/key variables: R, i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
let N = 100000 ; function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function longestFibSubarray ( arr , n ) { let max_val = Math . max ( ... arr ) ; let hash = new Set ( ) ; createHash ( hash , max_val ) ; let left = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let right = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let fibcount = 0 , res = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { left [ i ] = fibcount ; if ( hash . has ( arr [ i ] ) ) { fibcount ++ ; } else fibcount = 0 ; } fibcount = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { right [ i ] = fibcount ; if ( hash . has ( arr [ i ] ) ) { fibcount ++ ; } else fibcount = 0 ; } for ( let i = 0 ; i < n ; i ++ ) res = Math . max ( res , left [ i ] + right [ i ] ) ; return res ; } let arr = [ 2 , 8 , 5 , 7 , 3 , 5 , 7 ] ; let n = arr . length ; document . write ( longestFibSubarray ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: fibcount, i
Iterator variables: i
Javascript program:
function isPrime ( N ) { if ( N < 2 ) return false ; if ( N < 4 ) return true ; if ( ( N & 1 ) == 0 ) return false ; if ( N % 3 == 0 ) return false ; let curr = 5 , s = Math . floor ( Math . sqrt ( N ) ) ; while ( curr <= s ) { if ( N % curr == 0 ) return false ; curr += 2 ; if ( N % curr == 0 ) return false ; curr += 4 ; } return true ; } function check ( s , p , prefix_sum , n ) { let satisfies = true ; for ( let i = 0 ; i < n ; i ++ ) { if ( i + s - 1 >= n ) break ; if ( prefix_sum [ i + s - 1 ] - ( i - 1 >= 0 ? prefix_sum [ i - 1 ] : 0 ) < p ) satisfies = false ; } return satisfies ; } function minimumWindowSize ( x , y , p ) { let prefix_sum = new Array ( y - x + 1 ) . fill ( 0 ) ; for ( let i = x ; i <= y ; i ++ ) { if ( isPrime ( i ) ) prefix_sum [ i - x ] = 1 ; } for ( let i = 1 ; i < y - x + 1 ; i ++ ) prefix_sum [ i ] += prefix_sum [ i - 1 ] ; let low = 1 , high = y - x + 1 ; let mid ; while ( high - low > 1 ) { mid = Math . floor ( ( low + high ) / 2 ) ; if ( check ( mid , p , prefix_sum , y - x + 1 ) ) { high = mid ; } else low = mid ; } if ( check ( low , p , prefix_sum , y - x + 1 ) ) return low ; return high ; } let x = 12 ; let y = 42 ; let p = 3 ; document . write ( minimumWindowSize ( x , y , p ) ) ;

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: i
Boolean variables: satisfies
Javascript program:
function xorOfSum ( a , n ) { let answer = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) answer ^= ( a [ i ] + a [ j ] ) ; } return answer ; } let n = 3 ; let A = [ 1 , 2 , 3 ] ; document . write ( xorOfSum ( A , n ) ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
let N = 4 ; let M = 5 ; function preProcess ( mat , aux ) { for ( let i = 0 ; i < M ; i ++ ) aux [ 0 ] [ i ] = mat [ 0 ] [ i ] ; for ( let i = 1 ; i < N ; i ++ ) for ( let j = 0 ; j < M ; j ++ ) aux [ i ] [ j ] = mat [ i ] [ j ] + aux [ i - 1 ] [ j ] ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 1 ; j < M ; j ++ ) aux [ i ] [ j ] += aux [ i ] [ j - 1 ] ; } function sumQuery ( aux , tli , tlj , rbi , rbj ) { let res = aux [ rbi ] [ rbj ] ; if ( tli > 0 ) res = res - aux [ tli - 1 ] [ rbj ] ; if ( tlj > 0 ) res = res - aux [ rbi ] [ tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + aux [ tli - 1 ] [ tlj - 1 ] ; return res ; } function maximumSquareSize ( mat , k ) { let aux = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { aux [ i ] = new Array ( M ) ; } preProcess ( mat , aux ) ; for ( let i = Math . min ( N , M ) ; i >= 1 ; i -- ) { let satisfies = true ; for ( let x = 0 ; x < N ; x ++ ) { for ( let y = 0 ; y < M ; y ++ ) { if ( x + i - 1 <= N - 1 && y + i - 1 <= M - 1 ) { if ( sumQuery ( aux , x , y , x + i - 1 , y + i - 1 ) > K ) satisfies = false ; } } } if ( satisfies == true ) return ( i ) ; } return 0 ; } let mat = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 5 , 3 , 8 , 1 , 2 ] , [ 4 , 6 , 7 , 5 , 5 ] , [ 2 , 4 , 8 , 9 , 4 ] ] ; let K = 30 ; document . write ( maximumSquareSize ( mat , K ) ) ;

Index/key variables: i, j, rbi, rbj
Accumulator variables: i, j, x, y
Iterator variables: i, j, x, y
Boolean variables: satisfies
Javascript program:
function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr < maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function findFibonacciPair ( n ) { let hash = new Set ( ) ; createHash ( hash , n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( hash . has ( i ) && hash . has ( n - i ) ) { document . write ( i + " " + ( n - i ) + " " ) ; return ; } } document . write ( " " + " " ) ; } let N = 90 ; findFibonacciPair ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function add_factors ( n , mp ) { for ( var i = 1 ; i <= parseInt ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( parseInt ( n / i ) == i ) { if ( mp . has ( i ) ) mp . set ( i , mp . get ( i ) + 1 ) else mp . set ( i , 1 ) } else { if ( mp . has ( i ) ) mp . set ( i , mp . get ( i ) + 1 ) else mp . set ( i , 1 ) if ( mp . has ( parseInt ( n / i ) ) ) mp . set ( parseInt ( n / i ) , mp . get ( parseInt ( n / i ) ) + 1 ) else mp . set ( parseInt ( n / i ) , 1 ) } } } return mp ; } function count_divisors ( a , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( ( mp . has ( a [ i ] ) ? mp . get ( a [ i ] ) : 0 ) + " " ) ; mp = add_factors ( a [ i ] , mp ) ; } } var arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] ; var n = arr . length ; count_divisors ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function removeDuplicates ( arr , n ) { let st = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i < n - 2 && arr [ i ] == arr [ i + 1 ] && arr [ i ] == arr [ i + 2 ] ) continue ; else { arr [ st ] = arr [ i ] ; st ++ ; } } document . write ( " " ) ; for ( let i = 0 ; i < st ; i ++ ) { document . write ( arr [ i ] ) ; if ( i != st - 1 ) document . write ( " " ) ; } document . write ( " " ) ; } let arr = [ 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 5 ] ; let n = arr . length ; removeDuplicates ( arr , n ) ;

Index/key variables: i, st
Accumulator variables: i, st
Iterator variables: i
Javascript program:
function permutation ( arr , n ) { let hash = new Set ( ) ; let maxEle = 0 ; for ( let i = 0 ; i < n ; i ++ ) { hash . add ( arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } if ( maxEle != n ) return false ; if ( hash . length == n ) return true ; return false ; } let arr = [ 1 , 2 , 5 , 3 , 2 ] ; let n = arr . length ; if ( permutation ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CountSubSet ( arr , n , X ) { let N = Math . pow ( 2 , n ) ; let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) if ( arr [ j ] == X ) count += 1 ; } } return count ; } let arr = [ 4 , 5 , 6 , 7 ] ; let X = 5 ; let n = arr . length ; document . write ( CountSubSet ( arr , n , X ) ) ;

Index/key variables: j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function calculatePower ( b , e ) { let ans = 1 ; while ( e > 0 ) { if ( e % 2 == 1 ) ans = ans * b ; e = e / 2 ; b = b * b ; } return ans ; } function CountSubSet ( arr , n , X ) { let count = 0 , checkX = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == X ) { checkX = 1 ; break ; } } if ( checkX == 1 ) count = calculatePower ( 2 , n - 1 ) ; else count = 0 ; return count ; } let arr = [ 4 , 5 , 6 , 7 ] ; let X = 5 ; let n = arr . length ; document . write ( CountSubSet ( arr , n , X ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function woodCollected ( height , n , m ) { let sum = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] - m <= 0 ) break ; sum += ( height [ i ] - m ) ; } return sum ; } function collectKWood ( height , n , k ) { height . sort ( ( a , b ) => a - b ) ; let low = 0 , high = height [ n - 1 ] ; while ( low <= high ) { let mid = low + ( ( high - low ) / 2 ) ; let collected = woodCollected ( height , n , mid ) ; if ( collected == k ) return mid ; if ( collected > k ) low = mid + 1 ; else high = mid - 1 ; } return - 1 ; } let height = [ 1 , 2 , 1 , 2 ] ; let n = height . length ; let k = 2 ; document . write ( collectKWood ( height , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let MAX = 10 ; function isDigit ( ch ) { if ( ch >= ' ' && ch <= ' ' ) return true ; return false ; } function allDigits ( str , len ) { let present = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < len ; i ++ ) { if ( isDigit ( str [ i ] ) ) { let digit = str [ i ] - ' ' ; present [ digit ] = true ; } } for ( let i = 0 ; i < MAX ; i ++ ) { if ( ! present [ i ] ) return false ; } return true ; } let str = " " ; let len = str . length ; if ( allDigits ( str , len ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: digit, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPlusPossible ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) } var foundModOne = false ; var ans = true ; mp . forEach ( ( value , key ) => { var element = key ; var frequency = value ; if ( frequency % 4 != 0 ) { if ( frequency % 4 == 1 ) { if ( foundModOne ) ans = false foundModOne = true ; } else ans = false } } ) ; return ans ; } var arr = [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 ] ; var n = arr . length ; if ( isPlusPossible ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: ans, foundModOne
Javascript program:
function merge ( v1 , v2 ) { let i = 0 , j = 0 ; let v = new Array ( ) ; while ( i < v1 . length && j < v2 . length ) { if ( v1 [ i ] <= v2 [ j ] ) { v . push ( v1 [ i ] ) ; i ++ ; } else { v . push ( v2 [ j ] ) ; j ++ ; } } for ( let k = i ; k < v1 . length ; k ++ ) v . push ( v1 [ k ] ) ; for ( let k = j ; k < v2 . length ; k ++ ) v . push ( v2 [ k ] ) ; return v ; } function buildTree ( tree , arr , index , s , e ) { if ( s == e ) { tree [ index ] . push ( arr [ s ] ) ; return ; } let mid = Math . floor ( ( s + e ) / 2 ) ; buildTree ( tree , arr , 2 * index , s , mid ) ; buildTree ( tree , arr , 2 * index + 1 , mid + 1 , e ) ; tree [ index ] = merge ( tree [ 2 * index ] , tree [ 2 * index + 1 ] ) ; } function query ( tree , index , s , e , l , r , k ) { if ( r < s l > e ) return 0 ; if ( s >= l && e <= r ) { return ( tree [ index ] . length - ( lowerBound ( tree [ index ] , tree [ index ] . length , k ) ) ) ; } let mid = Math . floor ( ( s + e ) / 2 ) ; return ( query ( tree , 2 * index , s , mid , l , r , k ) + query ( tree , 2 * index + 1 , mid + 1 , e , l , r , k ) ) ; } function lowerBound ( array , length , value ) { let low = 0 ; let high = length ; while ( low < high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( value <= array [ mid ] ) { high = mid ; } else { low = mid + 1 ; } } return low ; } function performQueries ( L , R , K , n , q , tree ) { for ( let i = 0 ; i < q ; i ++ ) { document . write ( query ( tree , 1 , 0 , n - 1 , L [ i ] - 1 , R [ i ] - 1 , K [ i ] ) + " " ) ; } } let arr = [ 7 , 3 , 9 , 13 , 5 , 4 ] ; let n = arr . length ; let tree = new Array ( ) ; for ( let i = 0 ; i < 4 * n + 1 ; i ++ ) { tree . push ( [ ] ) } buildTree ( tree , arr , 1 , 0 , n - 1 ) ; let L = [ 1 , 2 ] ; let R = [ 4 , 6 ] ; let K = [ 6 , 8 ] ; let q = L . length ; performQueries ( L , R , K , n , q , tree ) ;

Index/key variables: i, index, j, k, mid, s
Accumulator variables: i, j, k
Iterator variables: i, k
Javascript program:
function findGCDSum ( n , a ) { var GCDSum = 0 ; var tempGCD = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i ; j < n ; j ++ ) { tempGCD = 0 ; for ( k = i ; k <= j ; k ++ ) { tempGCD = __gcd ( tempGCD , a [ k ] ) ; } GCDSum += tempGCD ; } } return GCDSum ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var n = 5 ; var a = [ 1 , 2 , 3 , 4 , 5 ] ; var totalSum = findGCDSum ( n , a ) ; document . write ( totalSum + " " ) ;

Index/key variables: k
Accumulator variables: GCDSum, i, j, k
Iterator variables: i, j, k
Javascript program:
function containsElement ( arr , n ) { let xorArr = 0 ; for ( let i = 0 ; i < n ; ++ i ) xorArr ^= arr [ i ] ; for ( let i = 0 ; i < n ; ++ i ) { let x = xorArr ^ arr [ i ] ; if ( arr [ i ] == x ) return true ; } return false ; } let arr = [ 8 , 2 , 4 , 15 , 1 ] ; let n = arr . length ; if ( containsElement ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: xorArr
Iterator variables: i
Javascript program:
function maxSum ( arr , k ) { arr . sort ( ( a , b ) => a - b ) ; var n = arr . length , l = 0 , r = n - 1 , ans = 0 ; while ( l < r ) { if ( arr [ l ] + arr [ r ] < k ) { ans = Math . max ( ans , arr [ l ] + arr [ r ] ) ; l ++ ; } else { r -- ; } } return ans ; } var A = [ 20 , 10 , 30 , 100 , 110 ] ; var k = 85 ; document . write ( maxSum ( A , k ) ) ;

Index/key variables: l, r
Accumulator variables: l, r
Javascript program:
function length_substring ( S , K ) { let curr_cnt = 0 , prev_cnt = 0 , max_len ; for ( let i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] == K ) { curr_cnt += 1 ; } else { prev_cnt = Math . max ( prev_cnt , curr_cnt ) ; curr_cnt = 0 ; } } prev_cnt = Math . max ( prev_cnt , curr_cnt ) ; max_len = prev_cnt ; return max_len ; } let S = " " ; let K = ' ' ; document . write ( length_substring ( S , K ) ) ;

Index/key variables: i
Accumulator variables: curr_cnt, i
Iterator variables: i
Javascript program:
function Xor_Sum ( arr , n ) { let sum = 0 , index , left_xor = 0 , right_xor = 0 ; for ( let i = 0 ; i < n ; i ++ ) { left_xor = left_xor ^ arr [ i ] ; right_xor = 0 ; for ( let j = i + 1 ; j < n ; j ++ ) { right_xor = right_xor ^ arr [ j ] ; } if ( left_xor + right_xor > sum ) { sum = left_xor + right_xor ; index = i ; } } return index + 1 ; } let arr = [ 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 ] ; let n = arr . length ; document . write ( Xor_Sum ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function ComputePrefixXor ( arr , PrefixXor , n ) { PrefixXor [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; } function Xor_Sum ( arr , n ) { let PrefixXor = new Array ( n ) ; ComputePrefixXor ( arr , PrefixXor , n ) ; let sum = 0 , index ; for ( let i = 0 ; i < n ; i ++ ) { if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) { sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; index = i ; } } return index + 1 ; } let arr = [ 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 ] ; let n = arr . length ; document . write ( Xor_Sum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findColor ( mapWithColor , query ) { let maximum = 0 ; while ( query >= 1 ) { if ( mapWithColor . has ( query ) ) { maximum = Math . max ( maximum , mapWithColor . get ( query ) ) ; } if ( query % 2 == 1 ) query = ( query - 1 ) / 2 ; else query = query / 2 ; } return maximum ; } function buildMapWithColor ( arr , n ) { let mapWithColor = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mapWithColor . set ( arr [ i ] , i + 1 ) ; } return mapWithColor ; } let arr = [ 3 , 2 , 1 , 3 ] ; let n = arr . length ; let k = 7 ; let mapWithColor = buildMapWithColor ( arr , n ) ; document . write ( findColor ( mapWithColor , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i