dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function gcd ( a , b ) { return b == 0 ? a : gcd ( b , a % b ) ; } function find_LCM ( x , y ) { return Math . floor ( ( x * y ) / gcd ( x , y ) ) ; } function CountPairs ( n , m , A , B ) { let cnt = 0 ; let lcm = find_LCM ( A , B ) ; for ( let i = 1 ; i <= n ; i ++ ) cnt += Math . floor ( ( m + ( i % lcm ) ) / lcm ) ; return cnt ; } let n = 60 , m = 90 , A = 5 , B = 10 ; document . write ( CountPairs ( n , m , A , B ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function sortArr ( arr , n , min , max ) { let m = max - min + 1 ; let c = new Array ( m ) ; c . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { c [ arr [ i ] - min ] ++ ; } for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < c [ i ] ; j ++ ) { document . write ( ( i + min ) + " " ) ; } } } let arr = [ 10 , 10 , 1 , 4 , 4 , 100 , 0 ] ; let min = 0 , max = 100 ; let n = arr . length ; sortArr ( arr , n , min , max ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPossible ( D , arr , N , K ) { let used = 0 ; for ( let i = 0 ; i < N - 1 ; ++ i ) { used += Math . floor ( ( arr [ i + 1 ] - arr [ i ] ) / D ) ; } return used <= K ; } function minMaxDist ( stations , N , K ) { let low = 0 , high = 1e8 ; while ( high - low > 1e-6 ) { let mid = ( low + high ) / 2 ; if ( isPossible ( mid , stations , N , K ) ) { high = mid ; } else { low = mid ; } } return low . toFixed ( 1 ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; let K = 9 ; let N = arr . length ; document . write ( minMaxDist ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: used
Iterator variables: i
Javascript program:
function findMissingBinaryString ( nums , N ) { let s = new Set ( ) ; let counter = 0 ; for ( let str of nums ) { s . add ( str ) ; } let total = Math . pow ( 2 , N ) ; let ans = " " ; for ( let i = 0 ; i < total ; i ++ ) { let num = " " ; for ( let j = N - 1 ; j >= 0 ; j -- ) { if ( i & ( 1 << j ) ) { num += " " ; } else { num += " " ; } } if ( s . has ( num ) ) { continue ; counter ++ ; } else { document . write ( num + " " ) ; } } if ( counter == total ) { document . write ( " " ) ; } } let N = 3 ; let arr = [ " " , " " , " " , " " , " " , " " ] ; findMissingBinaryString ( arr , N ) ;

Accumulator variables: counter, i, j, num
Iterator variables: i, j, str
Javascript program:
function check ( a , b , k , n , x ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + Math . pow ( Math . max ( a [ i ] - x , 0 ) , b [ i ] ) ; } if ( sum <= k ) return true ; else return false ; } function max_element ( a ) { let maxi = Number . MIN_VALUE ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] > maxi ) { maxi = a [ i ] ; } } return maxi ; } function findMin ( a , b , n , k ) { let l = 0 , u = max_element ( a ) ; while ( l < u ) { let m = Math . floor ( ( l + u ) / 2 ) ; if ( check ( a , b , k , n , m ) ) { u = m ; } else { l = m + 1 ; } } return l ; } let arr = [ 2 , 1 , 4 , 3 , 5 ] ; let brr = [ 4 , 3 , 2 , 3 , 1 ] ; let K = 12 ; let N = arr . length ; document . write ( findMin ( arr , brr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getPairsCount ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = arr [ i ] - ( i % arr [ i ] ) ; j < n ; j += arr [ i ] ) { if ( i < j && arr [ i ] * arr [ j ] == Math . abs ( i - j ) ) { count ++ ; } } } return count ; } let arr = [ 1 , 1 , 2 , 4 ] ; let N = arr . length ; document . write ( getPairsCount ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function printOccurences ( arr , N ) { let mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < arr [ i ] . length ; j ++ ) { if ( mp . has ( arr [ i ] [ j ] ) ) { let temp = mp . get ( arr [ i ] [ j ] ) ; temp . push ( [ i + 1 , j + 1 ] ) ; mp . set ( arr [ i ] [ j ] , temp ) ; } else { mp . set ( arr [ i ] [ j ] , [ [ i + 1 , j + 1 ] ] ) ; } } } for ( let it of new Map ( [ ... mp . entries ( ) ] . sort ( ) ) ) { document . write ( " " + it [ 0 ] + " " ) ; for ( let j = 0 ; j < it [ 1 ] . length ; j ++ ) { document . write ( " " + it [ 1 ] [ j ] [ 0 ] + " " + it [ 1 ] [ j ] [ 1 ] + " " ) ; } document . write ( " " ) ; } } let arr = [ " " , " " ] ; let N = arr . length ; printOccurences ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, it, j
Javascript program:
function mostFrequent ( arr , N ) { let ans = new Array ( N ) . fill ( 0 ) for ( let i = 0 ; i < N ; i ++ ) { let count = new Array ( N ) ; count . fill ( 0 ) let best = 1 ; for ( let j = i ; j < N ; j ++ ) { count [ arr [ j ] - 1 ] ++ ; if ( count [ arr [ j ] - 1 ] > count [ best - 1 ] || ( count [ arr [ j ] - 1 ] == count [ best - 1 ] && arr [ j ] < best ) ) { best = arr [ j ] ; } ans [ best - 1 ] ++ ; } } console . log ( ans ) for ( let i = 0 ; i < N ; i ++ ) document . write ( ans [ i ] + " " ) ; } let arr = [ 2 , 1 , 2 , 3 ] ; let N = arr . length mostFrequent ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countElement ( arr , N ) { let count = 0 ; let m = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) } } for ( let i = 0 ; i < N ; i ++ ) { let lg = Math . floor ( Math . log2 ( arr [ i ] ) ) ; let p = Math . pow ( 2 , lg ) ; if ( m . get ( p ) ) { count ++ ; } } return count ; } let arr = [ 3 , 4 , 6 , 9 ] ; let N = arr . length document . write ( countElement ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function lower_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + Math . floor ( ( high - low ) / 2 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function maximumLetersections ( arr , N ) { let count = 0 ; let L = Array . from ( { length : N } , ( _ , i ) => 0 ) ; let R = Array . from ( { length : N } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { L [ i ] = arr [ i ] [ 0 ] ; R [ i ] = arr [ i ] [ 1 ] ; } L . sort ( ) ; R . sort ( ) ; for ( let i = 0 ; i < N ; i ++ ) { let l = arr [ i ] [ 0 ] ; let r = arr [ i ] [ 1 ] ; let x = lower_bound ( L , 0 , N , l ) ; let y = N - lower_bound ( R , 0 , N , r + 1 ) ; let cnt = x + y ; cnt = N - cnt - 1 ; count = Math . max ( count , cnt ) ; } return count ; } let arr = [ [ 1 , 6 ] , [ 5 , 5 ] , [ 2 , 3 ] ] ; let N = arr . length ; document . write ( maximumLetersections ( arr , N ) ) ;

Index/key variables: i, middle
Accumulator variables: i
Iterator variables: i
Javascript program:
let head1 = null ; let head2 = null ; class Node { constructor ( x ) { this . data = x ; this . next = null ; } } constructor ( x ) { this . data = x ; this . next = null ; } } function intersectingNode ( headA , headB ) { let a = headA ; while ( a != null ) { a . data *= - 1 ; a = a . next ; } let b = headB ; while ( b != null ) { if ( b . data < 0 ) break ; b = b . next ; } return b ; } function formLinkList ( ) { head1 = new Node ( 3 ) ; head1 . next = new Node ( 6 ) ; head1 . next . next = new Node ( 9 ) ; head1 . next . next . next = new Node ( 15 ) ; head1 . next . next . next . next = new Node ( 30 ) ; head2 = new Node ( 10 ) ; head2 . next = head1 . next . next . next ; return ; } formLinkList ( ) ; document . write ( Math . abs ( intersectingNode ( head1 , head2 ) . data ) ) ;

Accumulator variables: data
Class/struct names: Node
Javascript program:
class Node { constructor ( v ) { this . val = v ; this . left = this . right = null ; } } function isInc ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; let pre = que [ 0 ] ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; if ( pre . val > temp . val ) return false ; pre = temp ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } } return true ; } function levelOrder ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; document . write ( temp . val + " " ) ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } document . write ( " " ) ; } document . write ( " " ) ; } function makeInc ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; let prev = - 1 ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; let optEle = temp . val ; let strEle = ( optEle ) . toString ( ) ; let flag = true ; let yy = strEle . length ; for ( let idx = 0 ; idx < strEle . length ; idx ++ ) { let s1 = strEle . substring ( idx , yy ) ; let s2 = strEle . substring ( 0 , idx ) ; let s = s1 + s2 ; let ls = parseInt ( s ) ; if ( ls >= prev && flag ) { optEle = ls ; flag = false ; } if ( ls >= prev ) optEle = Math . min ( optEle , ls ) ; } temp . val = optEle ; prev = temp . val ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } } if ( isInc ( root ) == true ) levelOrder ( root ) ; else document . write ( - 1 ) ; } let root = new Node ( 341 ) ; root . left = new Node ( 241 ) ; root . right = new Node ( 123 ) ; root . left . left = new Node ( 324 ) ; root . left . right = new Node ( 235 ) ; root . right . right = new Node ( 161 ) ; makeInc ( root ) ;

Accumulator variables: idx, len
Iterator variables: idx
Boolean variables: flag
Class/struct names: Node
Javascript program:
function removeDuplicateCharacters ( arr ) { var cset = new Set ( ) ; var n = arr . length ; var out = [ ] ; arr . forEach ( str => { var out_curr = " " ; str . split ( ' ' ) . forEach ( ch => { if ( ! cset . has ( ch ) ) { out_curr += ch ; cset . add ( ch ) ; } } ) ; if ( out_curr . size != 0 ) out . push ( out_curr ) ; } ) ; for ( var i = 0 ; i < out . length ; i ++ ) { document . write ( out [ i ] + " " ) ; } } var arr = [ " " , " " , " " , " " ] ; removeDuplicateCharacters ( arr ) ;

Index/key variables: i
Accumulator variables: i, out_curr
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; var i ; for ( i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function primeFactorSum ( arr , n , k ) { var sum = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) { if ( k % arr [ i ] == 0 && isPrime ( arr [ i ] ) ) { sum = sum + arr [ i ] ; } } document . write ( sum ) ; } var arr = [ 1 , 2 , 3 , 5 , 6 , 7 , 15 ] var N = arr . length ; var K = 35 ; primeFactorSum ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( nums , x ) { let sum = 0 ; for ( let i = 0 ; i < x ; i ++ ) sum += nums [ i ] ; if ( sum < x ) return - 1 ; let ans = Number . MAX_VALUE ; let l = nums . length - 1 , r = nums . length ; x -= sum ; while ( l >= 0 ) { if ( x <= 0 ) { x += nums [ l ] ; l -= 1 ; } if ( x > 0 ) { r -= 1 ; x -= nums [ r ] ; } if ( x == 0 ) { ans = Math . min ( ans , ( l + 1 ) + ( nums . length - r ) ) ; } } if ( ans < Number . MAX_VALUE ) return ans ; else return - 1 ; } let nums = [ 1 , 1 , 4 , 2 , 3 ] ; let x = 5 ; document . write ( minOperations ( nums , x ) ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r, sum, x
Iterator variables: i
Javascript program:
function evenproduct ( arr , length ) { var total_subarray = length * ( length + 1 ) / 2 ; var total_odd = 0 ; var count_odd = 0 ; for ( i = 0 ; i < arr . length ; ++ i ) { if ( arr [ i ] % 2 == 0 ) { count_odd = 0 ; } else { ++ count_odd ; total_odd += count_odd ; } } document . write ( total_subarray - total_odd ) ; } var arr = [ 7 , 5 , 4 , 9 ] ; var length = arr . length ; evenproduct ( arr , length ) ;

Index/key variables: i
Accumulator variables: total_odd
Iterator variables: i
Javascript program:
function checkGroup ( arr ) { if ( arr . length <= 2 ) return true ; let corner = arr [ 0 ] + arr [ arr . length - 1 ] ; let xorSum = 0 ; for ( let i = 0 ; i < arr . length - 1 ; i ++ ) xorSum += ( arr [ i ] ^ arr [ i + 1 ] ) ; if ( corner == 0 ) if ( xorSum > 2 ) return false ; else if ( corner == 1 ) if ( xorSum > 1 ) return false ; else if ( xorSum > 0 ) return false ; return true ; } function isInGroupUtil ( mat ) { for ( let i = 0 ; i < mat . length ; i ++ ) { let arr = [ ] for ( let j = 0 ; j < mat [ i ] . length ; j ++ ) { arr . push ( mat [ i ] [ j ] ) ; } if ( ! checkGroup ( arr ) ) return false ; } return true ; } function isInGroup ( mat ) { let ans = isInGroupUtil ( mat ) ; if ( ans ) document . write ( " " ) ; else document . write ( " " ) ; } let mat = [ [ 0 , 1 , 1 , 0 ] , [ 1 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 1 ] , [ 1 , 1 , 1 , 0 ] ] ; isInGroup ( mat ) ;

Index/key variables: i, j
Accumulator variables: i, j, xorSum
Iterator variables: i, j
Javascript program:
function productOfDigits ( N ) { let product = 1 ; while ( N != 0 ) { product = product * ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } return product ; } function productOfDigitsK ( N , K ) { let flag = 0 ; for ( let i = 1 ; i <= N ; ++ i ) { if ( K == productOfDigits ( i ) ) { document . write ( i + " " ) ; flag = 1 ; } } if ( flag == 0 ) document . write ( - 1 ) ; } let N = 500 , K = 10 ; productOfDigitsK ( N , K ) ;

Iterator variables: i
Javascript program:
function minimiseDifference ( arr , K ) { var N = arr . length ; var maxSuffix = new Array ( N + 1 ) ; var minSuffix = new Array ( N + 1 ) ; maxSuffix [ N ] = - 1e9 ; minSuffix [ N ] = 1e9 ; maxSuffix [ N - 1 ] = arr [ N - 1 ] ; minSuffix [ N - 1 ] = arr [ N - 1 ] ; for ( var i = N - 2 ; i >= 0 ; -- i ) { maxSuffix [ i ] = Math . max ( maxSuffix [ i + 1 ] , arr [ i ] ) ; minSuffix [ i ] = Math . min ( minSuffix [ i + 1 ] , arr [ i ] ) ; } var maxPrefix = arr [ 0 ] ; var minPrefix = arr [ 0 ] ; var minDiff = maxSuffix [ K ] - minSuffix [ K ] ; for ( var i = 1 ; i < N ; ++ i ) { if ( i + K <= N ) { var maximum = Math . max ( maxSuffix [ i + K ] , maxPrefix ) ; var minimum = Math . min ( minSuffix [ i + K ] , minPrefix ) ; minDiff = Math . min ( minDiff , maximum - minimum ) ; } maxPrefix = Math . max ( maxPrefix , arr [ i ] ) ; minPrefix = Math . min ( minPrefix , arr [ i ] ) ; } document . write ( minDiff + " " ) ; } var arr = [ 4 , 5 , 8 , 9 , 1 , 2 ] ; var K = 2 ; minimiseDifference ( arr , K ) ;

Index/key variables: K, N, i
Iterator variables: i
Javascript program:
function longestSubstring ( s , k ) { let ans = 0 ; let freq = new Array ( 26 ) ; freq . fill ( 0 ) ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) freq [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; let unique = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) if ( freq [ i ] != 0 ) unique ++ ; for ( let curr_unique = 1 ; curr_unique <= unique ; curr_unique ++ ) { for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } let start = 0 , end = 0 ; let cnt = 0 , count_k = 0 ; while ( end < n ) { if ( cnt <= curr_unique ) { let ind = s [ end ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( freq [ ind ] == 0 ) cnt ++ ; freq [ ind ] ++ ; if ( freq [ ind ] == k ) count_k ++ ; end ++ ; } else { let ind = s [ start ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( freq [ ind ] == k ) count_k -- ; freq [ ind ] -- ; if ( freq [ ind ] == 0 ) cnt -- ; start ++ ; } if ( cnt == curr_unique && count_k == curr_unique ) ans = Math . max ( ans , end - start ) ; } } document . write ( ans ) ; } let S = " " ; let K = 3 ; longestSubstring ( S , K ) ;

Index/key variables: end, i, ind, start
Accumulator variables: cnt, count_k, curr_unique, end, i, start, unique
Iterator variables: curr_unique, i
Javascript program:
let dRow = [ - 1 , 0 , 1 , 0 ] ; let dCol = [ 0 , 1 , 0 , - 1 ] ; function isValid ( vis , row , col , COL , ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis [ row ] [ col ] == true ) return false ; return true ; } function DFSUtil ( row , col , grid , vis , M , N ) { vis [ row ] [ col ] = true ; document . write ( grid [ row ] [ col ] + " " ) ; for ( let i = 0 ; i < 4 ; i ++ ) { let x = row + dRow [ i ] ; let y = col + dCol [ i ] ; if ( isValid ( vis , x , y , M , N ) ) DFSUtil ( x , y , grid , vis , M , N ) ; } } function DFS ( row , col , grid , M , N ) { let vis = new Array ( M + 1 ) ; for ( var i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < M + 1 ; i ++ ) { for ( let j = 0 ; j < N + 1 ; j ++ ) { vis [ i ] [ j ] = false ; } } DFSUtil ( 0 , 0 , grid , vis , M , N ) ; } let grid = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let M = grid . length ; let N = grid [ 0 ] . length ; DFS ( 0 , 0 , grid , M , N ) ;

Index/key variables: col, i, j, row
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dRow = [ - 1 , 0 , 1 , 0 ] ; let dCol = [ 0 , 1 , 0 , - 1 ] ; let vis ; function isValid ( row , col , COL , ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis [ row ] [ col ] == true ) return false ; return true ; } function DFS_iterative ( grid , M , N ) { vis = [ ] ; for ( let i = 0 ; i < M + 5 ; i ++ ) { vis . push ( [ ] ) ; for ( let j = 0 ; j < N + 5 ; j ++ ) { vis [ i ] . push ( false ) ; } } let st = [ ] ; st . push ( [ 0 , 0 ] ) ; vis [ 0 ] [ 0 ] = true ; while ( st . length > 0 ) { let p = st [ st . length - 1 ] ; st . pop ( ) ; let row = p [ 0 ] ; let col = p [ 1 ] ; document . write ( grid [ row ] [ col ] + " " ) ; for ( let i = 0 ; i < 4 ; i ++ ) { let x = row + dRow [ i ] ; let y = col + dCol [ i ] ; if ( isValid ( x , y , M , N ) ) { st . push ( [ x , y ] ) ; vis [ x ] [ y ] = true ; } } } } let grid = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let M = grid . length ; let N = grid [ 0 ] . length ; DFS_iterative ( grid , M , N ) ;

Index/key variables: col, i, row, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minOps ( s , N ) { var ans = 0 ; for ( i = 1 ; i < N ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( i - 1 ) ) { ans ++ ; } } if ( ans % 2 == 1 ) { document . write ( ( ans - 1 ) / 2 ) ; return ; } document . write ( ans / 2 ) ; } var str = " " ; var N = str . length ; minOps ( str , N ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let MAX = 1000001 let prime = new Array ( MAX ) . fill ( true ) ; let cntTriplet = new Array ( MAX ) . fill ( 0 ) ; function primeTriplet ( N ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( prime [ i ] ) { for ( let j = i * i ; j <= N ; j += i ) { prime [ j ] = false ; } } } for ( let i = 3 ; i <= N ; i ++ ) { for ( let i = 2 ; i * i <= N ; i ++ ) { if ( prime [ i ] ) { for ( let j = i * i ; j <= N ; j += i ) { prime [ j ] = false ; } } } for ( let i = 3 ; i <= N ; i ++ ) { if ( prime [ i ] && prime [ i - 2 ] ) { cntTriplet [ i ] = cntTriplet [ i - 1 ] + 1 ; } else { cntTriplet [ i ] = cntTriplet [ i - 1 ] ; } } document . write ( cntTriplet [ N ] ) ; } let N = 7 ; primeTriplet ( N ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function OddOneOut ( arr , N ) { let e = new Map ( ) ; let o = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { e . set ( arr [ i ] , i ) ; } else { o . set ( arr [ i ] , i ) ; } } if ( e . size == 1 ) { document . write ( Array . from ( e . values ( ) ) [ 0 ] ) ; } else { document . write ( Array . from ( o . values ( ) ) [ 0 ] ) ; } } let arr = [ 2 , 4 , 7 , 8 , 10 ] ; let N = arr . length ; OddOneOut ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( a , n ) { if ( n == 1 ) { document . write ( 0 ) ; return ; } let pre = new Array ( n - 1 ) ; let suf = new Array ( n - 1 ) ; let max = a [ 0 ] ; let ans = 0 , i ; pre [ 0 ] = a [ 0 ] ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i ] > max ) max = a [ i ] ; pre [ i ] = max ; } max = a [ n - 1 ] ; suf [ n - 2 ] = a [ n - 1 ] ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( a [ i ] > max ) max = a [ i ] ; suf [ i - 1 ] = max ; } for ( i = 0 ; i < n - 1 ; i ++ ) { if ( pre [ i ] < suf [ i ] ) ans ++ ; } document . write ( ans ) ; } let arr = [ 2 , 3 , 4 , 8 , 1 , 4 ] ; let N = arr . length ; count ( arr , N ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function xorSubsequence ( a , n , k ) { var ans = 0 ; var map = new Map ( ) ; var dp = Array ( n ) . fill ( 0 ) ; map . set ( a [ 0 ] , 1 ) dp [ 0 ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { var dpj ; if ( map . has ( a [ i ] ^ k ) ) { dpj = map . get ( a [ i ] ^ k ) ; } else { dpj = - 1 ; } if ( dpj != 0 ) dp [ i ] = Math . max ( dp [ i ] , dpj + 1 ) ; ans = Math . max ( ans , dp [ i ] ) ; if ( map . has ( a [ i ] ) ) { map . set ( a [ i ] , Math . max ( map . get ( a [ i ] ) + 1 , dp [ i ] ) ) ; } else { map . set ( a [ i ] , Math . max ( 1 , dp [ i ] ) ) ; } } return ans >= 2 ? ans : 0 ; } var arr = [ 3 , 2 , 4 , 3 , 5 ] ; var N = arr . length ; var K = 1 ; document . write ( xorSubsequence ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var ans ; class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } class TreeNode { constructor ( ) { this . data = 0 ; this . left = null ; this . right = null ; } } function newNode ( data ) { var Node = new TreeNode ( ) ; Node . data = data ; Node . left = null ; Node . right = null ; return Node ; } function sumofsubtree ( root ) { var p = new pair ( 1 , 0 ) ; if ( root . left != null ) { var ptemp = sumofsubtree ( root . left ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } if ( root . right != null ) { var ptemp = sumofsubtree ( root . right ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } ans += p . second ; return p ; } var root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . left . left . left = newNode ( 8 ) ; root . left . left . right = newNode ( 9 ) ; ans = 0 ; sumofsubtree ( root ) ; document . write ( ans ) ;

Accumulator variables: ans, first, second
Class/struct names: TreeNode, pair
Javascript program:
function minTime ( arr , N , K ) { var q = [ ] ; var vis = Array ( N + 1 ) . fill ( false ) ; var time = 0 ; for ( var i = 0 ; i < K ; i ++ ) { q . push ( arr [ i ] ) ; vis [ arr [ i ] ] = true ; } while ( q . length > 0 ) { for ( var i = 0 ; i < q . length ; i ++ ) { var curr = q [ 0 ] ; q . pop ( ) ; if ( curr - 1 >= 1 && ! vis [ curr - 1 ] ) { vis [ curr - 1 ] = true ; q . push ( curr - 1 ) ; } if ( curr + 1 <= N && ! vis [ curr + 1 ] ) { vis [ curr + 1 ] = true ; q . push ( curr + 1 ) ; } } time ++ ; } document . write ( time - 1 ) ; } var N = 6 ; var arr = [ 2 , 6 ] ; var K = arr . length ; minTime ( arr , N , K ) ;

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