dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxMod ( arr , n ) { let maxVal = arr . sort ( ( a , b ) => b - a ) [ 0 ] let secondMax = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < maxVal && arr [ i ] > secondMax ) { secondMax = arr [ i ] ; } } return secondMax ; } let arr = [ 2 , 4 , 1 , 5 , 3 , 6 ] ; let n = arr . length ; document . write ( maxMod ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100005 ; function Min_Replace ( arr , n , k ) { arr . sort ( ( a , b ) => a - b ) var freq = Array ( MAX ) . fill ( 0 ) ; var p = 0 ; freq [ p ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) ++ freq [ p ] ; else ++ freq [ ++ p ] ; } freq . sort ( ( a , b ) => b - a ) ; var ans = 0 ; for ( var i = k ; i <= p ; i ++ ) ans += freq [ i ] ; return ans ; } var arr = [ 1 , 2 , 7 , 8 , 2 , 3 , 2 , 3 ] ; var n = arr . length ; var k = 2 ; document . write ( Min_Replace ( arr , n , k ) ) ;

Index/key variables: i, p
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function Segment ( x , l , n ) { if ( n == 1 ) return 1 ; let ans = 2 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( x [ i ] - l [ i ] > x [ i - 1 ] ) ans ++ ; else if ( x [ i ] + l [ i ] < x [ i + 1 ] ) { x [ i ] = x [ i ] + l [ i ] ; ans ++ ; } } return ans ; } let x = [ 1 , 3 , 4 , 5 , 8 ] , l = [ 10 , 1 , 2 , 2 , 5 ] ; let n = x . length ; document . write ( Segment ( x , l , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function MinimizeleftOverSum ( a , n ) { var v1 = [ ] , v2 = [ ] ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) v1 . push ( a [ i ] ) ; else v2 . push ( a [ i ] ) ; } if ( v1 . length > v2 . length ) { v1 . sort ( ) ; v2 . sort ( ) ; var x = v1 . length - v2 . length - 1 ; var sum = 0 ; var i = 0 ; while ( i < x ) { sum += v1 [ i ++ ] ; } return sum ; } else if ( v2 . length > v1 . length ) { v1 . sort ( ) ; v2 . sort ( ) ; var x = v2 . length - v1 . length - 1 ; var sum = 0 ; var i = 0 ; while ( i < x ) { sum += v2 [ i ++ ] ; } return sum ; } else return 0 ; } var a = [ 2 , 2 , 2 , 2 ] ; var n = a . length ; document . write ( MinimizeleftOverSum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minOperation ( S , N , K ) { if ( N % K ) { document . write ( " " ) ; return ; } var count = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { count [ S [ i ] . charCodeAt ( 0 ) - 97 ] ++ ; } var E = N / K ; var greaterE = [ ] ; var lessE = [ ] ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] < E ) lessE . push ( E - count [ i ] ) ; else greaterE . push ( count [ i ] - E ) ; } greaterE . sort ( ) ; lessE . sort ( ) ; var mi = 1000000000 ; for ( var i = 0 ; i <= K ; i ++ ) { var set1 = i ; var set2 = K - i ; if ( greaterE . length >= set1 && lessE . length >= set2 ) { var step1 = 0 ; var step2 = 0 ; for ( var j = 0 ; j < set1 ; j ++ ) step1 += greaterE [ j ] ; for ( var j = 0 ; j < set2 ; j ++ ) step2 += lessE [ j ] ; mi = Math . min ( mi , Math . max ( step1 , step2 ) ) ; } } document . write ( mi ) ; } var S = " " ; var N = S . length ; var K = 2 ; minOperation ( S , N , K ) ;

Index/key variables: i, j
Accumulator variables: i, j, step1, step2
Iterator variables: i, j
Javascript program:
function minMovesToSort ( arr , n ) { var moves = 0 ; var i , mn = arr [ n - 1 ] ; for ( i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > mn ) moves += arr [ i ] - mn ; mn = arr [ i ] ; } return moves ; } var arr = [ 3 , 5 , 2 , 8 , 4 ] ; var n = arr . length ; document . write ( minMovesToSort ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, moves
Iterator variables: i
Javascript program:
var prime = Array ( 100005 ) . fill ( true ) ; function SieveOfEratosthenes ( n ) { prime [ 1 ] = false ; for ( var p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] ) { for ( var i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } } function sortPrimes ( arr , n ) { SieveOfEratosthenes ( 100005 ) ; var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) v . push ( arr [ i ] ) ; } v . sort ( ( a , b ) => b - a ) var j = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) arr [ i ] = v [ j ++ ] ; } } var arr = [ 4 , 3 , 2 , 6 , 100 , 17 ] ; var n = arr . length ; sortPrimes ( arr , n ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, p
Accumulator variables: i, j, p
Iterator variables: i, p
Javascript program:
function findOptimalPairs ( arr , N ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( var i = 0 , j = N - 1 ; i <= j ; i ++ , j -- ) document . write ( " " + arr [ i ] + " " + arr [ j ] + " " + " " ) ; } var arr = [ 9 , 6 , 5 , 1 ] ; var N = arr . length ; findOptimalPairs ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function countBits ( a ) { let count = 0 ; while ( a > 0 ) { if ( ( a & 1 ) > 0 ) count += 1 ; a = a >> 1 ; } return count ; } function insertionSort ( arr , aux , n ) { for ( let i = 1 ; i < n ; i ++ ) { let key1 = aux [ i ] ; let key2 = arr [ i ] ; let j = i - 1 ; while ( j >= 0 && aux [ j ] < key1 ) { aux [ j + 1 ] = aux [ j ] ; arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } aux [ j + 1 ] = key1 ; arr [ j + 1 ] = key2 ; } } function sortBySetBitCount ( arr , n ) { let aux = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) aux [ i ] = countBits ( arr [ i ] ) ; insertionSort ( arr , aux , n ) ; } function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; sortBySetBitCount ( arr , n ) ; printArr ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countBits ( a ) { let count = 0 ; while ( a > 0 ) { if ( ( a & 1 ) > 0 ) count += 1 ; a = a >> 1 ; } return count ; } function sortBySetBitCount ( arr , n ) { let count = new Array ( 32 ) ; for ( let i = 0 ; i < count . length ; i ++ ) count [ i ] = [ ] ; let setbitcount = 0 ; for ( let i = 0 ; i < n ; i ++ ) { setbitcount = countBits ( arr [ i ] ) ; count [ setbitcount ] . push ( arr [ i ] ) ; } let j = 0 ; for ( let i = 31 ; i >= 0 ; i -- ) { let v1 = count [ i ] ; for ( let p = 0 ; p < v1 . length ; p ++ ) arr [ j ++ ] = v1 [ p ] ; } } function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; sortBySetBitCount ( arr , n ) ; printArr ( arr , n ) ;

Index/key variables: i, p, setbitcount
Accumulator variables: count, i, j, p
Iterator variables: i, p
Javascript program:
function generateString ( k1 , k2 , s ) { let C1s = 0 , C0s = 0 ; let flag = 0 ; let pos = [ ] ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { C0s ++ ; if ( ( i + 1 ) % k1 != 0 && ( i + 1 ) % k2 != 0 ) { pos . push ( i ) ; } } else { C1s ++ ; } if ( C0s >= C1s ) { if ( pos . length == 0 ) { cout << - 1 ; flag = 1 ; break ; } else { let k = pos [ pos . length - 1 ] ; var ns = s . replace ( s [ k ] , ' ' ) ; C0s -- ; C1s ++ ; pos . pop ( ) ; } } } if ( flag == 0 ) { document . write ( ns ) ; } } let K1 = 2 , K2 = 4 ; let S = " " ; generateString ( K1 , K2 , S ) ;

Index/key variables: i, k
Accumulator variables: C0s, C1s, i
Iterator variables: i
Javascript program:
function maximizeProduct ( N ) { let MSB = Math . log2 ( N ) ; let X = 1 << MSB ; let Y = N - ( 1 << MSB ) ; for ( let i = 0 ; i < MSB ; i ++ ) { if ( ! ( N & ( 1 << i ) ) ) { X += 1 << i ; Y += 1 << i ; } } document . write ( X + " " + Y ) ; } let N = 45 ; maximizeProduct ( N ) ;

Accumulator variables: X, Y, i
Iterator variables: i
Javascript program:
function check ( num ) { let sm = 0 ; let num2 = num * num ; while ( num ) { sm += num % 10 ; num = Math . floor ( num / 10 ) ; } let sm2 = 0 ; while ( num2 ) { sm2 += num2 % 10 ; num2 = Math . floor ( num2 / 10 ) ; } return sm * sm == sm2 ; } function convert ( s ) { let val = 0 ; s = s . split ( " " ) . reverse ( ) . join ( " " ) ; let cur = 1 ; for ( let i = 0 ; i < s . length ; i ++ ) { val += ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) * cur ; cur *= 10 ; } return val ; } function generate ( s , len , uniq ) { if ( s . length == len ) { if ( check ( convert ( s ) ) ) { uniq . add ( convert ( s ) ) ; } return ; } for ( let i = 0 ; i <= 3 ; i ++ ) { generate ( s + String . fromCharCode ( i + " " . charCodeAt ( 0 ) ) , len , uniq ) ; } } function totalNumbers ( L , R ) { let ans = 0 ; let max_len = Math . log10 ( R ) + 1 ; let uniq = new Set ( ) ; for ( let i = 1 ; i <= max_len ; i ++ ) { generate ( " " , i , uniq ) ; } for ( let x of uniq ) { if ( x >= L && x <= R ) { ans ++ ; } } return ans ; } let L = 22 , R = 22 ; document . write ( totalNumbers ( L , R ) ) ;

Index/key variables: i
Accumulator variables: ans, cur, i, sm, sm2, val
Iterator variables: i, x
Javascript program:
function convertXintoY ( X , Y ) { while ( Y > X ) { if ( Y % 2 == 0 ) Y = parseInt ( Y / 2 ) ; else if ( Y % 10 == 1 ) Y = parseInt ( Y /= 10 ) ; else break ; } if ( X == Y ) document . write ( " " ) ; else document . write ( " " ) ; } let X = 100 , Y = 40021 ; convertXintoY ( X , Y ) ;

Accumulator variables: Y
Javascript program:
function generateString ( K ) { var s = " " ; for ( var i = 97 ; i < 97 + K ; i ++ ) { s = s + String . fromCharCode ( i ) ; for ( var j = i + 1 ; j < 97 + K ; j ++ ) { s += String . fromCharCode ( i ) ; s += String . fromCharCode ( j ) ; } } s += String . fromCharCode ( 97 ) ; document . write ( s ) ; } var K = 4 ; generateString ( K ) ;

Accumulator variables: i, j, s
Iterator variables: i, j
Javascript program:
function minSteps ( a , n ) { var prefix_sum = Array ( n ) . fill ( 0 ) ; prefix_sum [ 0 ] = a [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) prefix_sum [ i ] += prefix_sum [ i - 1 ] + a [ i ] ; var mx = - 1 ; for ( var subgroupsum = 0 ; subgroupsum < prefix_sum . length ; subgroupsum ++ ) { var sum = 0 ; var i = 0 ; var grp_count = 0 ; while ( i < n ) { sum += a [ i ] ; if ( sum == prefix_sum [ subgroupsum ] ) { grp_count += 1 ; sum = 0 ; } else if ( sum > prefix_sum [ subgroupsum ] ) { grp_count = - 1 ; break ; } i += 1 ; } if ( grp_count > mx ) mx = grp_count ; } return n - mx ; } var A = [ 1 , 2 , 3 , 2 , 1 , 3 ] ; var N = A . length ; document . write ( minSteps ( A , N ) ) ;

Index/key variables: i, subgroupsum
Accumulator variables: grp_count, i, subgroupsum, sum
Iterator variables: i, subgroupsum
Javascript program:
function maxOccuringCharacter ( s ) { var count0 = 0 , count1 = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { count1 ++ ; } else if ( s . charAt ( i ) == ' ' ) { count0 ++ ; } } var prev = - 1 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { prev = i ; break ; } } for ( var i = prev + 1 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) != ' ' ) { if ( s . charAt ( i ) == ' ' ) { count1 += i - prev - 1 ; prev = i ; } else { flag = true ; for ( var j = i + 1 ; j < s . length ; j ++ ) { if ( s . charAt ( j ) == ' ' ) { flag = false ; prev = j ; break ; } } if ( ! flag ) { i = prev ; } else { i = s . length ; } } } } prev = - 1 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { prev = i ; break ; } } for ( var i = prev + 1 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) != ' ' ) { if ( s . charAt ( i ) == ' ' ) { count0 += i - prev - 1 ; prev = i ; } else { flag = true ; for ( var j = i + 1 ; j < s . length ; j ++ ) { if ( s . charAt ( j ) == ' ' ) { prev = j ; flag = false ; break ; } } if ( ! flag ) { i = prev ; } else { i = s . length ; } } } } if ( s . charAt ( 0 ) == ' ' ) { var count = 0 ; var i = 0 ; while ( s . charAt ( i ) == ' ' ) { count ++ ; i ++ ; } if ( s . charAt ( i ) == ' ' ) { count1 += count ; } } if ( s . charAt ( s . length - 1 ) == ' ' ) { var count = 0 ; var i = s . length - 1 ; while ( s . charAt ( i ) == ' ' ) { count ++ ; i -- ; } if ( s . charAt ( i ) == ' ' ) { count0 += count ; } } if ( count0 == count1 ) { document . write ( " " ) ; } else if ( count0 > count1 ) { document . write ( 0 ) ; } else document . write ( 1 ) ; } var S = " " ; maxOccuringCharacter ( S ) ;

Accumulator variables: count, count0, count1, i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function maxSheets ( A , B ) { let area = A * B ; let count = 1 ; while ( area % 2 == 0 ) { area /= 2 ; count *= 2 ; } return count ; } let A = 5 , B = 10 ; document . write ( maxSheets ( A , B ) ) ;

Accumulator variables: area, count
Javascript program:
function minMoves ( arr ) { let N = arr . length ; if ( N <= 2 ) return 0 ; let ans = Number . MAX_VALUE ; for ( let i = - 1 ; i <= 1 ; i ++ ) { for ( let j = - 1 ; j <= 1 ; j ++ ) { let num1 = arr [ 0 ] + i ; let num2 = arr [ 1 ] + j ; let flag = 1 ; let moves = Math . abs ( i ) + Math . abs ( j ) ; for ( let idx = 2 ; idx < N ; idx ++ ) { let num = num1 + num2 ; if ( Math . abs ( arr [ idx ] - num ) > 1 ) flag = 0 ; else moves += Math . abs ( arr [ idx ] - num ) ; num1 = num2 ; num2 = num ; } if ( flag > 0 ) ans = Math . min ( ans , moves ) ; } } if ( ans == Number . MAX_VALUE ) return - 1 ; return ans ; } let arr = [ 4 , 8 , 9 , 17 , 27 ] ; document . write ( minMoves ( arr ) ) ;

Index/key variables: idx
Accumulator variables: i, idx, j, moves
Iterator variables: i, idx, j
Javascript program:
function querySum ( arr , N , Q , M ) { for ( let i = 0 ; i < M ; i ++ ) { let x = Q [ i ] [ 0 ] ; let y = Q [ i ] [ 1 ] ; let sum = 0 ; while ( x < N ) { sum += arr [ x ] ; x += y ; } document . write ( sum + " " ) ; } } let arr = [ 1 , 2 , 7 , 5 , 4 ] ; let Q = [ [ 2 , 1 ] , [ 3 , 2 ] ] ; let N = arr . length ; let M = Q . length ; querySum ( arr , N , Q , M ) ;

Index/key variables: i, x
Accumulator variables: i, sum, x
Iterator variables: i
Javascript program:
function countOfSubarray ( arr , N ) { var mp = new Map ( ) ; var answer = 0 ; var sum = 0 ; if ( ! mp . has ( 1 ) ) mp . set ( 1 , 1 ) else mp . set ( 1 , mp . get ( 1 ) + 1 ) for ( var i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; answer += mp . has ( sum - i ) ? mp . get ( sum - i ) : 0 ; if ( mp . has ( sum - i ) ) mp . set ( sum - i , mp . get ( sum - i ) + 1 ) else mp . set ( sum - i , 1 ) } document . write ( answer ) ; } var arr = [ 1 , 0 , 2 , 1 , 2 , - 2 , 2 , 4 ] ; var N = arr . length ; countOfSubarray ( arr , N ) ;

Index/key variables: i
Accumulator variables: answer, i, sum
Iterator variables: i
Javascript program:
function minAbsDiff ( N ) { var sumSet1 = 0 ; var sumSet2 = 0 ; for ( i = N ; i > 0 ; i -- ) { if ( sumSet1 <= sumSet2 ) { sumSet1 += i ; } else { sumSet2 += i ; } } return Math . abs ( sumSet1 - sumSet2 ) ; } var N = 6 ; document . write ( minAbsDiff ( N ) ) ;

Accumulator variables: i, sumSet1, sumSet2
Iterator variables: i
Javascript program:
function checkDigits ( n ) { do { var r = n % 10 ; if ( r == 3 r == 4 r == 6 r == 7 r == 9 ) return false ; n = parseInt ( n / 10 ) ; } while ( n != 0 ) ; return true ; } function isPrime ( n ) { if ( n <= 1 ) return false ; for ( var i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function isAllPrime ( n ) { return isPrime ( n ) && checkDigits ( n ) ; } var N = 101 ; if ( isAllPrime ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( str , a , b ) { let openUnbalanced = 0 ; let closedUnbalanced = 0 ; let openCount = 0 ; let closedCount = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { openUnbalanced ++ ; openCount ++ ; } else { if ( openUnbalanced == 0 ) closedUnbalanced ++ ; else openUnbalanced -- ; closedCount ++ ; } } let result = a * ( Math . abs ( openCount - closedCount ) ) ; if ( closedCount > openCount ) closedUnbalanced -= ( closedCount - openCount ) ; if ( openCount > closedCount ) openUnbalanced -= ( openCount - closedCount ) ; result += Math . min ( a * ( openUnbalanced + closedUnbalanced ) , b * closedUnbalanced ) ; document . write ( result + " " ) ; } let str = " " ; let A = 1 , B = 3 ; minCost ( str , A , B ) ;

Index/key variables: i
Accumulator variables: closedCount, closedUnbalanced, i, openCount, openUnbalanced, result
Iterator variables: i
Javascript program:
function countEvenSum ( low , high , k ) { let even_count = high / 2 - ( low - 1 ) / 2 ; let odd_count = ( high + 1 ) / 2 - low / 2 ; let even_sum = 1 ; let odd_sum = 0 ; for ( let i = 0 ; i < k ; i ++ ) { let prev_even = even_sum ; let prev_odd = odd_sum ; even_sum = ( prev_even * even_count ) + ( prev_odd * odd_count ) ; odd_sum = ( prev_even * odd_count ) + ( prev_odd * even_count ) ; } document . write ( even_sum ) ; } let low = 4 ; let high = 5 ; let K = 3 ; countEvenSum ( low , high , K ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findShifts ( A , N ) { let shift = Array . from ( { length : N } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( i == A [ i ] - 1 ) shift [ i ] = 0 ; else shift [ i ] = ( A [ i ] - 1 - i + N ) % N ; } for ( let i = 0 ; i < N ; i ++ ) document . write ( shift [ i ] + " " ) ; } let arr = [ 1 , 4 , 3 , 2 , 5 ] ; let N = arr . length ; findShifts ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function constructmatrix ( N ) { let check = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) { document . write ( " " ) ; } else if ( check ) { document . write ( " " ) ; check = false ; } else { document . write ( " " ) ; check = true ; } } document . write ( " " ) ; } } let N = 5 ; constructmatrix ( 5 ) ;

Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: check
Javascript program:
function check ( unit_digit , X ) { let times , digit ; for ( times = 1 ; times <= 10 ; times ++ ) { digit = ( X * times ) % 10 ; if ( digit == unit_digit ) return times ; } return - 1 ; } function getNum ( N , X ) { let unit_digit ; unit_digit = N % 10 ; let times = check ( unit_digit , X ) ; if ( times == - 1 ) return times ; else { if ( N >= ( times * X ) ) return times ; else return - 1 ; } } let N = 58 , X = 7 ; document . write ( getNum ( N , X ) ) ;

Accumulator variables: times
Iterator variables: times
Javascript program:
function getLargestString ( s , k ) { let frequency_array = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { frequency_array [ i ] = 0 ; } for ( let i = 0 ; i < s . length ; i ++ ) { frequency_array [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let ans = " " ; for ( let i = 25 ; i >= 0 ; ) { if ( frequency_array [ i ] > k ) { let temp = k ; let st = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; while ( temp > 0 ) { ans += st ; temp -- ; } frequency_array [ i ] -= k ; let j = i - 1 ; while ( frequency_array [ j ] <= 0 && j >= 0 ) { j -- ; } if ( frequency_array [ j ] > 0 && j >= 0 ) { let str = String . fromCharCode ( j + ' ' . charCodeAt ( 0 ) ) ; ans += str ; frequency_array [ j ] -= 1 ; } else { break ; } } else if ( frequency_array [ i ] > 0 ) { let temp = frequency_array [ i ] ; frequency_array [ i ] -= temp ; let st = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; while ( temp > 0 ) { ans += st ; temp -- ; } } else { i -- ; } } return ans ; } let S = " " ; let k = 3 ; document . write ( getLargestString ( S , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j, temp
Iterator variables: i
Javascript program:
function minOperations ( a , b , n ) { var minA = Math . max . apply ( Math , a ) ; ; for ( x = minA ; x >= 0 ; x -- ) { var check = true ; var operations = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( x % b [ i ] == a [ i ] % b [ i ] ) { operations += ( a [ i ] - x ) / b [ i ] ; } else { check = false ; break ; } } if ( check ) return operations ; } return - 1 ; } var N = 5 ; var A = [ 5 , 7 , 10 , 5 , 15 ] ; var B = [ 2 , 2 , 1 , 3 , 5 ] ; document . write ( minOperations ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i, operations, x
Iterator variables: i, x
Boolean variables: check
Javascript program:
function getLargestSum ( N ) { var max_sum = 0 ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = i + 1 ; j <= N ; j ++ ) { if ( i * j % ( i + j ) == 0 ) max_sum = Math . max ( max_sum , i + j ) ; } } return max_sum ; } var N = 25 ; var max_sum = getLargestSum ( N ) ; document . write ( max_sum ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxSubArraySum ( a , size ) { var max_so_far = Number . MIN_VALUE , max_ending_here = 0 ; for ( i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } function maxSum ( a , n ) { var S = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) S += a [ i ] ; var X = maxSubArraySum ( a , n ) ; return 2 * X - S ; } var a = [ - 1 , - 2 , - 3 ] ; var n = a . length ; var max_sum = maxSum ( a , n ) ; document . write ( max_sum ) ;

Index/key variables: i
Accumulator variables: S, i
Iterator variables: i
Javascript program:
function isPrime ( n ) { let flag = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { flag = 0 ; break ; } } return ( flag == 1 ? true : false ) ; } function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function countInterestingPrimes ( n ) { let answer = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( isPrime ( i ) ) { for ( let j = 1 ; j * j * j * j <= i ; j ++ ) { if ( isPerfectSquare ( i - j * j * j * j ) ) { answer ++ ; break ; } } } } return answer ; } let N = 10 ; document . write ( countInterestingPrimes ( N ) ) ;

Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function decBinary ( arr , n ) { let k = Math . log2 ( n ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n = Math . floor ( n / 2 ) ; } } function binaryDec ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } function maxNum ( n , k ) { let l = Math . log2 ( n ) + 1 ; let a = new Array ( l ) . fill ( 0 ) ; decBinary ( a , n ) ; let cn = 0 ; for ( let i = 0 ; i < l ; i ++ ) { if ( a [ i ] == 0 && cn < k ) { a [ i ] = 1 ; cn ++ ; } } return binaryDec ( a , l ) ; } let n = 4 , k = 1 ; document . write ( maxNum ( n , k ) ) ;

Index/key variables: i
Accumulator variables: ans, cn, i, k
Iterator variables: i
Javascript program:
function findSubSeq ( arr , n , sum ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( sum < arr [ i ] ) arr [ i ] = - 1 ; else sum -= arr [ i ] ; } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != - 1 ) document . write ( arr [ i ] + " " ) ; } } let arr = [ 17 , 25 , 46 , 94 , 201 , 400 ] ; let n = arr . length ; let sum = 272 ; findSubSeq ( arr , n , sum ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
const MAX = 26 ; function maxAlpha ( str , len ) { var first = new Array ( MAX ) ; var last = new Array ( MAX ) ; for ( var i = 0 ; i < MAX ; i ++ ) { first [ i ] = - 1 ; last [ i ] = - 1 ; } for ( var i = 0 ; i < len ; i ++ ) { var index = str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; if ( first [ index ] === - 1 ) first [ index ] = i ; last [ index ] = i ; } var ans = - 1 , maxVal = - 1 ; for ( var i = 0 ; i < MAX ; i ++ ) { if ( first [ i ] === - 1 ) continue ; if ( last [ i ] - first [ i ] > maxVal ) { maxVal = last [ i ] - first [ i ] ; ans = i ; } } return String . fromCharCode ( ans + " " . charCodeAt ( 0 ) ) ; } var str = " " ; var len = str . length ; document . write ( maxAlpha ( str , len ) ) ;

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