dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function getPairs ( A , B , n ) { let D = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { D [ i ] = A [ i ] - B [ i ] ; } D . sort ( ( a , b ) => a - b ) ; let total = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( D [ i ] > 0 ) { total += n - i - 1 ; } else { let k = upper_bound ( D , 0 , D . length , - D [ i ] ) total += n - k ; } } return total ; } 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 ; } let n = 5 ; let A = new Array ( ) ; let B = new Array ( ) ; A . push ( 4 ) ; A . push ( 8 ) ; A . push ( 2 ) ; A . push ( 6 ) ; A . push ( 2 ) ; B . push ( 4 ) ; B . push ( 5 ) ; B . push ( 4 ) ; B . push ( 1 ) ; B . push ( 3 ) ; document . write ( getPairs ( A , B , n ) )

Index/key variables: i, middle
Accumulator variables: i, total
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function lcm ( a , b ) { return ( a * b ) / gcd ( a , b ) ; } function countPairs ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) if ( lcm ( arr [ i ] , arr [ j ] ) == gcd ( arr [ i ] , arr [ j ] ) ) ans ++ ; return ans ; } var arr = [ 1 , 1 , 1 ] ; var n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countPairs ( arr , n ) { let frequency = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( frequency . has ( arr [ i ] ) ) { frequency . set ( arr [ i ] , frequency . get ( arr [ i ] ) + 1 ) ; } else { frequency . set ( arr [ i ] , 1 ) ; } } let count = 0 ; for ( let [ key , value ] of frequency . entries ( ) ) { let f = value ; count += f * ( f - 1 ) / 2 ; } return count ; } let arr = [ 1 , 1 , 1 ] ; let n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function maxValue ( arr , n , moves ) { for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { var distance = n - 1 - i ; if ( moves < distance ) break ; var can_take = parseInt ( moves / distance ) ; var take = Math . min ( arr [ i ] , can_take ) ; arr [ n - 1 ] += take ; moves -= take * distance ; } } return arr [ n - 1 ] ; } var arr = [ 2 , 3 , 0 , 1 ] ; var M = 5 ; var N = arr . length ; document . write ( maxValue ( arr , N , M ) ) ;

Index/key variables: i
Accumulator variables: i, moves
Iterator variables: i
Javascript program:
var fact = Array ( 14 ) . fill ( 0 ) ; var size = 1 ; function preCompute ( N ) { fact [ 0 ] = 1 ; for ( var i = 1 ; fact [ i - 1 ] <= N ; i ++ ) { fact [ i ] = ( fact [ i - 1 ] * i ) ; size ++ ; } } function findMin ( N ) { preCompute ( N ) ; var originalN = N ; ans = [ ] ; for ( var i = size - 1 ; i >= 0 ; i -- ) { while ( N >= fact [ i ] ) { N -= fact [ i ] ; ans . push ( fact [ i ] ) ; } } document . write ( ans . length + " " ) ; for ( var i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ; } var n = 27 ; findMin ( n ) ;

Index/key variables: i
Accumulator variables: N, i, size
Iterator variables: i
Javascript program:
function vertical_Fill ( records , tape , m , n ) { let v = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { v [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { v [ i ] [ j ] = 0 ; } } let sum = 0 ; let Retrieval_Time = 0 ; let Mrt ; let z = 0 , j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { sum = 0 ; for ( let k = 0 ; k < i ; k ++ ) { sum += v [ j ] [ k ] ; } if ( sum + records [ z ] <= tape [ j ] ) { v [ j ] [ i ] = records [ z ] ; z ++ ; } } if ( v [ 2 ] [ i ] == 0 ) { break ; } } for ( let i = 0 ; i < m ; i ++ ) { Retrieval_Time = 0 ; document . write ( " " + ( i + 1 ) + " " ) ; for ( j = 0 ; j < n ; j ++ ) { if ( v [ i ] [ j ] != 0 ) { document . write ( v [ i ] [ j ] + " " ) ; } else { break ; } } document . write ( " " ) ; for ( let k = 0 ; v [ i ] [ k ] != 0 ; k ++ ) { Retrieval_Time += v [ i ] [ k ] * ( j - k ) ; } Mrt = Retrieval_Time / j ; if ( i != m - 1 ) { document . write ( " " + Mrt + " " ) ; } else { document . write ( " " + Mrt . toFixed ( 4 ) + " " ) ; } } } let records = [ 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 ] ; let tape = [ 25 , 80 , 160 ] ; let n = records . length ; let m = tape . length ; records . sort ( function ( a , b ) { return a - b } ) ; vertical_Fill ( records , tape , m , n ) ;

Index/key variables: i, j, k, z
Accumulator variables: Retrieval_Time, i, j, k, sum, z
Iterator variables: i, j, k
Javascript program:
var MAX = 26 ; function maxLength ( str , len ) { var res = 0 ; var lastPos = Array ( MAX ) ; for ( var i = 0 ; i < MAX ; i ++ ) { lastPos [ i ] = - 1 ; } for ( var i = 0 ; i < len ; i ++ ) { var C = str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( lastPos [ C ] != - 1 ) { res = Math . max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ; } lastPos [ C ] = i ; } return res ; } var str = " " ; var len = str . length ; document . write ( maxLength ( str , len ) ) ;

Index/key variables: C, i
Accumulator variables: i
Iterator variables: i
Javascript program:
var INT_MAX = 1000000000 ; function min_element ( A , N ) { var min = A [ 0 ] ; var i ; for ( i = 1 ; i < N ; i ++ ) { if ( min > A [ i ] ) { min = A [ i ] ; } } return min ; } function countPartitions ( A , N ) { var count = 0 ; var i , j ; for ( i = 0 ; i < N ; i ++ ) { var min_elem = min_element ( A , N ) ; if ( min_elem == INT_MAX ) break ; count ++ ; for ( j = 0 ; j < N ; j ++ ) { if ( A [ j ] % min_elem == 0 ) A [ j ] = INT_MAX ; } } return count ; } var arr = [ 7 , 6 , 5 , 4 , 3 , 2 , 2 , 3 ] ; var N = arr . length ; document . write ( countPartitions ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function minChanges ( arr , n ) { var umap = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( umap . has ( arr [ i ] ) ) { umap . set ( arr [ i ] , umap . get ( arr [ i ] ) + 1 ) ; } else { umap . set ( arr [ i ] , 1 ) ; } } var maxFreq = 0 ; umap . forEach ( ( values , keys ) => { maxFreq = Math . max ( maxFreq , values ) ; } ) ; return n - maxFreq ; } var arr = [ 2 , 3 , 3 , 4 ] ; var n = arr . length ; document . write ( minChanges ( arr , n ) + ' ' ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function k_sum ( a , n , k ) { let r = 0 , sum = 0 ; let ans = 0 ; for ( let l = 0 ; l < n ; l ++ ) { while ( sum < k ) { if ( r == n ) break ; else { sum += a [ r ] ; r ++ ; } } if ( sum < k ) break ; ans += n - r + 1 ; sum -= a [ l ] ; } return ans ; } let a = [ 6 , 1 , 2 , 7 ] , k = 10 ; let n = a . length ; document . write ( k_sum ( a , n , k ) ) ;

Index/key variables: l, r
Accumulator variables: ans, l, r, sum
Iterator variables: l
Javascript program:
function hasCrest ( arr , n , L , R ) { let present = new Uint8Array ( n ) ; for ( let i = 1 ; i <= n - 2 ; i ++ ) { if ( ( arr [ i ] <= arr [ i + 1 ] ) && ( arr [ i ] <= arr [ i - 1 ] ) ) { present [ i ] = 1 ; } } for ( let i = 1 ; i < n ; i ++ ) { present [ i ] += present [ i - 1 ] ; } if ( present [ L ] == present [ R - 1 ] ) return true ; return false ; } let arr = [ 2 , 1 , 3 , 5 , 12 , 11 , 7 , 9 ] ; let N = arr . length ; let L = 2 ; let R = 6 ; if ( hasCrest ( arr , N , L , R ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: L, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( arr1 , arr2 , n ) { let initialParity = 0 , finalParity = 0 ; let sum = 0 , minPositive = Number . MAX_SAFE_INTEGER , maxNegative = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { initialParity += arr2 [ i ] ; if ( arr1 [ i ] >= 0 ) { finalParity += 1 ; sum += arr1 [ i ] ; minPositive = Math . min ( minPositive , arr1 [ i ] ) ; } else { maxNegative = Math . max ( maxNegative , arr1 [ i ] ) ; } } if ( initialParity % 2 == finalParity % 2 ) { return sum ; } else { if ( minPositive + maxNegative >= 0 ) { return sum + maxNegative ; } else { return sum - minPositive ; } } } let arr1 = [ 2 , - 4 , 5 , 3 ] ; let arr2 = [ 0 , 1 , 0 , 1 ] ; let n = arr1 . length ; document . write ( maxSum ( arr1 , arr2 , n ) ) ;

Index/key variables: i
Accumulator variables: finalParity, i, initialParity, sum
Iterator variables: i
Javascript program:
function IsLarger ( X , Y , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( X [ i ] < Y [ i ] ) { return false ; } } return true ; } function solve ( X , Y , n ) { let ans = 0 ; if ( IsLarger ( X , Y , n ) ) { ans = 0 ; } else { let d = Y [ 0 ] - X [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { X [ i ] += d ; } if ( IsLarger ( X , Y , n ) ) { ans = d ; } else { ans = d + 1 ; } } return ans ; } let X = [ 2 , 3 , 6 , 9 ] ; let Y = [ 3 , 4 , 8 , 1 ] ; let n = X . length ; document . write ( solve ( X , Y , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function max_bitwise_or ( L , R ) { let v1 = [ ] , v2 = [ ] , v3 = [ ] ; let z = 0 , i , ans = 0 , cnt = 1 ; while ( L > 0 ) { v1 . push ( L % 2 ) ; L = parseInt ( L / 2 ) ; } while ( R > 0 ) { v2 . push ( R % 2 ) ; R = parseInt ( R / 2 ) ; } while ( v1 . length != v2 . length ) { v1 . push ( 0 ) ; } for ( i = v2 . length - 1 ; i >= 0 ; i -- ) { if ( v2 [ i ] == 1 && v1 [ i ] == 0 && z == 0 ) { z = 1 ; continue ; } if ( z == 1 ) { v1 [ i ] = 1 ; } } for ( i = 0 ; i < v2 . length ; i ++ ) { v3 . push ( v2 [ i ] v1 [ i ] ) ; } for ( i = 0 ; i < v2 . length ; i ++ ) { if ( v3 [ i ] == 1 ) { ans += cnt ; } cnt *= 2 ; } return ans ; } let L = 10 , R = 20 ; document . write ( max_bitwise_or ( L , R ) ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function valueofX ( ar , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + ar [ i ] ; } if ( sum % n == 0 ) { return Math . floor ( sum / n ) ; } else { let A = Math . floor ( sum / n ) , B = Math . floor ( sum / n + 1 ) ; let ValueA = 0 , ValueB = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ValueA += ( ar [ i ] - A ) * ( ar [ i ] - A ) ; ValueB += ( ar [ i ] - B ) * ( ar [ i ] - B ) ; } if ( ValueA < ValueB ) { return A ; } else { return B ; } } } let n = 7 ; let arr = [ 6 , 9 , 1 , 6 , 1 , 3 , 7 ] ; document . write ( valueofX ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: ValueA, ValueB, i
Iterator variables: i
Javascript program:
function minLength ( n ) { var ans = parseInt ( n / 26 ) ; if ( n % 26 != 0 ) ans ++ ; return ans ; } function minString ( n ) { var ans = parseInt ( n / 26 ) ; var res = " " ; while ( ans -- ) { res = res + " " ; } if ( n % 26 != 0 ) { res = res + String . fromCharCode ( ( n % 26 ) + 96 ) ; } return res ; } var n = 50 ; document . write ( minLength ( n ) + " " + minString ( n ) ) ;

Accumulator variables: ans
Javascript program:
const MAX = 100001 ; function minHalls ( lectures , n ) { let prefix_sum = new Uint8Array ( MAX ) ; for ( let i = 0 ; i < n ; i ++ ) { prefix_sum [ lectures [ i ] [ 0 ] ] ++ ; prefix_sum [ lectures [ i ] [ 1 ] + 1 ] -- ; } let ans = prefix_sum [ 0 ] ; for ( let i = 1 ; i < MAX ; i ++ ) { prefix_sum [ i ] += prefix_sum [ i - 1 ] ; ans = Math . max ( ans , prefix_sum [ i ] ) ; } return ans ; } let lectures = [ [ 0 , 5 ] , [ 1 , 2 ] , [ 1 , 10 ] ] ; let n = lectures . length ; document . write ( minHalls ( lectures , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCapacity ( enter , exit , n ) { let minCap = 0 ; let currCap = 0 ; for ( let i = 0 ; i < n ; i ++ ) { currCap = currCap + enter [ i ] - exit [ i ] ; minCap = Math . max ( minCap , currCap ) ; } return minCap ; } let enter = [ 3 , 5 , 2 , 0 ] ; let exit = [ 0 , 2 , 4 , 4 ] ; let n = enter . length ; document . write ( minCapacity ( enter , exit , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 543210 ; let ans = [ ] ; function isValidNum ( x ) { let mp = new Map ( ) ; for ( let i = 0 ; i < x . length ; i ++ ) { if ( mp . has ( x [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) { return false ; } else if ( x [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) > 5 ) { return false ; } else { mp . set ( x [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) , 1 ) ; } } return true ; } function generate ( ) { let q = [ ] ; q . push ( " " ) ; q . push ( " " ) ; q . push ( " " ) ; q . push ( " " ) ; q . push ( " " ) ; let flag = true ; ans . push ( " " ) ; while ( q . length != 0 ) { let x = q . shift ( ) ; if ( isValidNum ( x ) ) { ans . push ( x ) ; } if ( x . length == 6 ) continue ; for ( let i = 0 ; i <= 5 ; i ++ ) { let z = ( i ) . toString ( ) ; let temp = x + z ; q . push ( temp ) ; } } } function comp ( a , b ) { if ( a . length == b . length ) { return a < b ? true : false ; } else return a . length < b . length ; } function findcount ( l , r ) { generate ( ) ; let count = 0 ; for ( let i = 0 ; i < ans . length ; i ++ ) { let a = ans [ i ] ; if ( comp ( l , a ) && comp ( a , r ) ) { count ++ ; } else if ( a == l a == r ) { count ++ ; } } return count ; } let l = " " , r = " " ; document . write ( findcount ( l , r ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function Findpermutation ( n ) { let a = new Array ( n + 1 ) ; a [ 1 ] = n ; for ( let i = 2 ; i <= n ; i ++ ) a [ i ] = i - 1 ; return a ; } let n = 8 ; let v = Findpermutation ( n ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( v [ i ] + ' ' ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lexo_small ( n , k ) { var arr = Array . from ( { length : n } , ( _ , i ) => ' ' ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { k -= i ; if ( k >= 0 ) { if ( k >= 26 ) { arr [ i ] = ' ' ; k -= 26 ; } else { arr [ i ] = String . fromCharCode ( k + 97 - 1 ) ; k -= arr [ i ] - ' ' + 1 ; } } else break ; k += i ; } return arr ; } var n = 5 , k = 42 ; var arr = lexo_small ( n , k ) ; document . write ( arr . join ( ' ' ) ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function Substring ( s ) { var ans = 1 , temp = 1 ; for ( var i = 1 ; i < s . length ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { ++ temp ; } else { ans = Math . max ( ans , temp ) ; temp = 1 ; } } ans = Math . max ( ans , temp ) ; return ans ; } var s = " " ; document . write ( Substring ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function Balanced_Substring ( str , n ) { let ans = 0 ; let arr = new Array ( n / 2 + 1 ) . fill ( 0 ) ; let d = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) d ++ ; else { if ( d == 1 ) { for ( let j = 2 ; j <= parseInt ( n / 2 ) + 1 && arr [ j ] != 0 ; j ++ ) arr [ j ] = 0 ; } ++ ans ; ans += arr [ d ] ; arr [ d ] ++ ; d -- ; } } return ans ; } let str = " " ; let n = str . length ; document . write ( Balanced_Substring ( str , n ) ) ;

Index/key variables: d, i, j
Accumulator variables: ans, d, i, j
Iterator variables: i, j
Javascript program:
function power ( x , y , mod ) { var res = 1 ; while ( y != 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; x = ( x * x ) % mod ; y = ( y >> 1 ) ; } return parseInt ( res % mod ) ; } function ncr ( n , r , mod ) { var res = 1 ; for ( var i = 1 ; i <= r ; i += 1 ) { res = ( res * ( n - i + 1 ) ) % mod ; var inv = power ( i , mod - 2 , mod ) ; res = ( res * inv ) % mod ; } return parseInt ( res % mod ) ; } function NoOfChords ( A ) { var mod = parseInt ( 7 ) ; var ans = ncr ( 2 * A , A , mod ) ; var inv = power ( A + 1 , mod - 2 , mod ) ; ans = ( ans * inv ) % mod ; return parseInt ( ans % mod ) ; } var N = 2 ; document . write ( NoOfChords ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function StrictlyPositiveXor ( A , N ) { let allxor = 0 ; let checkallzero = true ; for ( let i = 0 ; i < N ; i += 1 ) { allxor ^= A [ i ] ; if ( A [ i ] > 0 ) checkallzero = false ; } if ( allxor != 0 ) return N ; if ( checkallzero ) return - 1 ; let l = N , r = - 1 ; for ( let i = 0 ; i < N ; i += 1 ) { if ( A [ i ] > 0 ) { l = i + 1 ; break ; } } for ( let i = N - 1 ; i >= 0 ; i -= 1 ) { if ( A [ i ] > 0 ) { r = i + 1 ; break ; } } return Math . max ( N - l , r - 1 ) ; } let A = [ 1 , 0 , 0 , 1 ] ; let N = A . length ; document . write ( StrictlyPositiveXor ( A , N ) ) ;

Index/key variables: i
Accumulator variables: allxor, i
Iterator variables: i
Boolean variables: checkallzero
Javascript program:
let MAX_INT = 1000000 ; function solve ( array , N ) { let pos = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { pos [ i ] = new Array ( 10000 ) ; for ( let j = 0 ; j < 10000 ; j ++ ) { pos [ i ] [ j ] = 0 ; } } let pref = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { pref [ i ] = 0 ; } if ( array [ 0 ] == 0 ) { pref [ 0 ] = 1 ; pos [ 0 ] [ pos [ 0 ] . length - 1 ] = 0 ; } let ans = MAX_INT ; for ( let i = 1 ; i < N ; i ++ ) { if ( array [ i ] == 0 ) { pref [ 0 ] ++ ; pos [ 0 ] [ pos [ 0 ] . length - 1 ] = i ; } else { if ( pref [ array [ i ] - 1 ] > 0 ) { pref [ array [ i ] ] ++ ; pos [ array [ i ] ] [ pos [ array [ i ] ] . length - 1 ] = i ; if ( array [ i ] == 4 ) { let end = i ; let start = i ; for ( let j = 3 ; j >= 0 ; j -- ) { let s = 0 ; let e = pos [ j ] . length - 1 ; let temp = - 1 ; while ( s <= e ) { let m = Math . floor ( ( s + e ) / 2 ) ; if ( pos [ j ] [ m ] <= start ) { temp = pos [ j ] [ m ] ; s = m + 1 ; } else e = m - 1 ; } start = temp ; } ans = Math . min ( ans , end - start + 1 ) ; } } } } return ans ; } let array = [ 0 , 1 , 2 , 3 , 4 , 2 , 0 , 3 , 4 ] ; let N = array . length ; document . write ( solve ( array , N ) ) ;

Index/key variables: i, j, m
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findWeights ( X ) { let sum = 0 ; let power = 0 ; let number = 3 ; while ( sum < X ) { sum = number - 1 ; sum = Math . floor ( sum / 2 ) ; power ++ ; number *= 3 ; } let ans = 1 ; for ( let i = 1 ; i <= power ; i ++ ) { document . write ( ans + " " ) ; ans = ans * 3 ; } } let X = 2 ; findWeights ( X ) ;

Accumulator variables: i, number, power
Iterator variables: i
Javascript program:
function solve ( X , A ) { let min = Number . MAX_VALUE ; let ind = - 1 ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] < min ) { min = A [ i ] ; ind = i ; } } let maxIndChosen = Math . floor ( X / min ) ; let ans = [ ] ; if ( maxIndChosen == 0 ) { return ans ; } for ( let i = 0 ; i < maxIndChosen ; i ++ ) { ans . push ( ind ) ; } let temp = maxIndChosen ; let sum = maxIndChosen * A [ ind ] ; for ( let i = 0 ; i < ind ; i ++ ) { if ( sum - X == 0 temp == 0 ) break ; while ( ( sum - A [ ind ] + A [ i ] ) <= X && temp != 0 ) { ans . shift ( ) ; ans . push ( i ) ; temp -- ; sum += ( A [ i ] - A [ ind ] ) ; } } ans . sort ( function ( a , b ) { return a - b ; } ) ; return ans ; } let A = [ 5 , 6 , 4 , 8 ] ; let X = 18 ; let ans = solve ( X , A ) ; for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ;

Index/key variables: i, ind
Accumulator variables: i, sum, temp
Iterator variables: i
Javascript program:
function matrix_exist ( row , column , r , c ) { var row_sum = 0 ; var column_sum = 0 ; var row_max = - 1 ; var column_max = - 1 ; var row_non_zero = 0 ; var column_non_zero = 0 ; for ( var i = 0 ; i < r ; i ++ ) { row_sum += row [ i ] ; row_max = Math . max ( row_max , row [ i ] ) ; if ( row [ i ] ) row_non_zero ++ ; } for ( var i = 0 ; i < c ; i ++ ) { column_sum += column [ i ] ; column_max = Math . max ( column_max , column [ i ] ) ; if ( column [ i ] ) column_non_zero ++ ; } if ( ( row_sum != column_sum ) || ( row_max > column_non_zero ) || ( column_max > row_non_zero ) ) return false ; return true ; } var row = [ 2 , 2 , 2 , 2 , 2 ] ; var column = [ 5 , 5 , 0 , 0 ] ; var r = row . length ; var c = column . length ; if ( matrix_exist ( row , column , r , c ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: column_non_zero, column_sum, i, row_non_zero, row_sum
Iterator variables: i
Javascript program:
function longestSubarray ( arr , n ) { var maxMean = 0 ; for ( var i = 1 ; i < n ; i ++ ) maxMean = Math . max ( maxMean , parseInt ( ( arr [ i ] + arr [ i - 1 ] ) / 2 ) ) ; var ans = 0 ; var subarrayLength = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] >= maxMean ) ans = Math . max ( ans , ++ subarrayLength ) ; else subarrayLength = 0 ; return ans ; } var arr = [ 4 , 3 , 3 , 2 , 1 , 4 ] ; var n = arr . length ; document . write ( longestSubarray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxDistance ( arr , n ) { if ( arr [ 0 ] != arr [ n - 1 ] ) return ( n - 1 ) ; var i = n - 1 ; while ( i > 0 ) { if ( arr [ i ] != arr [ 0 ] ) break ; i -- ; } var distFirst = ( i == 0 ) ? - 1 : i ; i = 0 ; while ( i < n - 1 ) { if ( arr [ i ] != arr [ n - 1 ] ) break ; i ++ ; } var distLast = ( i == n - 1 ) ? - 1 : ( n - 1 - i ) ; var maxDist = Math . max ( distFirst , distLast ) ; return maxDist ; } var arr = [ 4 , 4 , 1 , 2 , 1 , 4 ] ; var n = arr . length ; document . write ( maxDistance ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function solve ( n , k ) { let mini = 0 ; let x1 = 1 ; let a = new Array ( k ) ; for ( let i = 1 ; i <= k ; i ++ ) { mini += x1 ; a [ i - 1 ] = x1 ; x1 += 1 ; } if ( n < mini ) { document . write ( " " ) ; return ; } let rem = n - mini ; let cnt = parseInt ( rem / k ) ; rem = rem % k ; for ( let i = 0 ; i < k ; i ++ ) a [ i ] += cnt ; for ( let i = k - 1 ; i > 0 && rem > 0 ; i -- ) { let xx = a [ i - 1 ] * 2 ; let left = xx - a [ i ] ; if ( rem >= left ) { a [ i ] = xx ; rem -= left ; } else { a [ i ] += rem ; rem = 0 ; } } let sum = a [ 0 ] ; for ( let i = 1 ; i < k ; i ++ ) { if ( a [ i ] > 2 * a [ i - 1 ] ) { document . write ( " " ) ; return ; } sum += a [ i ] ; } if ( sum != n ) { document . write ( " " ) ; return ; } for ( let i = 0 ; i < k ; i ++ ) document . write ( a [ i ] + " " ) ; } let n = 26 , k = 6 ; solve ( n , k ) ;

Index/key variables: i
Accumulator variables: i, mini, rem, sum, x1
Iterator variables: i
Javascript program:
const MAX = 25 ; function getMinSum ( arr , n ) { let bits_count = new Array ( MAX ) . fill ( 0 ) , max_bit = 0 , sum = 0 , ans = 0 ; for ( let d = 0 ; d < n ; d ++ ) { let e = arr [ d ] , f = 0 ; while ( e > 0 ) { let rem = e % 2 ; e = parseInt ( e / 2 ) ; if ( rem == 1 ) { bits_count [ f ] += rem ; } f ++ ; } max_bit = Math . max ( max_bit , f ) ; } for ( let d = 0 ; d < max_bit ; d ++ ) { let temp = Math . pow ( 2 , d ) ; if ( bits_count [ d ] > parseInt ( n / 2 ) ) ans = ans + temp ; } for ( let d = 0 ; d < n ; d ++ ) { arr [ d ] = arr [ d ] ^ ans ; sum = sum + arr [ d ] ; } return sum ; } let arr = [ 3 , 5 , 7 , 11 , 15 ] ; let n = arr . length ; document . write ( getMinSum ( arr , n ) ) ;

Index/key variables: d, f
Accumulator variables: d, f
Iterator variables: d
Javascript program:
function maxCoins ( X , Y ) { if ( X < Y ) { let temp = X ; X = Y ; Y = temp ; } let coins = X ; X -- ; coins += Math . max ( X , Y ) ; return coins ; } let X = 7 , Y = 5 ; document . write ( maxCoins ( X , Y ) ) ;

Accumulator variables: X, coins
Javascript program:
function findElementsCrossed ( arr , a , b , n ) { var aa = a ; var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a == 0 && b == 0 ) break ; else if ( a == 0 ) { if ( arr [ i ] == 1 ) { b -= 1 ; a = Math . min ( aa , a + 1 ) ; } else b -= 1 ; } else if ( b == 0 ) a -- ; else if ( arr [ i ] == 1 && a < aa ) { b -= 1 ; a = Math . min ( aa , a + 1 ) ; } else a -- ; ans ++ ; } return ans ; } var arr = [ 1 , 0 , 0 , 1 , 0 , 1 ] ; var n = arr . length ; var a = 1 ; var b = 2 ; document . write ( findElementsCrossed ( arr , a , b , n ) ) ;

Index/key variables: i
Accumulator variables: a, ans, b, i
Iterator variables: i