dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countCandies ( arr , n ) { let sum = 0 ; let ans = new Array ( n ) ; if ( n == 1 ) { return 1 ; } for ( let i = 0 ; i < n ; i ++ ) ans [ i ] = 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i + 1 ] > arr [ i ] && ans [ i + 1 ] <= ans [ i ] ) { ans [ i + 1 ] = ans [ i ] + 1 ; } } for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] && ans [ i ] <= ans [ i + 1 ] ) { ans [ i ] = ans [ i + 1 ] + 1 ; } else if ( arr [ i ] == arr [ i + 1 ] && ans [ i ] < ans [ i + 1 ] ) { ans [ i ] = ans [ i + 1 ] + 1 ; } sum += ans [ i ] ; } sum += ans [ n - 1 ] ; return sum ; } let arr = [ 1 , 0 , 2 ] ; let N = arr . length ; document . write ( countCandies ( arr , N ) )

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findMaximumProfit ( arr , M , N ) { let max_heap = [ ] ; let maxProfit = 0 ; for ( let i = 0 ; i < N ; i ++ ) max_heap . push ( arr [ i ] ) ; max_heap . sort ( function ( a , b ) { return a - b } ) ; max_heap . reverse ( ) ; while ( M > 0 ) { M -- ; let X = max_heap [ 0 ] ; max_heap . shift ( ) ; maxProfit += X ; max_heap . push ( X - 1 ) ; max_heap . sort ( function ( a , b ) { return a - b } ) ; max_heap . reverse ( ) ; } document . write ( maxProfit ) ; } let arr = [ 4 , 6 ] ; let M = 4 ; let N = arr . length ; findMaximumProfit ( arr , M , N ) ;

Index/key variables: i
Accumulator variables: M, i, maxProfit
Iterator variables: i
Javascript program:
function findSequence ( n , k ) { let arr = new Array ( n ) ; let sumPos = 0 , sumNeg = 0 ; for ( let i = 0 ; i < n - k ; i ++ ) { arr [ i ] = - ( i + 1 ) ; sumNeg += arr [ i ] ; } for ( let i = n - k ; i < n ; i ++ ) { arr [ i ] = i + 1 ; sumPos += arr [ i ] ; } if ( Math . abs ( sumNeg ) >= sumPos ) { document . write ( - 1 ) ; return ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let N = 10 , K = 6 ; findSequence ( N , K ) ;

Index/key variables: i
Accumulator variables: i, sumNeg, sumPos
Iterator variables: i
Javascript program:
function findPath ( arr , M , N ) { for ( let row = 0 ; row < M ; row ++ ) { let dir = ' ' ; let i = row ; let j = 0 ; while ( j < N ) { if ( arr [ i ] [ j ] == 1 ) { if ( dir == ' ' ) { i -- ; dir = ' ' ; } else if ( dir == ' ' ) { j -- ; dir = ' ' ; } else if ( dir == ' ' ) { i ++ ; dir = ' ' ; } else if ( dir == ' ' ) { j ++ ; dir = ' ' ; } } else { if ( dir == ' ' ) { i ++ ; dir = ' ' ; } else if ( dir == ' ' ) { j ++ ; dir = ' ' ; } else if ( dir == ' ' ) { i -- ; dir = ' ' ; } else if ( dir == ' ' ) { j -- ; dir = ' ' ; } } if ( i < 0 i == M j < 0 j == N ) break ; } if ( j == N ) document . write ( i + " " ) ; else document . write ( - 1 + " " ) ; } } let arr = [ [ 1 , 1 , 0 , 1 ] , [ 1 , 1 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 1 ] ] ; let M = arr . length ; let N = arr [ 0 ] . length ; findPath ( arr , M , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, row
Iterator variables: row
Javascript program:
function getSum ( n ) { let ans = 0 ; let arr = n . toString ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { ans += arr [ i ] ; } return ans ; } function getMax ( arr , n ) { let maxRem0 = 0 ; let rem1 = 0 ; let rem2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let digitSum = getSum ( arr [ i ] ) ; if ( digitSum % 3 == 0 ) maxRem0 = Math . max ( maxRem0 , arr [ i ] ) ; else if ( digitSum % 3 == 1 ) rem1 += arr [ i ] ; else rem2 += arr [ i ] ; } document . write ( maxRem0 + Math . max ( rem1 , rem2 ) ) } let arr = [ 23 , 12 , 43 , 3 , 56 ] ; let n = arr . length ; getMax ( arr , n ) ;

Index/key variables: i
Accumulator variables: ans, i, rem1, rem2
Iterator variables: i
Javascript program:
function findMin ( arr , N , k ) { let pairs = 0 ; for ( let i = 0 ; i < N ; i ++ ) { pairs += arr [ i ] / 2 ; } if ( k > pairs ) return - 1 ; else return 2 * k + N - 1 ; } let arr = [ 4 , 5 , 6 ] ; let K = 3 ; let N = arr . length ; document . write ( findMin ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, pairs
Iterator variables: i
Javascript program:
function minimumFlips ( A , B , C ) { var res = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { var x = 0 , y = 0 , z = 0 ; if ( ( A & ( 1 << i ) ) != 0 ) { x = 1 ; } if ( ( B & ( 1 << i ) ) != 0 ) { y = 1 ; } if ( ( C & ( 1 << i ) ) != 0 ) { z = 1 ; } if ( z == 0 ) { if ( x == 1 ) { res ++ ; } if ( y == 1 ) { res ++ ; } } if ( z == 1 ) { if ( x == 0 && y == 0 ) { res ++ ; } } } return res ; } var A = 2 , B = 6 , C = 5 ; document . write ( minimumFlips ( A , B , C ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
let prefixCount = [ [ ] ] ; function findPrefixCount ( arr , size ) { for ( let i = 0 ; i < 32 ; i ++ ) { prefixCount [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( let j = 1 ; j < size ; j ++ ) { prefixCount [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefixCount [ i ] [ j ] += prefixCount [ i ] [ j - 1 ] ; } } } function arrayBitwiseAND ( size ) { let result = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) { let temp = prefixCount [ i ] [ size - 1 ] ; if ( temp == size ) result = ( result | ( 1 << i ) ) ; } document . write ( result + " " ) ; } function applyQuery ( currentVal , newVal , size ) { for ( let i = 0 ; i < 32 ; i ++ ) { let bit1 = ( ( currentVal >> i ) & 1 ) ; let bit2 = ( ( newVal >> i ) & 1 ) ; if ( bit2 > 0 && bit1 == 0 ) prefixCount [ i ] [ size - 1 ] ++ ; else if ( bit1 > 0 && bit2 == 0 ) prefixCount [ i ] [ size - 1 ] -- ; } } function findbitwiseAND ( queries , arr , N , M ) { prefixCount = new Array ( 32 ) ; for ( var i = 0 ; i < prefixCount . length ; i ++ ) { prefixCount [ i ] = new Array ( 2 ) ; } findPrefixCount ( arr , N ) ; for ( let i = 0 ; i < M ; i ++ ) { let id = queries [ i ] [ 0 ] ; let newVal = queries [ i ] [ 1 ] ; let currentVal = arr [ id ] ; arr [ id ] = newVal ; applyQuery ( currentVal , newVal , N ) ; arrayBitwiseAND ( N ) ; } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let queries = [ [ 0 , 2 ] , [ 3 , 3 ] , [ 4 , 2 ] ] ; let N = arr . length ; let M = queries . length ; findbitwiseAND ( queries , arr , N , M ) ;

Index/key variables: i, id, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function evenXorSubarray ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let XOR = 0 ; for ( let j = i ; j < n ; j ++ ) { XOR = XOR ^ arr [ j ] ; if ( ( XOR & 1 ) == 0 ) ans ++ ; } } document . write ( ans ) ; } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; evenXorSubarray ( arr , N ) ;

Index/key variables: j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function makeSumEqual ( a , b , K , M , N ) { let sum1 = 0 ; let sum2 = 0 ; for ( let el = 0 ; el < a . length ; el ++ ) sum1 += a [ el ] ; for ( let el = 0 ; el < b . length ; el ++ ) sum2 += b [ el ] ; let diff = sum1 - sum2 ; let l1 = 0 , r1 = M - 1 ; let l2 = 0 , r2 = N - 1 ; let res = 0 ; a . sort ( function ( c , d ) { return c - d ; } ) ; b . sort ( function ( c , d ) { return c - d ; } ) ; while ( l1 <= r1 l2 <= r2 ) { if ( diff == 0 ) { break ; } if ( diff > 0 ) { if ( l2 <= r2 && l1 <= r1 ) { if ( K - b [ l2 ] < a [ r1 ] - 1 ) { let sub = Math . min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { let sub = Math . min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else if ( l1 <= r1 ) { let sub = Math . min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { let sub = Math . min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else { if ( l1 <= r1 && l2 <= r2 ) { if ( K - a [ l1 ] < b [ r2 ] - 1 ) { let sub = Math . min ( b [ r2 ] - 1 , - 1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { let sub = Math . min ( K - a [ l1 ] , - 1 * diff ) ; diff += sub ; a [ l1 ] -= sub ; l1 ++ ; } } else if ( l2 <= r2 ) { let sub = Math . min ( b [ r2 ] - 1 , - 1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { let sub = Math . min ( K - a [ l1 ] , diff ) ; diff += sub ; a [ l1 ] += sub ; l1 ++ ; } } res ++ ; } if ( diff == 0 ) return res ; else return - 1 ; } let A = [ 1 , 4 , 3 ] ; let B = [ 6 , 6 , 6 ] ; let M = A . length ; let N = B . length ; let K = 6 ; document . write ( makeSumEqual ( A , B , K , M , N ) ) ;

Index/key variables: el, l1, l2, r1, r2
Accumulator variables: diff, el, l1, l2, r1, r2, res, sum1, sum2
Iterator variables: el
Javascript program:
function findString ( S , N ) { var strLen = 4 * N ; for ( var i = 1 ; i <= N ; i ++ ) { S [ strLen - 1 ] = " " ; strLen -= 2 ; } for ( var i = 0 ; i < 4 * N ; i ++ ) { document . write ( S [ i ] ) ; } } var N = 2 ; var S = [ ... Array ( 4 * N ) ] ; for ( var i = 0 ; i < 4 * N ; i ++ ) S [ i ] = " " ; findString ( S , N ) ;

Index/key variables: i
Accumulator variables: i, strLen
Iterator variables: i
Javascript program:
function isVowel ( ch ) { if ( ch === " " ch === " " ch === " " ch === " " ch === " " ) return true ; if ( ch === " " ch === " " ch === " " ch === " " ch === " " ) return true ; return false ; } function containsEqualStrings ( S ) { var totalVowels = 0 ; for ( var i = 0 ; i < S . length ; i ++ ) { if ( isVowel ( S [ i ] ) ) totalVowels ++ ; } var vowelsTillNow = 0 ; for ( var i = 0 ; i < S . length ; i ++ ) { if ( isVowel ( S [ i ] ) ) { vowelsTillNow ++ ; totalVowels -- ; if ( vowelsTillNow === totalVowels ) { return " " ; } } } return " " ; } var S = " " ; document . write ( containsEqualStrings ( S ) ) ;

Index/key variables: i
Accumulator variables: i, totalVowels, vowelsTillNow
Iterator variables: i
Javascript program:
function getMaxSum ( A , M , N ) { let sum = 0 ; let negative = 0 ; let minVal = Number . MAX_VALUE ; for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { sum += Math . abs ( A [ i ] [ j ] ) ; if ( A [ i ] [ j ] < 0 ) { negative ++ ; } minVal = Math . min ( minVal , Math . abs ( A [ i ] [ j ] ) ) ; } } if ( negative % 2 != 0 ) { sum -= 2 * minVal ; } document . write ( sum ) ; } let A = [ [ 4 , - 8 , 6 ] , [ 3 , 7 , 2 ] ] ; let M = A . length ; let N = A [ 0 ] . length ; getMaxSum ( A , M , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, negative, sum
Iterator variables: i, j
Javascript program:
function areaToPaint ( N , W , L , Heights ) { let total = 0 ; for ( let i = 0 ; i < N ; i ++ ) { total += 2 * Heights [ i ] * W ; } total += L * ( Heights [ 0 ] + Heights [ N - 1 ] ) ; for ( let i = 1 ; i < N ; i ++ ) { total += L * Math . abs ( Heights [ i ] - Heights [ i - 1 ] ) ; } document . write ( total ) ; } let N = 7 , W = 1 , L = 1 ; let Heights = [ 4 , 3 , 1 , 2 , 3 , 4 , 2 ] ; areaToPaint ( N , W , L , Heights ) ;

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Javascript program:
function restoreGem ( r , c ) { let dp = new Array ( r . length ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < r . length ; i ++ ) { for ( let j = 0 ; j < c . length ; j ++ ) { let m = Math . min ( r [ i ] , c [ j ] ) ; dp [ i ] [ j ] = m ; r [ i ] -= m ; c [ j ] -= m ; } } return dp ; } function prletMatrix ( ans , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( ans [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let rowSum = [ 5 , 7 , 10 ] ; let colSum = [ 8 , 6 , 8 ] ; let ans = restoreGem ( rowSum , colSum ) ; prletMatrix ( ans , rowSum . length , colSum . length ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 1000000 ; function maxSumOfDistinctPrimeFactors ( arr , N , K ) { let CountDistinct = [ ] ; for ( let i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; } let prime = [ ] ; for ( let i = 0 ; i <= MAX ; i ++ ) { prime [ i ] = 0 ; } for ( let i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; prime [ i ] = true ; } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) { CountDistinct [ i ] = 1 ; for ( let j = i * 2 ; j <= MAX ; j += i ) { CountDistinct [ j ] ++ ; prime [ j ] = false ; } } } let sum = 0 ; let PrimeFactor = [ ] ; for ( let i = 0 ; i <= 20 ; i ++ ) { PrimeFactor [ i ] = 0 ; } for ( let i = 0 ; i < N ; i ++ ) { PrimeFactor [ CountDistinct [ arr [ i ] ] ] ++ ; } for ( let i = 19 ; i >= 1 ; i -- ) { while ( PrimeFactor [ i ] > 0 ) { sum += i ; PrimeFactor [ i ] -- ; K -- ; if ( K == 0 ) break ; } if ( K == 0 ) break ; } document . write ( sum ) ; } let arr = [ 6 , 9 , 12 ] ; let N = arr . length ; let K = 2 ; maxSumOfDistinctPrimeFactors ( arr , N , K ) ;

Index/key variables: i, j
Accumulator variables: K, i, j, sum
Iterator variables: i, j
Javascript program:
function maxChange ( str ) { if ( str . length <= 1 ) { return 0 ; } var minChanges = 0 ; for ( var i = 0 ; i < str . length - 1 ; i ++ ) { if ( str [ i ] === str [ i + 1 ] ) { str [ i + 1 ] = " " ; minChanges += 1 ; } else if ( i > 0 && str [ i - 1 ] === str [ i + 1 ] ) { str [ i + 1 ] = " " ; minChanges += 1 ; } } return minChanges ; } var str = " " ; document . write ( maxChange ( str . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: i, minChanges
Iterator variables: i
Javascript program:
function findMinKToMakeAllEqual ( N , A ) { var B = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) B . add ( A [ i ] ) ; var M = B . size ; var itr = [ ... B ] . sort ( ( a , b ) => a - b ) ; if ( M > 3 ) document . write ( " " ) ; else if ( M == 3 ) { var B_1 = itr [ 0 ] ; var B_2 = itr [ 1 ] ; var B_3 = itr [ 2 ] ; if ( B_2 - B_1 == B_3 - B_2 ) document . write ( B_2 - B_1 ) ; else document . write ( " " ) ; } else if ( M == 2 ) { var B_1 = itr [ 0 ] ; var B_2 = itr [ 1 ] ; if ( ( B_2 - B_1 ) % 2 == 0 ) document . write ( parseInt ( ( B_2 - B_1 ) / 2 ) ) ; else document . write ( B_2 - B_1 ) ; } else document . write ( 0 ) ; } var A = [ 1 , 3 , 5 , 1 ] ; var N = A . length ; findMinKToMakeAllEqual ( N , A ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function computeLPSArray ( pat , M , lps ) { var len = 0 ; lps [ 0 ] = 0 ; var i = 1 ; while ( i < M ) { if ( pat [ i ] == pat [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } function KMPSearch ( pat , txt ) { var M = pat . length ; var N = txt . length ; var lps = Array ( M ) ; computeLPSArray ( pat , M , lps ) ; var i = 0 ; var j = 0 ; while ( i < N ) { if ( pat [ j ] == txt [ i ] ) { j ++ ; i ++ ; } if ( j == M ) { return 1 ; j = lps [ j - 1 ] ; } else if ( i < N && pat [ j ] != txt [ i ] ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } return 0 ; } function maxRepeating ( seq , word ) { var resCount = 0 ; var curWord = word ; var numWords = seq . length / word . length ; for ( var i = 0 ; i < numWords ; i ++ ) { if ( KMPSearch ( curWord , seq ) ) { curWord += word ; resCount ++ ; } else break ; } document . write ( resCount ) ; } var S1 = " " , S2 = " " ; maxRepeating ( S1 , S2 ) ;

Index/key variables: i, j, len
Accumulator variables: curWord, i, j, len, resCount
Iterator variables: i
Javascript program:
function findMinimumTime ( p , n , target ) { let um = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( um [ p [ i ] ] ) um [ p [ i ] ] ++ ; else um [ p [ i ] ] = 1 } let time = 0 ; let sum = 0 ; while ( sum < target ) { sum = 0 ; time ++ ; for ( let it in um ) { sum += um [ it ] * Math . floor ( time / it ) ; } } document . write ( time ) ; } let arr = [ 1 , 3 , 3 , 4 ] ; let N = arr . length ; let target = 10 ; findMinimumTime ( arr , N , target ) ;

Index/key variables: i, it
Accumulator variables: i, sum, time
Iterator variables: i, it
Javascript program:
var MAXN = 100001 ; function constructMEX ( arr , N ) { var hash = Array ( MAXN ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { hash [ arr [ i ] ] = 1 ; } var MexOfArr ; for ( var i = 1 ; i < MAXN ; i ++ ) { if ( hash [ i ] == 0 ) { MexOfArr = i ; break ; } } var B = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < MexOfArr ) B [ i ] = arr [ i ] ; else B [ i ] = MexOfArr ; } for ( var i = 0 ; i < N ; i ++ ) document . write ( B [ i ] + ' ' ) ; } Given array * / var arr = [ 2 , 1 , 5 , 3 ] ; var N = arr . length ; constructMEX ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function smallestNumberLeftInPQ ( arr , N ) { let pq = [ ] ; let pairsArr = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { pq . push ( arr [ i ] ) ; } pq . sort ( function ( a , b ) { return b - a ; } ) ; while ( pq . length > 1 ) { let X = pq [ 0 ] ; pq . shift ( ) ; let Y = pq [ 0 ] ; pq . shift ( ) ; pq . push ( Math . floor ( ( X + Y + 1 ) / 2 ) ) ; pq . sort ( function ( a , b ) { return b - a ; } ) ; pairsArr . push ( new pair ( X , Y ) ) ; } document . write ( " " + pq [ 0 ] + " " ) ; let sz = pairsArr . length ; for ( let i = 0 ; i < sz ; i ++ ) { if ( i == 0 ) { document . write ( " " ) ; } document . write ( " " + pairsArr [ i ] . first + " " + pairsArr [ i ] . second + " " ) ; if ( i != sz - 1 ) { document . write ( " " ) ; } if ( i == sz - 1 ) { document . write ( " " ) ; } } } let arr = [ 3 , 2 , 1 ] ; let N = arr . length ; smallestNumberLeftInPQ ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: pair
Javascript program:
function findSum ( S , n , x ) { let table = new Array ( n + 1 ) ; for ( var i = 0 ; i < table . length ; i ++ ) { table [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < table . length ; i ++ ) { for ( var j = 0 ; j < table . length ; j ++ ) { table [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= x ; i ++ ) { table [ 0 ] [ i ] = Number . MAX_VALUE - 1 ; } for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= x ; j ++ ) { if ( S [ i - 1 ] > j ) { table [ i ] [ j ] = table [ i - 1 ] [ j ] ; } else { table [ i ] [ j ] = Math . min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) ; } } } return ( table [ n ] [ x ] > n ) ? - 1 : table [ n ] [ x ] ; } function minRemovals ( arr , n , m , x ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } let requied_Sum = 0 ; if ( sum % m < x ) requied_Sum = m + sum % m - x ; else requied_Sum = sum % m - x ; document . write ( findSum ( arr , n , requied_Sum ) ) ; } let arr = [ 3 , 2 , 1 , 2 ] ; let n = arr . length ; let m = 4 , x = 2 ; minRemovals ( arr , n , m , x % m ) ;

Index/key variables: i, j, n, x
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function minChange ( s , n ) { var L = new Array ( 26 ) . fill ( 0 ) ; var R = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n / 2 ; i ++ ) { var ch = s [ i ] . charCodeAt ( 0 ) ; L [ ch - " " . charCodeAt ( 0 ) ] ++ ; } for ( var i = n / 2 ; i < n ; i ++ ) { var ch = s [ i ] . charCodeAt ( 0 ) ; R [ ch - " " . charCodeAt ( 0 ) ] ++ ; } var count = n ; for ( var ch = " " . charCodeAt ( 0 ) ; ch <= " " . charCodeAt ( 0 ) ; ch ++ ) { count = Math . min ( count , n - L [ ch - " " . charCodeAt ( 0 ) ] - R [ ch - " " . charCodeAt ( 0 ) ] ) ; } var change = parseInt ( n / 2 ) ; for ( var d = 0 ; d + 1 < 26 ; d ++ ) { change -= L [ d ] ; change += R [ d ] ; count = Math . min ( count , change ) ; } change = n / 2 ; for ( var d = 0 ; d + 1 < 26 ; d ++ ) { change -= R [ d ] ; change += L [ d ] ; count = Math . min ( change , count ) ; } return count ; } var S = " " ; var N = S . length ; document . write ( minChange ( S , N ) ) ;

Index/key variables: d, i
Accumulator variables: ch, change, d, i
Iterator variables: ch, d, i
Javascript program:
function longestPalinSub ( str ) { var N = str . length ; var hash = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { hash [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } var res1 = [ ] ; var res2 = [ ] ; for ( var i = 0 ; i < 256 ; i ++ ) { for ( var j = 0 ; j < parseInt ( hash [ i ] / 2 ) ; j ++ ) { res1 . push ( String . fromCharCode ( i ) ) ; } for ( var j = parseInt ( ( hash [ i ] + 1 ) / 2 ) ; j < hash [ i ] ; j ++ ) { res2 . push ( String . fromCharCode ( i ) ) ; } } res2 = res2 . reverse ( ) ; var res3 = [ ] ; var f = false ; for ( var i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % 2 ) { if ( ! f ) { res1 . push ( String . fromCharCode ( i ) ) ; f = true ; } else { res3 . push ( String . fromCharCode ( i ) ) ; } } } return ( res1 . join ( ' ' ) + res2 . join ( ' ' ) + res3 . join ( ' ' ) ) ; } var str = " " ; document . write ( longestPalinSub ( str ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: f
Javascript program:
function No_Of_subsequences ( mp ) { var count = 0 ; var left = 0 ; mp . forEach ( ( value , key ) => { value += left ; count += ( value / key ) ; left = value % key ; } ) ; return count ; } function maximumsubsequences ( 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 ) ; } document . write ( No_Of_subsequences ( mp ) ) ; } var arr = [ 1 , 1 , 1 , 1 ] ; var N = arr . length ; maximumsubsequences ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i, value
Iterator variables: i
Javascript program:
function check ( arr , pieces ) { var m = new Map ( ) ; for ( var i = 0 ; i < arr . length ; i ++ ) m . set ( arr [ i ] , i + 1 ) for ( var i = 0 ; i < pieces . length ; i ++ ) { if ( pieces [ i ] . length == 1 && m . get ( pieces [ i ] [ 0 ] ) != 0 ) { continue ; } else if ( pieces [ i ] . length > 1 && m . get ( pieces [ i ] [ 0 ] ) != 0 ) { var idx = m . get ( pieces [ i ] [ 0 ] ) - 1 ; idx ++ ; if ( idx >= arr . length ) return false ; for ( var j = 1 ; j < pieces [ i ] . length ; j ++ ) { if ( arr [ idx ] == pieces [ i ] [ j ] ) { idx ++ ; if ( idx >= arr . length && j < pieces [ i ] . length - 1 ) return false ; } else { return false ; } } } else { return false ; } } return true ; } var arr = [ 1 , 2 , 4 , 3 ] ; var pieces = [ [ 1 ] , [ 4 , 3 ] , [ 2 ] ] ; if ( check ( arr , pieces ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, idx, j
Accumulator variables: i, idx, j
Iterator variables: i, j
Javascript program:
function makeArraySumEqual ( a , N ) { let count_0 = 0 , count_1 = 0 ; let odd_sum = 0 , even_sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( a [ i ] == 0 ) count_0 ++ ; else count_1 ++ ; if ( ( i + 1 ) % 2 == 0 ) even_sum += a [ i ] ; else if ( ( i + 1 ) % 2 > 0 ) odd_sum += a [ i ] ; } if ( odd_sum == even_sum ) { for ( let i = 0 ; i < N ; i ++ ) document . write ( a [ i ] + " " ) ; } else { if ( count_0 >= N / 2 ) { for ( let i = 0 ; i < count_0 ; i ++ ) document . write ( " " ) ; } else { let is_Odd = count_1 % 2 ; count_1 -= is_Odd ; for ( let i = 0 ; i < count_1 ; i ++ ) document . write ( " " ) ; } } } let arr = [ 1 , 1 , 1 , 0 ] ; let N = arr . length ; makeArraySumEqual ( arr , N ) ;

Index/key variables: i
Accumulator variables: count_0, count_1, even_sum, i, odd_sum
Iterator variables: i
Javascript program:
const maxm = 10001 ; var prime = Array ( ) ; var prime_number = Array ( ) ; function SieveOfEratosthenes ( ) { for ( i = 0 ; i < maxm ; i ++ ) prime [ i ] = true ; for ( p = 2 ; p * p < maxm ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * p ; i < maxm ; i += p ) prime [ i ] = false ; } } prime [ 0 ] = false ; prime [ 1 ] = false ; } function num_prime ( ) { prime_number [ 0 ] = 0 ; for ( i = 1 ; i <= maxm ; i ++ ) { var tmp ; if ( prime [ i ] == true ) { tmp = 1 ; } else { tmp = 0 ; } prime_number [ i ] = prime_number [ i - 1 ] + tmp ; } } function min_steps ( arr , n ) { SieveOfEratosthenes ( ) ; num_prime ( ) ; if ( n == 1 ) { document . write ( " " ) ; } else if ( n == 2 ) { document . write ( " " ) ; } else { document . write ( prime_number [ n ] - 1 + ( n - 2 ) ) ; } } prime_number . fill ( 0 ) ; var arr = [ 5 , 4 , 3 , 2 , 1 ] ; var N = arr . length ; min_steps ( arr , N ) ;

Index/key variables: i, n, p
Accumulator variables: i, p
Iterator variables: i, p