dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function convertToBase9 ( n ) { let ans = 0 ; let a = 1 ; while ( n > 0 ) { ans += a * ( n % 9 ) ; a *= 10 ; n = Math . floor ( n / 9 ) ; } return ans ; } function getNthnumber ( base9 , K ) { let ans = 0 ; let a = 1 ; while ( base9 > 0 ) { let cur = base9 % 10 ; if ( cur >= K ) { ans += a * ( cur + 1 ) ; } else { ans += a * cur ; } base9 = Math . floor ( base9 / 10 ) ; a *= 10 ; } return ans ; } let N = 10 , K = 1 ; let base9 = convertToBase9 ( N ) ; document . write ( getNthnumber ( base9 , K ) ) ;

Accumulator variables: a, ans
Javascript program:
const binarySearch = ( arr , size , key ) => { let low = 0 , high = size - 1 , mid ; while ( low <= high ) { mid = low + parseInt ( ( high - low ) / 2 ) ; if ( key > arr [ mid ] ) low = mid + 1 ; else if ( key < arr [ mid ] ) high = mid - 1 ; else return 1 ; } return 0 ; } const twoPointers = ( arr , N , mean ) => { let i = 0 , j = N - 1 ; while ( i < j ) { let temp = ( arr [ i ] + arr [ j ] ) / 2 ; if ( temp > mean ) j -- ; else if ( temp < mean ) i ++ ; else return 1 ; } return 0 ; } const checkArray = ( arr , N ) => { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; let mean = sum / N ; if ( N & 1 ) return binarySearch ( arr , N , mean ) ; else return twoPointers ( arr , N , mean ) ; } let arr = [ 1.0 , 3.0 , 6.0 , 9.0 , 12.0 , 32.0 ] ; let N = arr . length ; if ( checkArray ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, mid
Accumulator variables: i, j, sum
Iterator variables: i
Javascript program:
function UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) { let S = new Set ( ) ; let p1 = a1 ; for ( let i = 0 ; i < N ; i ++ ) { S . add ( p1 ) ; p1 = ( p1 * r1 ) ; } let p2 = a2 ; for ( let i = 0 ; i < N ; i ++ ) { S . add ( p2 ) ; p2 = ( p2 * r2 ) ; } return S . size ; } let N = 5 ; let a1 = 3 , r1 = 2 , a2 = 2 , r2 = 3 ; document . write ( UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( arr , N , K ) { let vp = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { vp . push ( { " " : arr [ i ] , " " : i } ) ; } vp . sort ( function ( a , b ) { return a . first - b . first ; } ) ; let minCnt = 0 ; while ( vp . length > 0 ) { let val , ind ; val = vp [ vp . length - 1 ] . first ; ind = vp [ vp . length - 1 ] . second ; minCnt ++ ; while ( vp . length > 0 && ( vp [ vp . length - 1 ] . first == val ) && ( ind - vp [ vp . length - 1 ] . second + 1 <= K ) ) { vp . pop ( ) ; } } return minCnt ; } let arr = [ 18 , 11 , 18 , 11 , 18 ] ; let K = 3 ; let N = arr . length ; document . write ( minOperations ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, minCnt
Iterator variables: i
Javascript program:
function nearestLeft ( arr , N , steps ) { let L = - N ; for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { L = - ( N - i ) ; break ; } } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { L = i ; } steps [ i ] = i - L ; } } function nearestRight ( arr , N , steps ) { let R = 2 * N ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { R = N + i ; break ; } } for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { R = i ; } steps [ i ] = Math . min ( steps [ i ] , R - i ) ; } } function findSum ( arr , N , M , K ) { let steps = new Array ( N ) ; let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum = sum + arr [ i ] ; } if ( sum == 0 ) { return 0 ; } nearestLeft ( arr , N , steps ) ; nearestRight ( arr , N , steps ) ; for ( let i = 0 ; i < N ; i ++ ) sum += 2 * K * Math . max ( 0 , M - steps [ i ] ) ; return sum ; } let arr = [ 0 , 1 , 0 , 1 , 0 , 0 ] ; let N = arr . length ; let M = 2 ; let K = 1 ; document . write ( findSum ( arr , N , M , K ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function getProduct ( n ) { let product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = Math . floor ( n / 10 ) ; } return product ; } function countPairs ( L , R ) { let cntPair = 0 ; for ( let a = L ; a <= R ; a ++ ) { for ( let b = a + 1 ; b <= R ; b ++ ) { let x = getProduct ( a ) ; let y = getProduct ( b ) ; if ( x && y && ( a * y ) == ( b * x ) ) { cntPair ++ ; } } } return cntPair ; } let L = 1 ; let R = 100 ; document . write ( countPairs ( 1 , 100 ) ) ;

Accumulator variables: a, b, cntPair
Iterator variables: a, b
Javascript program:
function maxSum ( matrix ) { let r = matrix . length ; let c = matrix [ 0 ] . length ; let sum = 0 ; let mini = Number . MAX_VALUE ; let count = 0 ; for ( let i = 0 ; i < r ; i ++ ) { for ( let j = 0 ; j < c ; j ++ ) { let k = matrix [ i ] [ j ] ; mini = Math . min ( mini , Math . abs ( k ) ) ; if ( k < 0 ) count ++ ; sum += Math . abs ( k ) ; } } if ( count % 2 == 0 ) { return sum ; } else { return ( sum - 2 * mini ) ; } } let matrix = [ [ 2 , - 2 ] , [ - 2 , 2 ] ] ; document . write ( maxSum ( matrix ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, sum
Iterator variables: i, j
Javascript program:
function lastPositiveElement ( arr ) { let N = arr . length ; if ( N == 1 ) return arr [ 0 ] ; let greatest = - 1 , secondGreatest = - 1 ; for ( let x of arr ) { if ( x >= greatest ) { secondGreatest = greatest ; greatest = x ; } else if ( x >= secondGreatest ) { secondGreatest = x ; } } return greatest - secondGreatest ; } let arr = [ 3 , 5 , 4 , 7 ] ; document . write ( lastPositiveElement ( arr ) ) ;

Iterator variables: x
Javascript program:
function updateArray ( arr , K ) { let sum = 0 ; let res = [ ] ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] < K ) { sum += arr [ i ] ; } else { if ( sum != 0 ) { res . push ( sum ) ; } sum = 0 ; res . push ( arr [ i ] ) ; } } if ( sum != 0 ) res . push ( sum ) ; for ( let it of res ) document . write ( it + ' ' ) ; } let arr = [ 200 , 6 , 36 , 612 , 121 , 66 , 63 , 39 , 668 , 108 ] ; let K = 100 ; updateArray ( arr , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i, it
Javascript program:
function highestPowerof2 ( n ) { let p = Math . floor ( Math . log2 ( n ) ) ; if ( p % 2 == 0 ) { p -= 1 } return Math . pow ( 2 , p ) } function minStep ( N , X ) { if ( N % 2 != 0 && X == 0 ) return - 1 let size = 0 while ( X < N ) { N -= highestPowerof2 ( N ) size += 1 } if ( N != 0 ) size += 1 return size ; } let N = 11 let X = 2 document . write ( minStep ( N , X ) )

Accumulator variables: N, p, size
Javascript program:
function findMaxK ( N ) { let K = N ; for ( let i = N - 1 ; i >= 0 ; i -- ) { K &= i ; if ( K == 0 ) { return i ; } } return 0 ; } let N = 5 ; document . write ( findMaxK ( N ) ) ;

Accumulator variables: K, i
Iterator variables: i
Javascript program:
function countPairs ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ j ] % arr [ i ] == 0 ) && ( j + 1 ) % ( i + 1 ) == 0 && ( arr [ j ] / arr [ i ] == ( j + 1 ) / ( i + 1 ) ) ) { count ++ ; } } } return count ; } let arr = [ 5 , - 2 , 4 , 20 , 25 , - 6 ] ; let n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function countMinDistance ( n , m , edges ) { let g = new Array ( 10005 ) . fill ( 0 ) . map ( ( ) => [ ] ) ; for ( let i = 0 ; i < m ; i ++ ) { let a = edges [ i ] [ 0 ] - 1 ; let b = edges [ i ] [ 1 ] - 1 ; g [ a ] . push ( b ) ; g [ b ] . push ( a ) ; } let queue1 = [ ] ; queue1 . push ( [ 0 , 0 ] ) ; let dist = new Array ( n ) . fill ( 1e9 ) ; let ways1 = new Array ( n ) . fill ( 0 ) ; dist [ 0 ] = 0 ; ways1 [ 0 ] = 1 ; while ( queue1 . length > 0 ) { let up = queue1 [ 0 ] ; queue1 . pop ( ) ; let x = up [ 0 ] ; let dis = up [ 1 ] ; if ( dis > dist [ x ] ) continue ; if ( x == n - 1 ) continue ; for ( let y of g [ x ] ) { if ( dist [ y ] > dis + 1 ) { dist [ y ] = dis + 1 ; ways1 [ y ] = ways1 [ x ] ; queue1 . push ( [ y , dis + 1 ] ) ; } else if ( dist [ y ] == dis + 1 ) ways1 [ y ] += ways1 [ x ] ; } } let queue2 = [ ] ; queue2 . push ( [ n - 1 , 0 ] ) ; let dist1 = new Array ( n ) . fill ( 1e9 ) ; let ways2 = new Array ( n ) . fill ( 0 ) ; dist1 [ n - 1 ] = 0 ; ways2 [ n - 1 ] = 1 ; while ( queue2 . length > 0 ) { let up = queue2 [ 0 ] ; queue2 . pop ( ) ; let x = up [ 0 ] ; let dis = up [ 1 ] ; if ( dis > dist1 [ x ] ) continue ; if ( x == 0 ) continue ; for ( let y of g [ x ] ) { if ( dist1 [ y ] > dis + 1 ) { dist1 [ y ] = dis + 1 ; ways2 [ y ] = ways2 [ x ] ; queue2 . push ( [ y , dis + 1 ] ) ; } else if ( dist1 [ y ] == 1 + dis ) ways2 [ y ] += ways2 [ x ] ; } } ways1 [ n - 1 ] = 1 ; ways2 [ n - 1 ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) document . write ( ways1 [ i ] * ways2 [ i ] + " " ) ; } let N = 5 ; let M = 5 ; let edges = [ [ 1 , 2 ] , [ 1 , 4 ] , [ 1 , 3 ] , [ 2 , 5 ] , [ 2 , 4 ] , ] ; countMinDistance ( N , M , edges ) ;

Index/key variables: a, b, i, x, y
Accumulator variables: i
Iterator variables: i, y
Javascript program:
function factorial ( n ) { let ans = 1 ; while ( n >= 1 ) { ans *= n ; n -- ; } return ans ; } function Binary_Num ( n , k ) { let num_even , num_odd ; if ( n - k - 1 >= 0 && k - 1 >= 0 ) { num_even = Math . floor ( factorial ( n - 2 ) / ( factorial ( k - 1 ) * factorial ( n - k - 1 ) ) ) ; } else { num_even = 0 ; } if ( k - 2 >= 0 ) { num_odd = Math . floor ( factorial ( n - 2 ) / ( factorial ( k - 2 ) * factorial ( n - k ) ) ) ; } else { num_odd = 0 ; } document . write ( num_even + " " + num_odd + " " ) ; } let N = 9 , K = 6 ; Binary_Num ( N , K ) ;

Accumulator variables: ans, n
Javascript program:
function findSumOfAllSubsets ( arr , n , k ) { let factorial_N = 1 , factorial_d = 1 , factorial_D = 1 ; for ( let i = 1 ; i <= n - 1 ; i ++ ) factorial_N *= i ; for ( let i = 1 ; i <= k - 1 ; i ++ ) factorial_d *= i ; for ( let i = 1 ; i <= n - k ; i ++ ) factorial_D *= i ; let freq = factorial_N / ( factorial_d * factorial_D ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum = sum * freq ; document . write ( " " + k + " " + sum + " " ) ; } let arr = [ 1 , 2 , 4 , 5 ] ; let n = 4 , k = 2 ; findSumOfAllSubsets ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: factorial_D, factorial_N, factorial_d, i, sum
Iterator variables: i
Javascript program:
function maximumTripletXOR ( A , B , C ) { let ans = 0 ; for ( let i = 30 ; i >= 0 ; i -- ) { let cur = 1 << i ; if ( A >= cur ) { ans += cur ; A -= cur ; } else if ( B >= cur ) { ans += cur ; B -= cur ; } else if ( C >= cur ) { ans += cur ; C -= cur ; } } return ans ; } let A = 6 ; let B = 2 ; let C = 10 ; document . write ( maximumTripletXOR ( A , B , C ) ) ;

Accumulator variables: A, B, C, ans, i
Iterator variables: i
Javascript program:
function intCount ( X , K ) { let ans = 0 ; for ( let z = 0 ; z < Math . pow ( 10 , K ) ; z += Math . floor ( ( Math . pow ( 10 , K ) - 1 ) / 9 ) ) { if ( z > X ) break ; ans += Math . floor ( ( ( X - z ) / Math . pow ( 10 , K ) + 1 ) ) ; } return ans ; } function intCountInRange ( L , R , K ) { return ( intCount ( R , K ) - intCount ( L - 1 , K ) ) ; } let L = 49 ; let R = 101 ; let K = 2 ; document . write ( intCountInRange ( L , R , K ) ) ;

Accumulator variables: ans, z
Iterator variables: z
Javascript program:
function countQuadruples ( A , N ) { let ans = 0 ; let freq = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { ans += freq . get ( A [ i ] ) ; } for ( let j = 0 ; j < i ; j ++ ) { for ( let k = 0 ; k < j ; k ++ ) { if ( freq . has ( A [ i ] * A [ j ] * A [ k ] ) ) { freq . set ( freq . get ( A [ i ] * A [ j ] * A [ k ] ) , freq . get ( [ A [ i ] * A [ j ] * A [ k ] ] ) + 1 ) ; } else { freq . set ( A [ i ] * A [ j ] * A [ k ] , 1 ) ; } } } } return ans ; } let arr = [ 10 , 2 , 2 , 7 , 40 , 160 ] ; let N = arr . length ; document . write ( countQuadruples ( arr , N ) ) ;

Index/key variables: i, j, k
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Javascript program:
function printFactors ( n ) { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { let d1 = i , d2 = n ; while ( d2 % d1 == 0 ) { d2 = Math . floor ( d2 / d1 ) ; } if ( d1 > 1 && d2 > 1 ) { document . write ( d1 + " " + d2 ) ; return ; } } } document . write ( - 1 ) ; } let N = 10 ; printFactors ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countTriplets ( arr , n ) { let odd = 0 , even = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & 1 ) odd ++ ; else even ++ ; } let c1 = Math . floor ( odd * ( even * ( even - 1 ) ) / 2 ) ; let c2 = Math . floor ( ( odd * ( odd - 1 ) * ( odd - 2 ) ) / 6 ) ; return c1 + c2 ; } let arr = [ 4 , 5 , 6 , 4 , 5 , 10 , 1 , 7 ] ; let n = arr . length ; let ans = countTriplets ( arr , n ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function maxUniqueElements ( A , N ) { let mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( mp . has ( A [ i ] ) ) { mp . set ( mp . get ( A [ i ] ) , mp . get ( A [ i ] ) + 1 ) ; } else { mp . set ( A [ i ] , 1 ) ; } } let cnt = 0 ; for ( let [ key , value ] of mp ) { if ( value % 2 == 0 ) { cnt ++ ; } } let ans = mp . size ; if ( cnt % 2 == 1 ) { ans -- ; } return ans ; } let N = 5 ; let A = [ 1 , 2 , 1 , 3 , 7 ] ; document . write ( maxUniqueElements ( A , N ) ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function countCells ( n , m , s ) { let mx1 = - 1 ; let cont1 = 0 ; for ( let i = 0 ; i < s && i < n ; ++ i ) { let aux = Math . floor ( ( n - ( i + 1 ) ) / s + 1 ) ; if ( aux > mx1 ) { mx1 = cont1 = aux ; } else if ( aux == mx1 ) cont1 += aux ; } let mx2 = - 1 ; let cont2 = 0 ; for ( let i = 0 ; i < s && i < m ; ++ i ) { let aux = Math . floor ( ( m - ( i + 1 ) ) / s + 1 ) ; if ( aux > mx2 ) mx2 = cont2 = aux ; else if ( aux == mx2 ) cont2 += aux ; } return cont1 * cont2 ; } let N = 5 , M = 5 , K = 2 ; document . write ( countCells ( N , M , K ) ) ;

Accumulator variables: cont1, cont2
Iterator variables: i
Javascript program:
function countTotalPairs ( N , K ) { if ( K == 0 ) { return N * N ; } let ans = 0 ; for ( let b = K + 1 ; b <= N ; b ++ ) { ans += Math . floor ( ( N / b ) * ( b - K ) ) ; ans += Math . max ( N % b - K + 1 , 0 ) ; } return ans ; } let N = 5 , K = 2 ; document . write ( countTotalPairs ( N , K ) ) ;

Accumulator variables: ans, b
Iterator variables: b
Javascript program:
let arr = [ 4 , 2 , 4 , 1 , 4 , 3 ] ; let n = arr . length ; let maxi = 0 , remain , ans ; let freq = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } for ( let it of freq ) { maxi = Math . max ( maxi , it [ 1 ] ) ; } remain = n - maxi ; if ( maxi >= remain ) { ans = remain ; } else { ans = Math . floor ( n / 2 ) ; } document . write ( ans ) ; freq . clear ( ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, it
Javascript program:
function minSumDifference ( ar , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += ar [ i ] ; let rem = sum % n ; return rem * ( n - rem ) ; } let arr = [ 3 , 6 , 8 , 5 , 2 , 1 , 11 , 7 , 10 , 4 ] ; let N = arr . length ; document . write ( minSumDifference ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minSteps ( N ) { let count = 1 , res = 0 ; for ( let i = 1 ; i <= N ; i += count ) { res = Math . max ( res , count ) ; count ++ ; } return res ; } let N = 6 ; document . write ( minSteps ( N ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countReachablePoints ( X , Y , L , R ) { let diff_arr = new Array ( 100000 ) . fill ( 0 ) ; let count = 0 ; diff_arr [ X ] = 1 ; diff_arr [ X + 1 ] = - 1 ; for ( let i = X ; i <= Y ; i ++ ) { diff_arr [ i ] += diff_arr [ i - 1 ] ; if ( diff_arr [ i ] >= 1 ) { diff_arr [ i + L ] += 1 ; diff_arr [ i + R + 1 ] -= 1 ; count ++ ; } } return count ; } let X = 3 , Y = 12 , L = 2 , R = 3 ; document . write ( countReachablePoints ( X , Y , L , R ) ) ;

Index/key variables: X, i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function newNode ( data ) { var new_node = new Node ( ) ; new_node . data = data ; new_node . next = null ; return new_node ; } function reverse ( head ) { var prev = null ; var current = head ; var next ; while ( current != null ) { next = current . next ; current . next = prev ; prev = current ; current = next ; } return prev ; } function multiplyHelp ( head , M ) { var res = head ; var prev = null ; var carry = 0 , product = 1 ; while ( head != null ) { product = head . data * M ; product += carry ; carry = parseInt ( product / 10 ) ; head . data = product % 10 ; prev = head ; head = head . next ; } if ( carry > 0 ) prev . next = newNode ( carry ) ; return res ; } function multiply ( head , M ) { head = reverse ( head ) ; head = multiplyHelp ( head , M ) ; return reverse ( head ) ; } function printList ( node ) { while ( node != null ) { document . write ( node . data ) ; node = node . next ; } } var head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 7 ) ; head . next . next . next = newNode ( 3 ) ; var M = 3 ; head = multiply ( head , M ) ; printList ( head ) ;

Accumulator variables: product
Class/struct names: Node
Javascript program:
let s = new Array ( 11 ) . fill ( 0 ) function sieveOfEratosthenes ( N ) { let prime = new Array ( N + 1 ) . fill ( false ) ; for ( let i = 2 ; i < N + 1 ; i += 2 ) s [ i ] = 2 ; for ( let i = 3 ; i < N + 1 ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( let j = i ; j < Math . floor ( N / i + 1 ) ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } function generatePrimeFactors ( N ) { let curr = s [ N ] ; let cnt = new Map ( ) ; cnt . set ( s [ N ] , 1 ) ; while ( N > 1 ) { N = Math . floor ( N / s [ N ] ) ; if ( N != 0 && s [ N ] != 0 ) if ( ! cnt . has ( s [ N ] ) ) cnt . set ( s [ N ] , 1 ) ; else cnt . set ( s [ N ] , cnt . get ( s [ N ] ) + 1 ) ; } if ( cnt . has ( 0 ) ) cnt . delete ( 0 ) ; let totfactor = 1 ; for ( i of cnt . values ( ) ) totfactor *= i + 1 ; return totfactor ; } function countTriplets ( N ) { let CountTriplet = 0 ; for ( let z = 1 ; z < N + 1 ; z ++ ) { let p = generatePrimeFactors ( N - z ) ; if ( p > 1 ) CountTriplet += p ; } return CountTriplet + 1 ; } let N = 10 ; sieveOfEratosthenes ( N ) ; document . write ( ( countTriplets ( N ) ) ) ;

Index/key variables: N, i
Accumulator variables: CountTriplet, i, j, totfactor, z
Iterator variables: i, j, z
Javascript program:
function minimumSubarray ( arr , n , m ) { let mapu = new Array ( m + 1 ) . fill ( 0 ) ; let c = 0 ; for ( let i = 0 ; i < n ; i ++ ) { mapu [ arr [ i ] ] ++ ; if ( mapu [ arr [ i ] ] == ( n / m ) + 1 ) c ++ ; } if ( c == 0 ) return 0 ; let ans = n ; let l = 0 , r = 0 ; while ( r < n ) { if ( -- mapu [ arr [ r ] ] == ( n / m ) ) c -- ; if ( c == 0 ) { while ( l <= r && c == 0 ) { ans = Math . min ( ans , r - l + 1 ) ; if ( ++ mapu [ arr [ l ] ] > ( n / m ) ) c ++ ; l ++ ; } } r ++ ; } return ans ; } let arr = [ 1 , 1 , 2 , 1 , 1 , 2 ] ; let M = 2 ; let N = arr . length ; document . write ( minimumSubarray ( arr , N , M ) ) ;

Index/key variables: i, l, r
Accumulator variables: c, i, l, r
Iterator variables: i
Javascript program:
function checkSum ( arr , n , k ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( m . get ( arr [ i ] ) , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) ; } } let freq = new Array ( n + 1 ) ; for ( let i = 0 ; i < n ; i ++ ) { let f = m . get ( arr [ i ] ) ; if ( f != - 1 ) { freq [ f ] = new Array ( ) ; freq [ f ] . push ( arr [ i ] ) ; m . set ( arr [ i ] , - 1 ) ; } } let count = 0 ; let kleastfreqsum = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { for ( let x in freq [ i ] ) { kleastfreqsum += x ; count ++ ; if ( count == k ) break ; } if ( count == k ) break ; } count = 0 ; let kmostfreqsum = 0 ; for ( let i = n ; i >= 0 ; i -- ) { for ( let x in freq [ i ] ) { kmostfreqsum += x ; count ++ ; if ( count == k ) break ; } if ( count == k ) break ; } if ( kleastfreqsum == kmostfreqsum ) return " " ; return " " ; } let arr = [ 3 , 2 , 1 , 2 , 3 , 3 , 4 ] ; let N = arr . length ; let K = 2 ; document . write ( checkSum ( arr , N , K ) ) ;

Index/key variables: f, i
Accumulator variables: count, i, kleastfreqsum, kmostfreqsum
Iterator variables: i, x
Javascript program:
function minDistance ( start , intend , n , d ) { let left = Number . MIN_SAFE_INTEGER ; let right = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { left = Math . max ( left , start [ i ] ) ; right = Math . min ( right , end [ i ] ) ; } if ( left > right ) return - 1 ; if ( d >= left && d <= right ) return 0 ; if ( d < left ) return left - d ; if ( d > right ) return d - right ; } let start = [ 0 , 2 , 4 ] ; let end = [ 7 , 14 , 6 ] ; let n = start . length ; let d = 3 ; document . write ( minDistance ( start , end , n , d ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function power ( x , y ) { if ( y == 0 ) return 1 ; if ( y % 2 == 0 ) return power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ; return x * power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ; } function order ( num ) { let count = 0 ; while ( num ) { count ++ ; num = Math . floor ( num / 10 ) ; } return count ; } function isArmstrong ( N ) { let r = order ( N ) ; let temp = N , sum = 0 ; while ( temp ) { let d = temp % 10 ; sum += power ( d , r ) ; temp = Math . floor ( temp / 10 ) ; } return sum == N ; } function maxSum ( arr , N , K ) { if ( N < K ) { return - 1 ; } let res = 0 ; for ( let i = 0 ; i < K ; i ++ ) { res += arr [ i ] ; } let curr_sum = res ; for ( let i = K ; i < N ; i ++ ) { curr_sum += arr [ i ] - arr [ i - K ] ; res = Math . max ( res , curr_sum ) ; } return res ; } function maxArmstrong ( arr , N , K ) { for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = isArmstrong ( arr [ i ] ) ; } return maxSum ( arr , N , K ) ; } let arr = [ 28 , 2 , 3 , 6 , 153 , 99 , 828 , 24 ] ; let K = 6 ; let N = arr . length ; document . write ( maxArmstrong ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, curr_sum, i, res, sum
Iterator variables: i
Javascript program:
function fact ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { res = res * i ; } return res ; } function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function countWays ( s , t ) { let n = s . length ; let sum1 = 0 , sum2 = 0 , K = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { sum1 ++ ; } else sum1 -- ; } let m = t . length ; for ( let i = 0 ; i < m ; i ++ ) { if ( t [ i ] == ' ' ) { sum2 ++ ; } else if ( t [ i ] == ' ' ) { sum2 -- ; } else K ++ ; } let P = Math . abs ( sum1 - sum2 ) ; if ( P > K || ( K - P ) % 2 ) { document . write ( 0 ) ; return ; } document . write ( nCr ( K , ( P + K ) / 2 ) ) ; } let S1 = " " ; let S2 = " " ; countWays ( S1 , S2 ) ;

Index/key variables: i
Accumulator variables: K, i, sum1, sum2
Iterator variables: i
Javascript program:
function countPairs ( arr , N ) { let answer = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] + arr [ j ] == i + j ) { answer ++ ; } } } document . write ( answer ) ; } let arr = [ 0 , 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; countPairs ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j