dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countSubArraySignChange ( arr , N ) { let prefixCount = new Map ( ) ; let suffixCount = new Map ( ) ; let total = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { total += arr [ i ] ; if ( suffixCount . has ( arr [ i ] ) ) { suffixCount . set ( arr [ i ] , suffixCount . get ( arr [ i ] ) + 1 ) ; } else { suffixCount . set ( arr [ i ] , 1 ) ; } } let prefixSum = 0 ; let suffixSum = 0 ; let count = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { prefixSum += arr [ i ] ; if ( prefixCount . has ( arr [ i ] ) ) { prefixCount . set ( arr [ i ] , prefixCount . get ( arr [ i ] ) + 1 ) ; } else { prefixCount . set ( arr [ i ] , 1 ) ; } suffixSum = total - prefixSum ; if ( suffixCount . has ( arr [ i ] ) ) { suffixCount . set ( arr [ i ] , suffixCount . get ( arr [ i ] ) - 1 ) ; } let diff = prefixSum - suffixSum ; if ( diff % 2 == 0 ) { let x = ( prefixCount . has ( diff / 2 ) ? prefixCount . get ( diff / 2 ) : 0 ) + ( suffixCount . has ( - diff / 2 ) ? suffixCount . get ( - diff / 2 ) : 0 ) ; count = count + x ; } } return count ; } let arr = [ 2 , 2 , - 3 , 3 ] ; let N = arr . length ; document . write ( countSubArraySignChange ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, prefixSum, total
Iterator variables: i
Javascript program:
function countCommonChar ( ind , S ) { var cnt = 0 ; var ls = new Set ( ) ; var rs = new Set ( ) ; for ( var i = 0 ; i < ind ; ++ i ) { ls . add ( S [ i ] ) ; } for ( var i = ind ; i < S . length ; ++ i ) { rs . add ( S [ i ] ) ; } ls . forEach ( v => { if ( rs . has ( v ) ) { ++ cnt ; } } ) ; return cnt ; } function partitionStringWithMaxCom ( S ) { var ans = 0 ; for ( var i = 1 ; i < S . length ; ++ i ) { ans = Math . max ( ans , countCommonChar ( i , S ) ) ; } document . write ( ans ) ; } var str = " " ; partitionStringWithMaxCom ( str ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function longestSubarray ( s ) { s += ' ' ; let i ; let res = 0 ; let prev_one = 0 ; let curr_one = 0 ; let numberOfZeros = 0 ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { curr_one += 1 ; } else { numberOfZeros += 1 ; prev_one += curr_one ; res = Math . max ( res , prev_one ) ; prev_one = curr_one ; curr_one = 0 ; } } if ( numberOfZeros == 1 ) { res -= 1 ; } return res ; } let S = " " ; document . write ( longestSubarray ( S ) ) ;

Index/key variables: i
Accumulator variables: curr_one, i, numberOfZeros, prev_one, res, s
Iterator variables: i
Javascript program:
function longestSubarray ( s ) { var i = 0 , j = 0 , k = 1 ; for ( j = 0 ; j < s . length ; ++ j ) { if ( s [ j ] == ' ' ) k -- ; if ( k < 0 && s [ i ++ ] == ' ' ) k ++ ; } return j - i - 1 ; } var S = " " ; document . write ( longestSubarray ( S ) ) ;

Index/key variables: j
Accumulator variables: i, k
Iterator variables: j
Javascript program:
function SmallestString ( s , c ) { for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] > c ) { let temp = s ; s = s . substring ( 0 , i ) ; s += c ; s += temp . substring ( i , temp . length ) ; return s ; } } s += c ; return s ; } let S = " " ; let C = ' ' ; document . write ( SmallestString ( S , C ) ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
function LarUnEl ( arr , N ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) ; } var LNRElem = - 1000000000 ; var ind = - 1 ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . get ( arr [ i ] ) == 1 && arr [ i ] > LNRElem ) { ind = i ; LNRElem = arr [ i ] ; } } if ( ind == - 1 ) { cout << ind ; return ; } document . write ( arr [ ind ] ) ; } var arr = [ 3 , 1 , 8 , 8 , 4 ] ; var N = arr . length ; LarUnEl ( arr , N ) ;

Index/key variables: i, ind
Accumulator variables: i
Iterator variables: i
Javascript program:
function countShifts ( str ) { let firstOne = - 1 ; let lastOne = - 1 ; let count = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { if ( firstOne == - 1 ) firstOne = i ; lastOne = i ; } } if ( ( firstOne == - 1 ) || ( firstOne == lastOne ) ) { Console . Write ( 0 ) ; return ; } for ( let i = firstOne ; i <= lastOne ; i ++ ) { if ( str [ i ] == ' ' ) { count ++ ; } } document . write ( count ) ; } let str = " " ; countShifts ( str ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function checkSubsequenceUtil ( arr , L , R , N ) { for ( let i = 0 ; i < L ; i ++ ) if ( arr [ i ] == arr [ L ] ) return true ; for ( let i = R + 1 ; i < N ; i ++ ) if ( arr [ i ] == arr [ R ] ) return true ; return false ; } function checkSubsequence ( arr , L , R , N ) { if ( checkSubsequenceUtil ( arr , L , R , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 ] ; let N = arr . length ; let L = 3 , R = 6 ; checkSubsequence ( arr , L , R , N ) ;

Index/key variables: L, R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; this . prev = null ; } } ; function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) { ( head_ref ) . prev = new_node ; } ( head_ref ) = new_node ; return head_ref ; } function search ( head_ref , x ) { var temp = head_ref ; var pos = 0 ; while ( temp . data != x && temp . next != null ) { pos ++ ; temp = temp . next ; } if ( temp . data != x ) return - 1 ; return ( pos + 1 ) ; } var head = null ; var X = 8 ; head = push ( head , 14 ) ; head = push ( head , 9 ) ; head = push ( head , 8 ) ; head = push ( head , 15 ) ; head = push ( head , 18 ) ; document . write ( search ( head , X ) ) ;

Accumulator variables: pos
Class/struct names: Node
Javascript program:
function largestSubarray ( arr , N , K ) { let count = 0 ; let len = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < K ) { count += 1 ; } else { len = Math . max ( len , count ) ; count = 0 ; } } if ( count != 0 ) { len = Math . max ( len , count ) ; } document . write ( len ) ; } let arr = [ 1 , 8 , 3 , 5 , 2 , 2 , 1 , 13 ] ; let N = arr . length ; let K = 6 ; largestSubarray ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function findPair ( A , N ) { let right_prod = [ ] ; let flag = 0 ; right_prod [ N - 1 ] = A [ N - 1 ] ; for ( let i = N - 2 ; i >= 0 ; i -- ) right_prod [ i ] = right_prod [ i + 1 ] * A [ i ] ; let total_prod = right_prod [ 0 ] ; let product ; for ( let i = 1 ; i < N - 1 ; i ++ ) { product = 1 ; for ( let j = i ; j < N - 1 ; j ++ ) { product *= A [ j ] ; if ( gcd ( product , right_prod [ j + 1 ] ) == 1 || gcd ( product , total_prod / right_prod [ i ] ) == 1 ) { flag = 1 ; document . write ( " " + ( i - 1 ) + " " + ( j + 1 ) + " " ) ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) document . write ( - 1 ) ; } let arr = [ 2 , 4 , 1 , 3 , 7 ] ; let N = arr . length ; findPair ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, product
Iterator variables: i, j
Javascript program:
function countString ( S ) { var count = 0 ; for ( var it = 0 ; it < S . length ; it ++ ) { if ( S [ it ] == ' ' && count > 0 ) { count -- ; } else { count ++ ; } } document . write ( ( 1 << count ) - 1 ) ; } var S = " " ; countString ( S ) ;

Index/key variables: it
Accumulator variables: count, it
Iterator variables: it
Javascript program:
function replaceDuplicates ( names ) { var hash = new Map ( ) ; for ( var i = 0 ; i < names . length ; i ++ ) { if ( ! hash . has ( names [ i ] ) ) hash . set ( names [ i ] , 1 ) ; else { var count = hash . get ( names [ i ] ) ; hash . set ( names [ i ] , hash . get ( names [ i ] ) + 1 ) ; names [ i ] += count . toString ( ) ; } } for ( var i = 0 ; i < names . length ; i ++ ) { document . write ( names [ i ] + " " ) ; } } var str = [ " " , " " , " " , " " , " " , " " , " " ] ; replaceDuplicates ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function convert_to_allzeroes ( str , a , b ) { let len = str . length ; let left_1 , i = 0 ; while ( i < len && str [ i ] == ' ' ) i ++ ; left_1 = i ; let right_1 ; i = len - 1 ; while ( i >= 0 && str [ i ] == ' ' ) i -- ; right_1 = i ; if ( left_1 == len && right_1 == - 1 ) { document . write ( 0 ) ; return ; } let cost = a , zeroes ; for ( i = left_1 ; i <= right_1 ; i ++ ) { zeroes = 0 ; while ( i < len && str [ i ] == ' ' ) { zeroes ++ ; i ++ ; } if ( zeroes != 0 ) cost += Math . min ( zeroes * b , a ) ; } document . write ( cost ) ; } let str = " " ; let A = 5 , B = 1 ; convert_to_allzeroes ( str , A , B ) ;

Index/key variables: i
Accumulator variables: cost, i, zeroes
Iterator variables: i
Javascript program:
function MinDistK ( arr , N , K ) { let res = Number . MAX_VALUE ; let dist = 0 ; for ( let i = 0 ; i <= ( N - K ) ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i + K - 1 ] >= 0 ) { dist = Math . max ( arr [ i ] , arr [ i + K - 1 ] ) ; } else { dist = Math . abs ( arr [ i ] ) + Math . abs ( arr [ i + K - 1 ] ) + Math . min ( Math . abs ( arr [ i ] ) , Math . abs ( arr [ i + K - 1 ] ) ) ; } res = Math . min ( res , dist ) ; } return res ; } let K = 3 ; let arr = [ - 30 , - 10 , 10 , 20 , 50 ] ; let N = arr . length ; document . write ( MinDistK ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function min1 ( a , n ) { let minIndex = 0 , minValue = a [ 0 ] , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < minValue ) { minValue = a [ i ] ; minIndex = i ; } } return minIndex ; } function maximizeMin ( A , N , S , M ) { let minIndex , left , right , i , j ; for ( i = 0 ; i < M ; i ++ ) { minIndex = min1 ( A , N ) ; A [ minIndex ] ++ ; left = minIndex - 1 ; right = minIndex + 1 ; for ( j = 0 ; j < S - 1 ; j ++ ) { if ( left == - 1 ) A [ right ++ ] ++ ; else if ( right == N ) A [ left -- ] ++ ; else { if ( A [ left ] < A [ right ] ) A [ left -- ] ++ ; else A [ right ++ ] ++ ; } } } minIndex = min1 ( A , N ) ; return A [ minIndex ] ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let N = arr . length ; let S = 2 , M = 3 ; document . write ( maximizeMin ( arr , N , S , M ) ) ;

Index/key variables: i, left, minIndex, right
Accumulator variables: i, j, left, right
Iterator variables: i, j
Javascript program:
function sumOfPathNodes ( N ) { if ( N == 1 ) { return 1 ; } else if ( N == 2 N == 3 ) { return N + 1 ; } let arr = [ ] ; arr . push ( 1 ) ; let k = 1 ; let flag = true ; while ( k < N ) { if ( flag == true ) { k *= 2 ; flag = false ; } else { k *= 4 ; flag = true ; } if ( k > N ) { break ; } arr . push ( k ) ; } let len = arr . length ; let prefix = new Array ( len ) ; prefix [ 0 ] = 1 ; for ( let i = 1 ; i < len ; ++ i ) { prefix [ i ] = arr [ i ] + prefix [ i - 1 ] ; } let it = lowerBound ( prefix , 0 , len , N ) + 1 ; let ind = it - prefix [ 0 ] ; let final_ans = 0 ; let temp = N ; while ( ind > 1 ) { let val = temp - prefix [ ind - 1 ] ; if ( ind % 2 != 0 ) { temp = prefix [ ind - 2 ] + parseInt ( ( val + 1 ) / 2 , 10 ) ; } else { temp = prefix [ ind - 2 ] + parseInt ( ( val + 3 ) / 4 , 10 ) ; } -- ind ; final_ans += temp ; } final_ans += ( N + 1 ) ; return final_ans ; } function lowerBound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } let N = 13 ; document . write ( sumOfPathNodes ( N ) + " " ) ;

Index/key variables: i, middle
Accumulator variables: final_ans, k
Iterator variables: i
Boolean variables: flag
Javascript program:
function checkPointRange ( arr , X , Y , N ) { for ( let i = 0 ; i < N ; i ++ ) { let dist = Math . sqrt ( ( arr [ i ] [ 0 ] - X ) * ( arr [ i ] [ 0 ] - X ) + ( arr [ i ] [ 1 ] - Y ) * ( arr [ i ] [ 1 ] - Y ) ) ; if ( dist <= arr [ i ] [ 2 ] ) { return true ; } } return false ; } let arr = [ [ 1 , 1 , 3 ] , [ 10 , 10 , 3 ] , [ 15 , 15 , 15 ] ] ; let X = 5 , Y = 5 ; let N = arr . length ; if ( checkPointRange ( arr , X , Y , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findWinner ( arr , N ) { let odd = 0 ; let even = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { document . write ( " " ) ; } else if ( odd % 2 == 1 ) { document . write ( " " ) ; } } else if ( even == 1 && odd % 2 == 1 ) { document . write ( " " ) ; } else { document . write ( - 1 ) ; } } let arr = [ 3 , 1 , 9 , 7 ] ; let N = arr . length ; findWinner ( arr , N ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function rearrangeArrMaxcntMinima ( arr , N ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; let left = 0 ; let right = Math . floor ( N / 2 ) ; while ( left < Math . floor ( N / 2 ) right < N ) { if ( right < N ) { document . write ( arr [ right ] + " " ) ; right ++ ; } if ( left < Math . floor ( N / 2 ) ) { document . write ( arr [ left ] + " " ) ; left ++ ; } } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; rearrangeArrMaxcntMinima ( arr , N ) ;

Index/key variables: left, right
Accumulator variables: left, right
Javascript program:
let MOD = 1e9 + 7 ; function minJumps ( seats ) { let position = [ ] ; let count = 0 ; let len = seats . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( seats [ i ] == ' ' ) { position . push ( i - count ) ; count ++ ; } } if ( count == len count == 0 ) return 0 ; let med_index = parseInt ( ( count - 1 ) / 2 , 10 ) ; let med_val = position [ med_index ] ; let ans = 0 ; for ( let i = 0 ; i < position . length ; i ++ ) { ans = ( ans % MOD + Math . abs ( position [ i ] - med_val ) % MOD ) % MOD ; } return ans % MOD ; } let S = " " ; document . write ( minJumps ( S ) ) ;

Index/key variables: i, med_index
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function singlePrimeFactor ( N ) { var disPrimeFact = { } ; for ( var i = 2 ; i * i <= N ; ++ i ) { while ( N % i === 0 ) { disPrimeFact [ i ] = 1 ; N = parseInt ( N / i ) ; } } if ( N !== 1 ) { disPrimeFact [ N ] = 1 ; } if ( Object . keys ( disPrimeFact ) . length === 1 ) { for ( const [ key , value ] of Object . entries ( disPrimeFact ) ) { return key ; } } return - 1 ; } function cntsingleFactorPair ( arr , N ) { var countOf1 = 0 ; var mp = { } ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] === 1 ) { countOf1 ++ ; continue ; } var factorValue = singlePrimeFactor ( arr [ i ] ) ; if ( factorValue === - 1 ) { continue ; } else { if ( mp . hasOwnProperty ( factorValue ) ) mp [ factorValue ] = mp [ factorValue ] + 1 ; else mp [ factorValue ] = 1 ; } } var res = 0 ; for ( const [ key , value ] of Object . entries ( mp ) ) { var X = value ; res = parseInt ( res + countOf1 * X + ( X * ( X - 1 ) ) / 2 ) ; } return res ; } var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; document . write ( cntsingleFactorPair ( arr , N ) ) ;

Index/key variables: N, factorValue, i
Accumulator variables: countOf1, i
Iterator variables: i
Javascript program:
function MincntBothPalin ( str1 , str2 , N ) { var i = 0 ; var j = N - 1 ; var cntOp = 0 ; while ( i < j ) { if ( str1 [ i ] === str1 [ j ] && str2 [ i ] !== str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] !== str1 [ j ] && str2 [ i ] === str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] !== str1 [ j ] && str2 [ i ] !== str2 [ j ] ) { if ( str1 [ i ] === str2 [ j ] && str2 [ i ] === str1 [ j ] ) { cntOp += 1 ; } else { cntOp += 2 ; } } i += 1 ; j -= 1 ; } return cntOp ; } var str1 = " " ; var str2 = " " ; var N = str1 . length ; document . write ( MincntBothPalin ( str1 , str2 , N ) ) ;

Index/key variables: i, j
Accumulator variables: cntOp, i, j
Javascript program:
function power ( x , N ) { let res = 1 ; while ( N > 0 ) { if ( ( N & 1 ) != 0 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } function findValX_Y ( N ) { if ( N <= 1 ) { document . write ( - 1 ) ; return ; } let xMax ; xMax = Math . log ( N ) ; let yMax ; yMax = Math . log ( N ) / Math . log ( 5.0 ) ; for ( let i = 1 ; i <= xMax ; i ++ ) { for ( let j = 1 ; j <= yMax ; j ++ ) { let a = power ( 2 , i ) ; let b = power ( 5 , j ) ; if ( a + b == N ) { document . write ( i + " " + j ) ; return ; } } } document . write ( " " ) ; } let N = 129 ; findValX_Y ( N ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countPairs ( v1 , v2 , n , m , k ) { let count = 0 ; if ( n <= m ) { v1 . sort ( ) ; for ( let j = 0 ; j < m ; j ++ ) { let index = lowerBound ( v1 , 0 , n , v2 [ j ] - k ) ; count += index ; } } else { v2 . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let index = upperBound ( v2 , 0 , m , v1 [ i ] + k ) ; count += m - index ; } } return count ; } function lowerBound ( a , low , high , element ) { while ( low < high ) { let middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function upperBound ( a , low , high , element ) { while ( low < high ) { let middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } let arr = [ 5 , 9 , 1 , 8 ] ; let brr = [ 10 , 12 , 7 , 4 , 2 , 3 ] ; let K = 3 ; let N = arr . length ; let M = brr . length ; document . write ( countPairs ( arr , brr , N , M , K ) ) ;

Index/key variables: i, j, middle
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function maxSumSubarr ( A , N , K , X ) { let sum_K = 0 ; for ( let i = 0 ; i < K ; i ++ ) { sum_K += A [ i ] ; } let Max_Sum = 0 ; if ( sum_K < X ) { Max_Sum = sum_K ; } for ( let i = K ; i < N ; i ++ ) { sum_K -= ( A [ i - K ] - A [ i ] ) ; if ( sum_K < X ) { Max_Sum = Math . max ( Max_Sum , sum_K ) ; } } document . write ( Max_Sum ) ; } let arr = [ - 5 , 8 , 7 , 2 , 10 , 1 , 20 , - 4 , 6 , 9 ] ; let K = 5 ; let X = 30 ; let N = arr . length ; maxSumSubarr ( arr , N , K , X ) ;

Index/key variables: i
Accumulator variables: i, sum_K
Iterator variables: i
Javascript program:
function rearrangeArray ( a , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; } if ( sum == 0 ) { document . write ( " " ) ; return ; } sum = 0 ; let b = 0 ; a . sort ( ) ; for ( let i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( sum == 0 ) { if ( a [ i ] != a [ N - 1 ] ) { sum -= a [ i ] ; let temp = a [ i ] ; a [ i ] = a [ N - 1 ] ; a [ N - 1 ] = temp ; sum += a [ i ] ; } else { b = 1 ; break ; } } } if ( b == 1 ) { b = 0 ; sum = 0 ; a . sort ( ) ; for ( let i = N - 1 ; i >= 0 ; i -- ) { sum += a [ i ] ; if ( sum == 0 ) { if ( a [ i ] != a [ 0 ] ) { sum -= a [ i ] ; let temp = a [ i ] ; a [ i ] = a [ 0 ] ; a [ 0 ] = temp ; sum += a [ i ] ; } else { b = 1 ; break ; } } } } if ( b == 1 ) { document . write ( " " + " " ) ; return ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let arr = [ 1 , - 1 , 2 , 4 , 0 ] ; let N = arr . length ; rearrangeArray ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function removeSmallestSubarray ( arr , n , k ) { let mod_arr = new Array ( n ) ; let total_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { mod_arr [ i ] = ( arr [ i ] + k ) % k ; total_sum += arr [ i ] ; } let target_remainder = total_sum % k ; if ( target_remainder == 0 ) { document . write ( " " ) ; return ; } let map1 = new Map ( ) ; map1 . set ( 0 , - 1 ) ; let curr_remainder = 0 ; let res = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { curr_remainder = ( curr_remainder + arr [ i ] + k ) % k ; map1 . set ( curr_remainder , i ) ; let mod = ( curr_remainder - target_remainder + k ) % k ; if ( map1 . has ( mod ) ) res = Math . min ( res , i - map1 . get ( mod ) ) ; } if ( res == Number . MAX_SAFE_INTEGER res == n ) { res = - 1 ; } document . write ( res ) ; } let arr = [ 3 , 1 , 4 , 2 ] ; let N = arr . length ; let K = 6 ; removeSmallestSubarray ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i, total_sum
Iterator variables: i
Javascript program:
function toggleQuery ( str , Q , M ) { let N = str . length ; let prefixCnt = new Array ( N + 1 ) ; for ( let i = 0 ; i < N + 1 ; i ++ ) { prefixCnt [ i ] = 0 ; } for ( let i = 0 ; i < M ; i ++ ) { prefixCnt [ Q [ i ] [ 0 ] ] += 1 ; prefixCnt [ Q [ i ] [ 1 ] + 1 ] -= 1 ; } for ( let i = 1 ; i <= N ; i ++ ) { prefixCnt [ i ] += prefixCnt [ i - 1 ] ; } for ( let i = 0 ; i < N ; i ++ ) { if ( prefixCnt [ i ] % 2 == 1 ) { str [ i ] = String . fromCharCode ( ' ' . charCodeAt ( 0 ) - str [ i ] . charCodeAt ( 0 ) + ' ' . charCodeAt ( 0 ) ) ; } } return ( str ) . join ( " " ) ; } let str = " " ; let Q = [ [ 0 , 1 ] , [ 2 , 5 ] , [ 2 , 3 ] , [ 1 , 4 ] , [ 0 , 5 ] ] ; let M = Q . length ; document . write ( toggleQuery ( str . split ( " " ) , Q , M ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isValid ( wood , N , len , K ) { var count = 0 ; for ( i = 0 ; i < N ; i ++ ) { count += parseInt ( wood [ i ] / len ) ; } return count >= K ; } function findMaxLen ( wood , N , K ) { var left = 1 ; var right = Math . max . apply ( Math , wood ) ; while ( left <= right ) { var mid = left + ( right - left ) / 2 ; if ( isValid ( wood , N , mid , K ) ) { left = mid + 1 ; } else { right = mid - 1 ; } } return right ; } var wood = [ 5 , 9 , 7 ] ; var N = wood . length ; var K = 4 ; document . write ( findMaxLen ( wood , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countSum ( a , n , sum ) { let i , j , k , l ; let count = 0 ; for ( i = 0 ; i < n - 3 ; i ++ ) { for ( j = i + 1 ; j < n - 2 ; j ++ ) { for ( k = j + 1 ; k < n - 1 ; k ++ ) { for ( l = k + 1 ; l < n ; l ++ ) { if ( a [ i ] + a [ j ] + a [ k ] + a [ l ] == sum ) count ++ ; } } } } return count ; } let arr = [ 4 , 5 , 3 , 1 , 2 , 4 ] ; let S = 13 ; let N = arr . length ; document . write ( countSum ( arr , N , S ) ) ;

Index/key variables: i, j, k, l
Accumulator variables: count, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function minSwaps ( S , n ) { let swaps = 0 ; let arr = new Array ( 26 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) arr [ i ] = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { let pos = S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; arr [ pos ] . push ( i ) ; } for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ++ ch ) { let pos = ch - ' ' . charCodeAt ( 0 ) ; for ( let i = 1 ; i < arr [ pos ] . length ; ++ i ) { swaps += Math . abs ( arr [ pos ] [ i ] - arr [ pos ] [ i - 1 ] - 1 ) ; } } return swaps ; } let S = " " ; let N = S . length ; document . write ( minSwaps ( S , N ) ) ;

Index/key variables: i, pos
Accumulator variables: i, swaps
Iterator variables: ch, i
Javascript program:
function printConnections ( store , ind , ind1 ) { for ( let pr = 0 ; pr < store . length ; pr ++ ) { document . write ( store [ pr ] [ 0 ] + " " + store [ pr ] [ 1 ] + " " ) ; } if ( ind . length != 0 ) { for ( let x = 0 ; x < ind . length ; x ++ ) { document . write ( ind1 + " " + ( ind [ x ] + 1 ) + " " ) ; } } } function constructGraph ( arr , N ) { let ind = [ ] ; let store = [ ] ; let x = arr [ 0 ] ; let count = 0 ; let ind1 = - 1 ; for ( let i = 1 ; i <= N - 1 ; ++ i ) { if ( arr [ i ] != x ) { ind1 = i + 1 ; count ++ ; store . push ( [ 1 , i + 1 ] ) ; } else { ind . push ( i ) ; } } if ( count == 0 ) { document . write ( " " ) ; } else { document . write ( " " + " " ) ; printConnections ( store , ind , ind1 ) ; } } let N = 5 ; let arr = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; constructGraph ( arr , N ) ;

Index/key variables: i, pr, x
Accumulator variables: count, pr, x
Iterator variables: i, pr, x