dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; this . prev = null ; } } function getNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; return newNode ; } function insertEnd ( head , new_node ) { if ( head == null ) { new_node . next = new_node . prev = new_node ; head = new_node ; return head ; } var last = head . prev ; new_node . next = head ; head . prev = new_node ; new_node . prev = last ; last . next = new_node ; return head ; } function reverse ( head ) { if ( head == null ) return null ; var new_head = null ; var last = head . prev ; var curr = last , prev ; while ( curr . prev != last ) { prev = curr . prev ; new_head = insertEnd ( new_head , curr ) ; curr = prev ; } new_head = insertEnd ( new_head , curr ) ; return new_head ; } function display ( head ) { if ( head == null ) return ; var temp = head ; document . write ( " " ) ; while ( temp . next != head ) { document . write ( temp . data + " " ) ; temp = temp . next ; } document . write ( temp . data + " " ) ; var last = head . prev ; temp = last ; document . write ( " " ) ; while ( temp . prev != last ) { document . write ( temp . data + " " ) ; temp = temp . prev ; } document . write ( temp . data + " " ) ; } var head = null ; head = insertEnd ( head , getNode ( 1 ) ) ; head = insertEnd ( head , getNode ( 2 ) ) ; head = insertEnd ( head , getNode ( 3 ) ) ; head = insertEnd ( head , getNode ( 4 ) ) ; head = insertEnd ( head , getNode ( 5 ) ) ; document . write ( " " ) ; display ( head ) ; head = reverse ( head ) ; document . write ( " " ) ; display ( head ) ;

Class/struct names: Node
Javascript program:
var MAXN = 1001 ; var depth = Array ( MAXN ) ; var parent = Array ( MAXN ) ; var adj = Array . from ( Array ( MAXN ) , ( ) => Array ( ) ) ; function addEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function dfs ( cur , prev ) { parent [ cur ] = prev ; depth [ cur ] = depth [ prev ] + 1 ; for ( var i = 0 ; i < adj [ cur ] . length ; i ++ ) if ( adj [ cur ] [ i ] != prev ) dfs ( adj [ cur ] [ i ] , cur ) ; } function preprocess ( ) { depth [ 0 ] = - 1 ; dfs ( 1 , 0 ) ; } function LCANaive ( u , v ) { if ( u == v ) return u ; if ( depth [ u ] > depth [ v ] ) { var temp = u ; u = v ; v = temp ; } v = parent [ v ] ; return LCANaive ( u , v ) ; } for ( var i = 0 ; i < MAXN ; i ++ ) adj [ i ] = [ ] ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 1 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 4 , 8 ) ; addEdge ( 4 , 9 ) ; addEdge ( 9 , 10 ) ; addEdge ( 9 , 11 ) ; addEdge ( 7 , 12 ) ; addEdge ( 7 , 13 ) ; preprocess ( ) ; document . write ( " " + LCANaive ( 11 , 8 ) + " " ) ; document . write ( " " + LCANaive ( 3 , 13 ) ) ;

Index/key variables: cur, i, prev, u, v
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAXN = 1001 ; let block_sz ; let depth = new Array ( MAXN ) ; let parent = new Array ( MAXN ) ; let jump_parent = new Array ( MAXN ) ; let adj = new Array ( MAXN ) ; function addEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function LCANaive ( u , v ) { if ( u == v ) return u ; if ( depth [ u ] > depth [ v ] ) { let t = u ; u = v ; v = t ; } v = parent [ v ] ; return LCANaive ( u , v ) ; } function dfs ( cur , prev ) { depth [ cur ] = depth [ prev ] + 1 ; parent [ cur ] = prev ; if ( depth [ cur ] % block_sz == 0 ) jump_parent [ cur ] = parent [ cur ] ; else jump_parent [ cur ] = jump_parent [ prev ] ; for ( let i = 0 ; i < adj [ cur ] . length ; ++ i ) if ( adj [ cur ] [ i ] != prev ) dfs ( adj [ cur ] [ i ] , cur ) ; } function LCASQRT ( u , v ) { while ( jump_parent [ u ] != jump_parent [ v ] ) { if ( depth [ u ] > depth [ v ] ) { let t = u ; u = v ; v = t ; } v = jump_parent [ v ] ; } return LCANaive ( u , v ) ; } function preprocess ( height ) { block_sz = parseInt ( Math . sqrt ( height ) , 10 ) ; depth [ 0 ] = - 1 ; dfs ( 1 , 0 ) ; } for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 1 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 4 , 8 ) ; addEdge ( 4 , 9 ) ; addEdge ( 9 , 10 ) ; addEdge ( 9 , 11 ) ; addEdge ( 7 , 12 ) ; addEdge ( 7 , 13 ) ; let height = 4 ; preprocess ( height ) ; document . write ( " " + LCASQRT ( 11 , 8 ) + " " ) ; document . write ( " " + LCASQRT ( 3 , 13 ) + " " ) ;

Index/key variables: cur, i, prev, u, v
Accumulator variables: i
Iterator variables: i
Javascript program:
function countOfNum ( n , a , b ) { let cnt_of_a , cnt_of_b , cnt_of_ab , sum ; cnt_of_a = Math . floor ( n / a ) ; cnt_of_b = Math . floor ( n / b ) ; sum = cnt_of_b + cnt_of_a ; cnt_of_ab = Math . floor ( n / ( a * b ) ) ; sum = sum - cnt_of_ab ; return sum ; } function sumOfNum ( n , a , b ) { let i ; let sum = 0 ; let ans = new Set ( ) ; for ( i = a ; i <= n ; i = i + a ) { ans . add ( i ) ; } for ( i = b ; i <= n ; i = i + b ) { ans . add ( i ) ; } for ( let it of ans . values ( ) ) { sum = sum + it ; } return sum ; } let N = 88 ; let A = 11 ; let B = 8 ; let count = countOfNum ( N , A , B ) ; let sumofnum = sumOfNum ( N , A , B ) ; document . write ( sumofnum % count ) ;

Iterator variables: i, it
Javascript program:
const MAX = 100000 ; let v = [ ] ; function upper_bound ( ar , k ) { let s = 0 ; let e = ar . length ; while ( s != e ) { let mid = s + e >> 1 ; if ( ar [ mid ] <= k ) { s = mid + 1 ; } else { e = mid ; } } if ( s == ar . length ) { return - 1 ; } return s ; } function consecutiveOnes ( x ) { let p = 0 ; while ( x > 0 ) { if ( x % 2 == 1 && p == 1 ) return true ; p = x % 2 ; x = parseInt ( x / 2 ) ; } return false ; } function preCompute ( ) { for ( let i = 0 ; i <= MAX ; i ++ ) { if ( ! consecutiveOnes ( i ) ) v . push ( i ) ; } } function nextValid ( n ) { let it = upper_bound ( v , n ) ; let val = v [ it ] ; return val ; } function performQueries ( queries , q ) { for ( let i = 0 ; i < q ; i ++ ) document . write ( nextValid ( queries [ i ] ) + " " ) ; } let queries = [ 4 , 6 ] ; let q = queries . length ; preCompute ( ) ; performQueries ( queries , q ) ;

Index/key variables: i, it, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function changeToOnes ( str ) { var i , l , ctr = 0 ; l = str . length ; for ( i = l - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) ctr ++ ; else break ; } return l - ctr ; } function removeZeroesFromFront ( str ) { var s ; var i = 0 ; while ( i < str . length && str [ i ] == ' ' ) i ++ ; if ( i == str . length ) s = " " ; else s = str . substring ( i , str . length - i ) ; return s ; } var str = " " ; str = removeZeroesFromFront ( str ) ; document . write ( changeToOnes ( str ) ) ;

Index/key variables: i
Accumulator variables: ctr, i
Iterator variables: i
Javascript program:
function MinDeletion ( a , n ) { let map = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( map [ a [ i ] ] ) map [ a [ i ] ] ++ ; else map [ a [ i ] ] = 1 } let ans = 0 ; for ( var m in map ) { let x = m ; let frequency = map [ m ] ; if ( x <= frequency ) { ans += ( frequency - x ) ; } else ans += frequency ; } ; return ans ; } let a = [ 2 , 3 , 2 , 3 , 4 , 4 , 4 , 4 , 5 ] ; let n = a . length ; document . write ( MinDeletion ( a , n ) ) ;

Index/key variables: i, m
Accumulator variables: ans, i
Iterator variables: i, m
Javascript program:
function maxCountAB ( s , n ) { var A = 0 , B = 0 , BA = 0 , ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var S = s [ i ] ; var L = S . length ; for ( var j = 0 ; j < L - 1 ; j ++ ) { if ( S [ j ] == ' ' && S [ j + 1 ] == ' ' ) { ans ++ ; } } if ( S [ 0 ] == ' ' && S [ L - 1 ] == ' ' ) BA ++ ; else if ( S [ 0 ] == ' ' ) B ++ ; else if ( S [ L - 1 ] == ' ' ) A ++ ; } if ( BA == 0 ) ans += Math . min ( B , A ) ; else if ( A + B == 0 ) ans += BA - 1 ; else ans += BA + Math . min ( B , A ) ; return ans ; } var s = [ " " , " " , " " ] ; var n = s . length ; document . write ( maxCountAB ( s , n ) ) ;

Index/key variables: i, j
Accumulator variables: A, B, BA, ans, i, j
Iterator variables: i, j
Javascript program:
function MinOperations ( n , x , arr ) { let total = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( arr [ i ] > x ) { let difference = arr [ i ] - x ; total = total + difference ; arr [ i ] = x ; } } for ( let i = 1 ; i < n ; ++ i ) { let LeftNeigbouringSum = arr [ i ] + arr [ i - 1 ] ; if ( LeftNeigbouringSum > x ) { let current_diff = LeftNeigbouringSum - x ; arr [ i ] = Math . max ( 0 , arr [ i ] - current_diff ) ; total = total + current_diff ; } } return total ; } let X = 1 ; let arr = [ 1 , 6 , 1 , 2 , 0 , 4 ] ; let N = arr . length ; document . write ( MinOperations ( N , X , arr ) + " " ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function findNumbers ( arr , n ) { sumN = ( n * ( n + 1 ) ) / 2 ; sumSqN = ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; let sum = 0 ; let sumSq = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; sumSq += Math . pow ( arr [ i ] , 2 ) ; } B = ( ( ( sumSq - sumSqN ) / ( sum - sumN ) ) + sumN - sum ) / 2 ; A = sum - sumN + B ; document . write ( " " + A , " " , B ) ; } let arr = [ 1 , 2 , 2 , 3 , 4 ] ; n = arr . length ; findNumbers ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, sum, sumSq
Iterator variables: i
Javascript program:
function is_prefix ( temp , str ) { if ( temp . length < str . length ) return 0 ; else { for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] != temp [ i ] ) return 0 ; } return 1 ; } } function lexicographicallyString ( input , n , str ) { input = Array . from ( input ) . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let temp = input [ i ] ; if ( is_prefix ( temp , str ) ) { return temp ; } } return " " ; } let arr = [ " " , " " , " " , " " , " " ] ; let S = " " ; let N = 5 ; document . write ( lexicographicallyString ( arr , N , S ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function Rearrange ( arr , K , N ) { let ans = new Array ( N + 1 ) ; let f = - 1 ; for ( let i = 0 ; i < N ; i ++ ) { ans [ i ] = - 1 ; } for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == K ) { K = i ; break ; } } let smaller = [ ] ; let greater = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < arr [ K ] ) smaller . push ( arr [ i ] ) ; else if ( arr [ i ] > arr [ K ] ) greater . push ( arr [ i ] ) ; } let low = 0 , high = N - 1 ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( mid == K ) { ans [ mid ] = arr [ K ] ; f = 1 ; break ; } else if ( mid < K ) { if ( smaller . length == 0 ) { break ; } ans [ mid ] = smaller [ smaller . length - 1 ] ; smaller . pop ( ) ; low = mid + 1 ; } else { if ( greater . length == 0 ) { break ; } ans [ mid ] = greater [ greater . length - 1 ] ; greater . pop ( ) ; high = mid - 1 ; } } if ( f == - 1 ) { document . write ( - 1 ) ; return ; } for ( let i = 0 ; i < N ; i ++ ) { if ( ans [ i ] == - 1 ) { if ( smaller . length != 0 ) { ans [ i ] = smaller [ smaller . length - 1 ] ; smaller . pop ( ) ; } else if ( greater . length != 0 ) { ans [ i ] = greater [ greater . length - 1 ] ; greater . pop ; } } } for ( let i = 0 ; i < N ; i ++ ) document . write ( ans [ i ] + " " ) ; document . write ( " " ) } let arr = [ 10 , 7 , 2 , 5 , 3 , 8 ] ; let K = 7 ; let N = arr . length ; Rearrange ( arr , K , N ) ;

Index/key variables: K, i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumK ( arr , M , N ) { let good = Math . floor ( ( N * 1.0 ) / ( ( M + 1 ) * 1.0 ) ) + 1 ; for ( let i = 1 ; i <= N ; i ++ ) { let K = i ; let candies = N ; let taken = 0 ; while ( candies > 0 ) { taken += Math . min ( K , candies ) ; candies -= Math . min ( K , candies ) ; for ( let j = 0 ; j < M ; j ++ ) { let consume = ( arr [ j ] * candies ) / 100 ; candies -= consume ; } } if ( taken >= good ) { document . write ( i ) ; return ; } } } let N = 13 , M = 1 ; let arr = new Array ( ) ; arr . push ( 50 ) ; minimumK ( arr , M , N ) ;

Index/key variables: j
Accumulator variables: candies, i, j, taken
Iterator variables: i, j
Javascript program:
function calcTotalTime ( path ) { var time = 0 ; var x = 0 , y = 0 ; var s = new Set ( ) ; for ( var i = 0 ; i < path . length ; i ++ ) { var p = x ; var q = y ; if ( path [ i ] == ' ' ) y ++ ; else if ( path [ i ] == ' ' ) y -- ; else if ( path [ i ] == ' ' ) x ++ ; else if ( path [ i ] == ' ' ) x -- ; if ( ! s . has ( [ p + x , q + y ] . toString ( ) ) ) { time += 2 ; s . add ( [ p + x , q + y ] . toString ( ) ) ; } else time += 1 ; } document . write ( time ) } var path = " " ; calcTotalTime ( path ) ;

Index/key variables: i
Accumulator variables: i, time, x, y
Iterator variables: i
Javascript program:
function findCost ( A , N ) { var totalCost = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 0 ) { A [ i ] = 1 ; totalCost += i ; } } return totalCost ; } var arr = [ 1 , 0 , 1 , 0 , 1 , 0 ] var N = arr . length document . write ( findCost ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, totalCost
Iterator variables: i
Javascript program:
function peakIndex ( arr ) { var N = arr . length ; if ( arr . length < 3 ) return - 1 ; var i = 0 ; while ( i + 1 < N ) { if ( arr [ i + 1 ] < arr [ i ] arr [ i ] == arr [ i + 1 ] ) break ; i ++ ; } if ( i == 0 i == N - 1 ) return - 1 ; var ans = i ; while ( i < N - 1 ) { if ( arr [ i ] < arr [ i + 1 ] arr [ i ] == arr [ i + 1 ] ) break ; i ++ ; } if ( i == N - 1 ) return ans ; return - 1 ; } var arr = [ 0 , 1 , 0 ] ; document . write ( peakIndex ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function hasArrayTwoPairs ( nums , n , target ) { nums . sort ( ) ; var i ; for ( i = 0 ; i < n ; i ++ ) { var x = target - nums [ i ] ; var low = 0 , high = n - 1 ; while ( low <= high ) { var mid = low + ( Math . floor ( ( high - low ) / 2 ) ) ; if ( nums [ mid ] > x ) { high = mid - 1 ; } else if ( nums [ mid ] < x ) { low = mid + 1 ; } else { if ( mid == i ) { if ( ( mid - 1 >= 0 ) && nums [ mid - 1 ] == x ) { document . write ( nums [ i ] + " " ) ; document . write ( nums [ mid - 1 ] ) ; return ; } if ( ( mid + 1 < n ) && nums [ mid + 1 ] == x ) { document . write ( nums [ i ] + " " ) ; document . write ( nums [ mid + 1 ] ) ; return ; } break ; } else { document . write ( nums [ i ] + " " ) ; document . write ( nums [ mid ] ) ; return ; } } } } document . write ( - 1 ) ; } var A = [ 0 , - 1 , 2 , - 3 , 1 ] ; var X = - 2 ; var N = A . length ; hasArrayTwoPairs ( A , N , X ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function findClosest ( N , target ) { let closest = - 1 ; let diff = Number . MAX_VALUE ; for ( let i = 1 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( N / i == i ) { if ( Math . abs ( target - i ) < diff ) { diff = Math . abs ( target - i ) ; closest = i ; } } else { if ( Math . abs ( target - i ) < diff ) { diff = Math . abs ( target - i ) ; closest = i ; } if ( Math . abs ( target - N / i ) < diff ) { diff = Math . abs ( target - N / i ) ; closest = N / i ; } } } } document . write ( closest ) ; } let N = 16 , X = 5 ; findClosest ( N , X ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function power ( A , N ) { let count = 0 ; if ( A == 1 ) return 0 ; while ( N > 0 ) { count ++ ; N /= A ; } return count ; } function Pairs ( N , A , B ) { let powerA , powerB ; powerA = power ( A , N ) ; powerB = power ( B , N ) ; let letialB = B , letialA = A ; A = 1 ; for ( let i = 0 ; i <= powerA ; i ++ ) { B = 1 ; for ( let j = 0 ; j <= powerB ; j ++ ) { if ( B == N - A ) { document . write ( i + " " + j ) ; return ; } B *= letialB ; } A *= letialA ; } document . write ( " " ) ; return ; } let N = 106 , A = 3 , B = 5 ; Pairs ( N , A , B ) ;

Accumulator variables: A, B, N, count, i, j
Iterator variables: i, j
Javascript program:
function findNonMultiples ( arr , n , k ) { let multiples = new Set ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( ! multiples . has ( arr [ i ] ) ) { for ( let j = 1 ; j <= k / arr [ i ] ; j ++ ) { multiples . add ( arr [ i ] * j ) ; } } } return k - multiples . size ; } function countValues ( arr , N , L , R ) { return findNonMultiples ( arr , N , R ) - findNonMultiples ( arr , N , L - 1 ) ; } let arr = [ 2 , 3 , 4 , 5 , 6 ] ; let N = arr . length ; let L = 1 , R = 20 ; document . write ( countValues ( arr , N , L , R ) ) ;

Index/key variables: i
Accumulator variables: j
Iterator variables: i, j
Javascript program:
function minCollectingSpeed ( piles , H ) { var ans = - 1 ; var low = 1 , high ; high = piles . reduce ( ( a , b ) => Math . max ( a , b ) ) ; while ( low <= high ) { var K = low + parseInt ( ( high - low ) / 2 ) ; var time = 0 ; piles . forEach ( ai => { time += parseInt ( ( ai + K - 1 ) / K ) ; } ) ; if ( time <= H ) { ans = K ; high = K - 1 ; } else { low = K + 1 ; } } document . write ( ans ) ; } var arr = [ 3 , 6 , 7 , 11 ] ; var H = 8 ; minCollectingSpeed ( arr , H ) ;

Accumulator variables: time
Javascript program:
function cntDisPairs ( arr , N , K ) { var cntPairs = 0 ; arr . sort ( ) ; var i = 0 ; var j = N - 1 ; while ( i < j ) { if ( arr [ i ] + arr [ j ] == K ) { while ( i < j && arr [ i ] == arr [ i + 1 ] ) { i ++ ; } while ( i < j && arr [ j ] == arr [ j - 1 ] ) { j -- ; } cntPairs += 1 ; i ++ ; j -- ; } else if ( arr [ i ] + arr [ j ] < K ) { i ++ ; } else { j -- ; } } return cntPairs ; } var arr = [ 5 , 6 , 5 , 7 , 7 , 8 ] ; var N = arr . length ; var K = 13 ; document . write ( cntDisPairs ( arr , N , K ) ) ;

Index/key variables: i, j
Accumulator variables: cntPairs, i, j
Javascript program:
function longestSubsequence ( N , Q , arr , Queries ) { for ( let i = 0 ; i < Q ; i ++ ) { let x = Queries [ i ] [ 0 ] ; let y = Queries [ i ] [ 1 ] ; arr [ x - 1 ] = y ; let count = 1 ; for ( let j = 1 ; j < N ; j ++ ) { if ( arr [ j ] != arr [ j - 1 ] ) { count += 1 ; } } document . write ( count + " " ) ; } } let arr = [ 1 , 1 , 2 , 5 , 2 ] ; let N = arr . length ; let Q = 2 ; let Queries = [ [ 1 , 3 ] , [ 4 , 2 ] ] ; longestSubsequence ( N , Q , arr , Queries ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function longestSubsequence ( N , Q , arr , Queries ) { var count = 1 ; for ( var i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != arr [ i - 1 ] ) { count += 1 ; } } for ( var i = 0 ; i < Q ; i ++ ) { var x = Queries [ i ] [ 0 ] ; var y = Queries [ i ] [ 1 ] ; if ( x > 1 ) { if ( arr [ x - 1 ] != arr [ x - 2 ] ) { count -= 1 ; } if ( arr [ x - 2 ] != y ) { count += 1 ; } } if ( x < N ) { if ( arr [ x ] != arr [ x - 1 ] ) { count -= 1 ; } if ( y != arr [ x ] ) { count += 1 ; } } document . write ( count + " " ) ; arr [ x - 1 ] = y ; } } var arr = [ 1 , 1 , 2 , 5 , 2 ] ; var N = arr . length ; var Q = 2 ; var Queries = [ [ 1 , 3 ] , [ 4 , 2 ] ] ; longestSubsequence ( N , Q , arr , Queries ) ;

Index/key variables: i, x
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function sum ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { var tmp = mp . get ( arr [ i ] ) ; tmp . push ( i ) ; mp . set ( arr [ i ] , tmp ) ; } else { mp . set ( arr [ i ] , [ i ] ) ; } } var ans = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { var sum = 0 ; mp . get ( arr [ i ] ) . forEach ( it => { sum += Math . abs ( it - i ) ; } ) ; ans [ i ] = sum ; } for ( var i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } return ; } var arr = [ 1 , 3 , 1 , 1 , 2 ] ; var n = arr . length ; sum ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function conVowUpp ( str ) { var N = str . length ; for ( var i = 0 ; i < N ; i ++ ) { if ( str [ i ] === " " str [ i ] === " " str [ i ] === " " str [ i ] === " " str [ i ] === " " ) { document . write ( str [ i ] . toUpperCase ( ) ) ; } else { document . write ( str [ i ] ) ; } } } var str = " " ; conVowUpp ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var mp = new Map ( ) ; var N , P ; function helper ( mid ) { var cnt = 0 ; mp . forEach ( ( value , ) => { var temp = value ; while ( temp >= mid ) { temp -= mid ; cnt ++ ; } } ) ; return cnt >= N ; } function findMaximumDays ( arr ) { for ( var i = 0 ; i < P ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) ; } var start = 0 , end = P , ans = 0 ; while ( start <= end ) { var mid = start + parseInt ( ( end - start ) / 2 ) ; if ( mid != 0 && helper ( mid ) ) { ans = mid ; start = mid + 1 ; } else if ( mid == 0 ) { start = mid + 1 ; } else { end = mid - 1 ; } } return ans ; } N = 3 , P = 10 ; var arr = [ 1 , 2 , 2 , 1 , 1 , 3 , 3 , 3 , 2 , 4 ] ; document . write ( findMaximumDays ( arr ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, temp
Iterator variables: i
Javascript program:
function countSubarrays ( a , n , k ) { var ans = 0 ; var pref = [ ] ; pref . push ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) pref . push ( ( a [ i ] + pref [ i ] ) % k ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = i ; j <= n ; j ++ ) { if ( ( pref [ j ] - pref [ i - 1 ] + k ) % k == j - i + 1 ) { ans ++ ; } } } document . write ( ans + ' ' ) ; } var arr = [ 2 , 3 , 5 , 3 , 1 , 5 ] ; var N = arr . length ; var K = 4 ; countSubarrays ( arr , N , K ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function check ( s , k ) { let n = s . length ; for ( let i = 0 ; i < k ; i ++ ) { for ( let j = i ; j < n ; j += k ) { if ( s [ i ] != s [ j ] ) return false ; } } let c = 0 ; for ( let i = 0 ; i < k ; i ++ ) { if ( s [ i ] == ' ' ) c ++ ; else c -- ; } if ( c == 0 ) return true ; else return false ; } let s = " " ; let k = 2 ; if ( check ( s , k ) ) document . write ( " " + " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function isSame ( str , n ) { var mp = { } ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( mp . hasOwnProperty ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) { mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] + 1 ; } else { mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = 1 ; } } for ( const [ key , value ] of Object . entries ( mp ) ) { if ( value >= n ) { return true ; } } return false ; } var str = " " ; var n = 4 ; if ( isSame ( str , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function possible ( mid , a ) { let n = a . length ; let total = parseInt ( ( n * ( n - 1 ) ) / 2 ) ; let need = parseInt ( ( total + 1 ) / 2 ) ; let count = 0 ; let start = 0 , end = 1 ; while ( end < n ) { if ( a [ end ] - a [ start ] <= mid ) { end ++ ; } else { count += ( end - start - 1 ) ; start ++ ; } } if ( end == n && start < end && a [ end - 1 ] - a [ start ] <= mid ) { let t = end - start - 1 ; count += parseInt ( t * ( t + 1 ) / 2 ) ; } if ( count >= need ) return true ; else return false ; } function findMedian ( a ) { let n = a . length ; let low = 0 , high = a [ n - 1 ] - a [ 0 ] ; while ( low <= high ) { let mid = ( low + high ) / 2 ; if ( possible ( mid , a ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } let a = [ 1 , 7 , 5 , 2 ] ; a . sort ( ) ; document . write ( findMedian ( a ) ) ;

Index/key variables: end, start
Accumulator variables: count, end, start