dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function largest ( arr ) { let i ; let max = arr [ 0 ] ; for ( i = 1 ; i < arr . length ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } return max ; } let arr = [ 10 , 324 , 45 , 90 , 9808 ] ; document . write ( " " + largest ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumsteps ( N ) { let steps = 0 ; while ( steps * ( steps + 1 ) < 2 * N ) { steps ++ ; } if ( steps * Math . floor ( ( steps + 1 ) / 2 ) == N + 1 ) { steps ++ ; } document . write ( steps ) ; } let N = 18 ; minimumsteps ( N ) ;

Accumulator variables: steps
Javascript program:
function find3largest ( arr ) { arr . sort ( ( a , b ) => a - b ) ; let check = 0 , count = 1 ; for ( let i = 1 ; i <= arr . length ; i ++ ) { if ( count < 4 ) { if ( check != arr [ arr . length - i ] ) { document . write ( arr [ arr . length - i ] + " " ) ; check = arr [ arr . length - i ] ; count ++ ; } } else break ; } } let arr = [ 12 , 45 , 1 , - 1 , 45 , 54 , 23 , 5 , 0 , - 10 ] ; find3largest ( arr ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minCntCharDeletionsfrequency ( str , N ) { let mp = new Map ( ) ; let pq = [ ] ; let cntChar = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( mp . has ( str [ i ] ) ) { mp . set ( str [ i ] , mp . get ( str [ i ] ) + 1 ) ; } else { mp . set ( str [ i ] , 1 ) ; } } for ( let [ key , value ] of mp . entries ( ) ) { pq . push ( value ) ; } pq . sort ( function ( a , b ) { return b - a ; } ) ; while ( pq . length != 0 ) { let frequent = pq [ 0 ] ; pq . shift ( ) ; if ( pq . length == 0 ) { return cntChar ; } if ( frequent == pq [ 0 ] ) { if ( frequent > 1 ) { pq . push ( frequent - 1 ) ; pq . sort ( function ( a , b ) { return b - a ; } ) ; } cntChar ++ ; } } return cntChar ; } let str = " " ; let N = str . length ; document . write ( minCntCharDeletionsfrequency ( str . split ( " " ) , N ) ) ;

Index/key variables: i
Accumulator variables: cntChar, i
Iterator variables: i
Javascript program:
function issafe ( v , i , j , n , m , ch ) { let rowN = [ 1 , - 1 , 0 , 0 ] ; let colN = [ 0 , 0 , 1 , - 1 ] ; for ( let k = 0 ; k < 4 ; k ++ ) { if ( i + rowN [ k ] >= 0 && i + rowN [ k ] < n && j + colN [ k ] >= 0 && j + colN [ k ] < m && v [ i + rowN [ k ] ] [ j + colN [ k ] ] == ch ) { return false ; } } return true ; } function place ( v , n , m ) { let i = 0 , j = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( v [ i ] [ j ] == ' ' ) { break ; } } if ( j != m ) { break ; } } if ( i == n && j == m ) { return true ; } if ( issafe ( v , i , j , n , m , ' ' ) ) { v [ i ] [ j ] = ' ' ; if ( place ( v , n , m ) ) { return true ; } v [ i ] [ j ] = ' ' ; } if ( issafe ( v , i , j , n , m , ' ' ) ) { v [ i ] [ j ] = ' ' ; if ( place ( v , n , m ) ) { return true ; } v [ i ] [ j ] = ' ' ; } return false ; } function printMatrix ( arr , n , m ) { place ( arr , n , m ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { document . write ( arr [ i ] [ j ] ) ; } document . write ( " " ) ; } } let arr = [ [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , ] ; let n = 4 , m = 4 ; printMatrix ( arr , n , m ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findMean ( a , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += a [ i ] ; return sum / n ; } function findMedian ( a , n ) { a . sort ( ) ; if ( n % 2 != 0 ) return a [ n / 2 ] ; return ( a [ Math . floor ( ( n - 1 ) / 2 ) ] + a [ n / 2 ] ) / 2 ; } let a = [ 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 ] let n = a . length ; document . write ( " " + findMean ( a , n ) + " " ) ; document . write ( " " + findMedian ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findMax ( a , dp , i , flag ) { if ( i == a . length ) { return 0 ; } if ( dp [ i ] [ flag ] != - 1 ) { return dp [ i ] [ flag ] ; } let ans ; if ( flag == 0 ) { ans = Math . max ( findMax ( a , dp , i + 1 , 0 ) , a [ i ] + findMax ( a , dp , i + 1 , 1 ) ) ; } else { ans = Math . max ( findMax ( a , dp , i + 1 , 1 ) , - 1 * a [ i ] + findMax ( a , dp , i + 1 , 0 ) ) ; } return dp [ i ] [ flag ] = ans ; } function findMaxSumUtil ( arr , N ) { let dp = new Array ( N ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( findMax ( arr , dp , 0 , 0 ) ) ; } let arr = [ 1 , 2 , 3 , 4 , 1 , 2 ] ; let N = arr . length ; findMaxSumUtil ( arr , N ) ;

Index/key variables: flag, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findWinner ( s ) { var vowels_count = 0 , consonants_count = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] === " " s [ i ] === " " s [ i ] === " " s [ i ] === " " s [ i ] === " " ) { vowels_count ++ ; } else { consonants_count ++ ; } } if ( vowels_count === 0 ) { if ( consonants_count % 2 === 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } else if ( vowels_count === 1 && consonants_count % 2 !== 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var s = " " ; findWinner ( s ) ;

Index/key variables: i
Accumulator variables: consonants_count, i, vowels_count
Iterator variables: i
Javascript program:
function getSmallestArray ( A , B ) { let arr = [ ] ; for ( let i = 0 ; i < A ; i ++ ) arr [ i ] = i + 1 ; let ans = [ ] ; for ( let i = 0 ; i < A ; i ++ ) ans . push ( 0 ) ; for ( let i = 0 ; i < B - 1 ; i ++ ) ans [ i ] = arr [ i ] ; ans [ B - 1 ] = arr [ A - 1 ] ; for ( let i = B ; i < A ; i ++ ) ans [ i ] = arr [ i - 1 ] ; return ans ; } let A = 3 ; let B = 2 ; let ans = getSmallestArray ( A , B ) ; for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] , " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printSmall ( arr , n , k ) { for ( let i = k ; i < n ; ++ i ) { let max_var = arr [ k - 1 ] ; let pos = k - 1 ; for ( let j = k - 2 ; j >= 0 ; j -- ) { if ( arr [ j ] > max_var ) { max_var = arr [ j ] ; pos = j ; } } if ( max_var > arr [ i ] ) { let j = pos ; while ( j < k - 1 ) { arr [ j ] = arr [ j + 1 ] ; j ++ ; } arr [ k - 1 ] = arr [ i ] ; } } for ( let i = 0 ; i < k ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] ; let n = 10 ; let k = 5 ; printSmall ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) { if ( k > n1 * n2 ) { document . write ( " " ) ; return ; } let index2 = new Array ( n1 ) ; index2 . fill ( 0 ) ; while ( k > 0 ) { let min_sum = Number . MAX_VALUE ; let min_index = 0 ; for ( let i1 = 0 ; i1 < n1 ; i1 ++ ) { if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) { min_index = i1 ; min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ; } } document . write ( " " + arr1 [ min_index ] + " " + arr2 [ index2 [ min_index ] ] + " " ) ; index2 [ min_index ] ++ ; k -- ; } } let arr1 = [ 1 , 3 , 11 ] ; let n1 = arr1 . length ; let arr2 = [ 2 , 4 , 8 ] ; let n2 = arr2 . length ; let k = 4 ; kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) ;

Index/key variables: i1, min_index
Accumulator variables: i1, k
Iterator variables: i1
Javascript program:
function comp ( a , b ) { return a > b ; } function maxSubset ( arr , N , X ) { arr = arr . sort ( ( a , b ) => b - a ) ; let counter = 0 ; let sz = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sz ++ ; if ( arr [ i ] * sz >= X ) { counter ++ ; sz = 0 ; } } return counter ; } let arr = [ 7 , 11 , 2 , 9 , 5 ] ; let N = arr . length ; let X = 10 ; document . write ( maxSubset ( arr , N , X ) ) ;

Index/key variables: i
Accumulator variables: counter, i, sz
Iterator variables: i
Javascript program:
function maximumModuloValue ( A , n ) { var mn = Number . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { mn = Math . min ( A [ i ] , mn ) ; } return mn ; } var A = [ 7 , 10 , 12 ] ; var n = A . length ; document . write ( maximumModuloValue ( A , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 3 ; let M = 4 ; class query { constructor ( x1 , x2 , y1 , y2 , k ) { this . x1 = x1 ; this . x2 = x2 ; this . y1 = y1 ; this . y2 = y2 ; this . K = k ; } } function updateQuery ( from_x , from_y , to_x , to_y , k , aux ) { aux [ from_x ] [ from_y ] += k ; if ( to_x + 1 < N ) aux [ to_x + 1 ] [ from_y ] -= k ; if ( to_x + 1 < N && to_y + 1 < M ) aux [ to_x + 1 ] [ to_y + 1 ] += k ; if ( to_y + 1 < M ) aux [ from_x ] [ to_y + 1 ] -= k ; } function updateMatrix ( mat , aux ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 1 ; j < M ; j ++ ) { aux [ i ] [ j ] += aux [ i ] [ j - 1 ] ; } } for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 1 ; j < N ; j ++ ) { aux [ j ] [ i ] += aux [ j - 1 ] [ i ] ; } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { mat [ i ] [ j ] += aux [ i ] [ j ] ; } } } function printMatrix ( mat ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function matrixQuery ( mat , Q , q ) { let aux = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { aux [ i ] = new Array ( M ) ; for ( let j = 0 ; j < M ; j ++ ) { aux [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < Q ; i ++ ) { updateQuery ( q [ i ] . x1 , q [ i ] . x2 , q [ i ] . y1 , q [ i ] . y2 , q [ i ] . K , aux ) ; } updateMatrix ( mat , aux ) ; printMatrix ( mat ) ; } let mat = [ [ 1 , 0 , 1 , 2 ] , [ 0 , 2 , 4 , 1 ] , [ 1 , 2 , 1 , 0 ] ] ; let Q = 1 ; let q = [ new query ( 0 , 0 , 1 , 1 , 2 ) ] ; matrixQuery ( mat , Q , q ) ;

Index/key variables: from_x, from_y, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: query
Javascript program:
function print2largest ( arr , arr_size ) { let i , first , second ; if ( arr_size < 2 ) { document . write ( " " ) ; return ; } arr . sort ( ) ; for ( i = arr_size - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] != arr [ arr_size - 1 ] ) { document . write ( " " + arr [ i ] ) ; return ; } } document . write ( " " ) ; } let arr = [ 12 , 35 , 1 , 10 , 34 , 1 ] ; let n = arr . length ; print2largest ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countNestedPolygons ( sides ) { var count = 0 ; while ( sides > 5 ) { sides /= 2 ; count += 1 ; } return count ; } var N = 12 ; document . write ( countNestedPolygons ( N ) ) ;

Accumulator variables: count, sides
Javascript program:
function print2largest ( arr , arr_size ) { let i ; if ( arr_size < 2 ) { document . write ( " " ) ; return ; } let largest = second = - 2454635434 ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > largest ) { largest = arr [ i ] ; } } for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > second && arr [ i ] < largest ) { second = arr [ i ] ; } } if ( second == - 2454635434 ) { document . write ( " " ) ; } else { document . write ( " " + second ) ; return ; } } let arr = [ 12 , 35 , 1 , 10 , 34 , 1 ] ; let n = arr . length ; print2largest ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function print2largest ( arr , arr_size ) { let i ; let largest = second = - 2454635434 ; if ( arr_size < 2 ) { document . write ( " " ) ; return ; } for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > largest ) { second = largest ; largest = arr [ i ] } else if ( arr [ i ] != largest && arr [ i ] > second ) { second = arr [ i ] ; } } if ( second == - 2454635434 ) { document . write ( " " ) ; } else { document . write ( " " + second ) ; return ; } } let arr = [ 12 , 35 , 1 , 10 , 34 , 1 ] ; let n = arr . length ; print2largest ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function queryResult ( prefix , Q ) { let l = Q [ 0 ] ; let r = Q [ 1 ] ; if ( l == 0 ) { let xorval = prefix [ r ] ; document . write ( countSetBits ( xorval ) + " " ) ; } else { let xorval = prefix [ r ] ^ prefix [ l - 1 ] ; document . write ( countSetBits ( xorval ) + " " ) ; } } function calculateCount ( S , Q , m ) { let n = S . length ; let arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = ( 1 << ( S [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ) ; } let prefix = new Array ( n ) ; let x = 0 ; for ( let i = 0 ; i < n ; i ++ ) { x ^= arr [ i ] ; prefix [ i ] = x ; } for ( let i = 0 ; i < m ; i ++ ) { queryResult ( prefix , Q [ i ] ) ; } } function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let S = " " ; let Q = [ [ 2 , 4 ] , [ 0 , 3 ] , [ 0 , 12 ] ] ; calculateCount ( S , Q , 3 ) ;

Index/key variables: i, r
Accumulator variables: i, setBits, x
Iterator variables: i
Javascript program:
function UniqueMatrix ( N ) { let element_value = 1 ; let i = 0 ; while ( i < N ) { if ( i % 2 == 0 ) { for ( let f = element_value ; f < element_value + N ; f ++ ) { document . write ( f + " " ) ; } element_value += N ; } else { for ( let k = element_value + N - 1 ; k > element_value - 1 ; k -- ) { document . write ( k + " " ) ; } element_value += N ; } document . write ( " " ) ; i = i + 1 ; } } let N = 4 ; UniqueMatrix ( N ) ;

Accumulator variables: element_value, f, k
Iterator variables: f, k
Javascript program:
function sumNodes ( l ) { let leafNodeCount = Math . pow ( 2 , l - 1 ) ; let vec = [ ] ; for ( let i = 1 ; i <= l ; i ++ ) { vec . push ( [ ] ) ; } for ( let i = 1 ; i <= leafNodeCount ; i ++ ) { vec [ l - 1 ] . push ( i ) ; } for ( let i = l - 2 ; i >= 0 ; i -- ) { let k = 0 ; while ( k < vec [ i + 1 ] . length - 1 ) { vec [ i ] . push ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ; k += 2 ; } } let sum = 0 ; for ( let i = 0 ; i < l ; i ++ ) { for ( let j = 0 ; j < vec [ i ] . length ; j ++ ) { sum += vec [ i ] [ j ] ; } } return sum ; } let l = 3 ; document . write ( sumNodes ( l ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sum
Iterator variables: i, j
Javascript program:
function findways ( s , x ) { if ( x > s . length ) return 0 ; var n = s . length ; var freq = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; ++ i ) freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var se = [ ] ; for ( var i = 0 ; i < 26 ; ++ i ) if ( freq [ i ] > 0 ) se . push ( freq [ i ] ) ; var ans = 1 ; for ( var i = 0 ; i < x / 2 ; ++ i ) { var count = 0 ; se . forEach ( u => { if ( u >= 2 ) count ++ ; } ) ; if ( count == 0 ) return 0 ; else ans = ans * count ; se . sort ( ( a , b ) => a - b ) var val = se [ se . length - 1 ] se . pop ( ) ; if ( val > 2 ) se . push ( val - 2 ) ; } if ( x % 2 != 0 ) { var count = 0 ; se . forEach ( u => { if ( u > 0 ) count ++ ; } ) ; ans = ans * count ; } return ans ; } var s = " " ; var x = 2 ; document . write ( findways ( s , x ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Javascript program:
function findIfPossible ( n , a , b ) { if ( b % a != 0 ) { if ( n == 1 ) return 0 ; else if ( n % b != 0 ) return - 1 ; else return n / b ; } let c = b / a ; let x = 0 , y = 0 ; while ( n % b == 0 ) { n = n / b ; x ++ ; } while ( n % c == 0 ) { n = n / c ; y ++ ; } if ( n == 1 ) { let total_steps = x + ( 2 * y ) ; return total_steps ; } else return - 1 ; } let n = 48 ; let a = 3 , b = 12 ; document . write ( findIfPossible ( n , a , b ) ) ;

Accumulator variables: x, y
Javascript program:
function removeLeadingZeros ( str ) { var i = 0 ; var n = str . length ; while ( str [ i ] == ' ' && i < n ) i ++ ; return str ; } function findPairs ( sum , K ) { var A , B ; A = " " ; B = " " ; var N = ( sum . toString ( ) ) ; var n = N . length ; for ( var i = 0 ; i < n ; i ++ ) { var D = N [ i ] - ' ' ; if ( D == K ) { var D1 , D2 ; D1 = parseInt ( D / 2 ) ; D2 = parseInt ( D / 2 ) + D % 2 ; A = A + String . fromCharCode ( D1 + ' ' . charCodeAt ( 0 ) ) ; B = B + String . fromCharCode ( D2 + ' ' . charCodeAt ( 0 ) ) ; } else { A = A + String . fromCharCode ( D + ' ' . charCodeAt ( 0 ) ) ; B = B + ' ' ; } } A = removeLeadingZeros ( A ) ; B = removeLeadingZeros ( B ) ; document . write ( A + " " + B ) ; } var N = 33673 ; var K = 3 ; findPairs ( N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinimumHike ( ratings , employees ) { let hikes = new Array ( employees ) ; for ( let i = 0 ; i < employees ; i ++ ) hikes [ i ] = 1 ; for ( let i = 1 ; i < employees ; i ++ ) { if ( ratings [ i - 1 ] < ratings [ i ] && hikes [ i - 1 ] >= hikes [ i ] ) hikes [ i ] = hikes [ i - 1 ] + 1 ; } for ( let i = employees - 2 ; i >= 0 ; i -- ) { if ( ratings [ i ] > ratings [ i + 1 ] && hikes [ i + 1 ] >= hikes [ i ] ) hikes [ i ] = hikes [ i + 1 ] + 1 ; } return hikes ; } let data = [ 5 , 3 , 4 , 2 , 1 , 6 ] ; let result = findMinimumHike ( data , data . length ) ; document . write ( " " + ( result ) . join ( " " ) + " " ) ; data = [ 1 , 3 , 5 , 4 ] ; result = findMinimumHike ( data , data . length ) ; document . write ( " " + ( result ) . join ( " " ) + " " ) ; data = [ 1 , 4 ] ; result = findMinimumHike ( data , data . length ) ; document . write ( " " + ( result ) . join ( " " ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Array ( 100005 ) ; function calculate ( pos , prev , s ) { if ( pos == s . length ) { return 0 ; } if ( dp [ pos ] [ prev ] != - 1 ) return dp [ pos ] [ prev ] ; let val = 0 ; if ( s [ pos ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 != prev ) { val = Math . max ( val , 1 + calculate ( pos + 1 , s [ pos ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 , s ) ) ; } val = Math . max ( val , calculate ( pos + 1 , prev , s ) ) ; dp [ pos ] [ prev ] = val ; return dp [ pos ] [ prev ] ; } function longestSubsequence ( s ) { let n = s . length ; for ( let i = 0 ; i < 100005 ; i ++ ) { dp [ i ] = new Array ( 27 ) ; for ( let j = 0 ; j < 27 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return calculate ( 0 , 0 , s ) ; } let str = " " ; document . write ( longestSubsequence ( str ) ) ;

Index/key variables: i, j, pos, prev
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function add ( arr , N , lo , hi , val ) { arr [ lo ] += val ; if ( hi != N - 1 ) arr [ hi + 1 ] -= val ; } function updateArray ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) arr [ i ] += arr [ i - 1 ] ; } function printArr ( arr , N ) { updateArray ( arr , N ) ; for ( let i = 0 ; i < N ; i ++ ) document . write ( " " + arr [ i ] + " " ) ; document . write ( " " ) ; } let N = 6 ; let arr = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = 0 ; } add ( arr , N , 0 , 2 , 100 ) ; add ( arr , N , 1 , 5 , 100 ) ; add ( arr , N , 2 , 3 , 100 ) ; printArr ( arr , N ) ;

Index/key variables: i, lo
Accumulator variables: i
Iterator variables: i
Javascript program:
function find_count ( arr , k ) { var ans = 0 ; for ( var i = 0 ; i <= arr . length ; i ++ ) { var x = countSetBits ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } function countSetBits ( x ) { var setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } var arr = [ 12 , 345 , 2 , 68 , 7896 ] ; var K = 2 ; document . write ( find_count ( arr , K ) ) ;

Accumulator variables: ans, i, setBits
Iterator variables: i
Javascript program:
function KPrimeDivisors ( N , K ) { var maximum_split = 0 ; while ( N % 2 == 0 ) { maximum_split ++ ; N /= 2 ; } for ( i = 3 ; i * i <= N ; i = i + 2 ) { while ( N % i == 0 ) { N = N / i ; maximum_split ++ ; } } if ( N > 2 ) maximum_split ++ ; if ( maximum_split < K ) { document . write ( " " ) ; return ; } document . write ( " " ) ; } var N = 12 ; var K = 3 ; KPrimeDivisors ( N , K ) ;

Accumulator variables: N, maximum_split
Iterator variables: i
Javascript program:
function findSum ( L , R ) { var arr = [ ] ; var i = 0 ; var x = 2 ; while ( i <= R ) { arr . push ( i + x ) ; if ( i + 1 <= R ) arr . push ( i + 1 + x ) ; x *= - 1 ; i += 2 ; } var sum = 0 ; for ( var i = L ; i <= R ; ++ i ) sum += arr [ i ] ; return sum ; } var L = 0 , R = 5 ; document . write ( findSum ( L , R ) ) ;

Index/key variables: i
Accumulator variables: i, sum, x
Iterator variables: i
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } function FillPrefixSuffix ( prefix , arr , suffix , n ) { prefix [ 0 ] = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) prefix [ i ] = GCD ( prefix [ i - 1 ] , arr [ i ] ) ; suffix [ n - 1 ] = arr [ n - 1 ] ; for ( i = n - 2 ; i >= 0 ; i -- ) suffix [ i ] = GCD ( suffix [ i + 1 ] , arr [ i ] ) ; } function GCDoutsideRange ( l , r , prefix , suffix , n ) { if ( l == 0 ) return suffix [ r + 1 ] ; if ( r == n - 1 ) return prefix [ l - 1 ] ; return GCD ( prefix [ l - 1 ] , suffix [ r + 1 ] ) ; } var arr = [ 2 , 6 , 9 ] ; var n = arr . length ; var prefix = Array ( n ) . fill ( 0 ) ; var suffix = Array ( n ) . fill ( 0 ) ; FillPrefixSuffix ( prefix , arr , suffix , n ) ; var l = 0 , r = 0 ; document . write ( GCDoutsideRange ( l , r , prefix , suffix , n ) ) ; document . write ( " " ) ; l = 1 ; r = 1 ; document . write ( GCDoutsideRange ( l , r , prefix , suffix , n ) ) ; document . write ( " " ) ; l = 1 ; r = 2 ; document . write ( GCDoutsideRange ( l , r , prefix , suffix , n ) ) ; document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( A , B , N ) { let pq1 = [ ] ; let pq2 = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { pq1 . push ( A [ i ] ) ; } for ( let i = 0 ; i < N ; i ++ ) { pq2 . push ( B [ i ] ) ; } pq1 . sort ( function ( a , b ) { return a - b ; } ) ; pq1 . reverse ( ) ; pq2 . sort ( function ( a , b ) { return a - b ; } ) ; pq2 . reverse ( ) ; let c = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( pq1 [ 0 ] > pq2 [ 0 ] ) { c ++ ; pq1 . shift ( ) ; pq2 . shift ( ) ; } else { if ( pq2 . length == 0 ) { break ; } pq2 . shift ( ) ; } } return ( c ) ; } let A = [ 10 , 3 , 7 , 5 , 8 ] ; let B = [ 8 , 6 , 2 , 5 , 9 ] ; let N = A . length ; document . write ( check ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function countInRange ( arr , n , x , y ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ; } return count ; } let arr = [ 1 , 3 , 4 , 9 , 10 , 3 ] ; let n = arr . length ; let i = 1 , j = 4 ; document . write ( countInRange ( arr , n , i , j ) + " " ) ; i = 9 ; j = 12 ; document . write ( countInRange ( arr , n , i , j ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function lowerIndex ( arr , n , x ) { let l = 0 , h = n - 1 ; while ( l <= h ) { let mid = parseInt ( ( l + h ) / 2 , 10 ) ; if ( arr [ mid ] >= x ) h = mid - 1 ; else l = mid + 1 ; } return l ; } function upperIndex ( arr , n , y ) { let l = 0 , h = n - 1 ; while ( l <= h ) { let mid = parseInt ( ( l + h ) / 2 , 10 ) ; if ( arr [ mid ] <= y ) l = mid + 1 ; else h = mid - 1 ; } return h ; } function countInRange ( arr , n , x , y ) { let count = 0 ; count = upperIndex ( arr , n , y ) - lowerIndex ( arr , n , x ) + 1 ; return count ; } let arr = [ 1 , 4 , 4 , 9 , 10 , 3 ] ; let n = arr . length ; arr . sort ( function ( a , b ) { return a - b } ) ; let i = 1 , j = 4 ; document . write ( countInRange ( arr , n , i , j ) + " " ) ; ; i = 9 ; j = 12 ; document . write ( countInRange ( arr , n , i , j ) ) ;

Index/key variables: mid