dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var size = 4 ; function checkStar ( mat ) { var vertexD1 = 0 , vertexDn_1 = 0 ; if ( size == 1 ) return ( mat [ 0 ] [ 0 ] == 0 ) ; if ( size == 2 ) return ( mat [ 0 ] [ 0 ] == 0 && mat [ 0 ] [ 1 ] == 1 && mat [ 1 ] [ 0 ] == 1 && mat [ 1 ] [ 1 ] == 0 ) ; for ( var i = 0 ; i < size ; i ++ ) { var degreeI = 0 ; for ( var j = 0 ; j < size ; j ++ ) if ( mat [ i ] [ j ] ) degreeI ++ ; if ( degreeI == 1 ) vertexD1 ++ ; else if ( degreeI == size - 1 ) vertexDn_1 ++ ; } return ( vertexD1 == ( size - 1 ) && vertexDn_1 == 1 ) ; } var mat = [ [ 0 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] ] ; checkStar ( mat ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: degreeI, i, j, vertexD1, vertexDn_1
Iterator variables: i, j
Javascript program:
function orientation ( a , b , c ) { let res = ( b [ 1 ] - a [ 1 ] ) * ( c [ 0 ] - b [ 0 ] ) - ( c [ 1 ] - b [ 1 ] ) * ( b [ 0 ] - a [ 0 ] ) ; if ( res == 0 ) return 0 ; if ( res > 0 ) return 1 ; return - 1 ; } function sqDist ( p1 , p2 ) { return ( p1 [ 0 ] - p2 [ 0 ] ) * ( p1 [ 0 ] - p2 [ 0 ] ) + ( p1 [ 1 ] - p2 [ 1 ] ) * ( p1 [ 1 ] - p2 [ 1 ] ) ; } function inside ( A , p ) { let mid = [ 0 , 0 ] ; let n = A . length ; for ( let i = 0 ; i < n ; i ++ ) { mid [ 0 ] += A [ i ] [ 0 ] ; mid [ 1 ] += A [ i ] [ 1 ] ; } for ( let i = 0 , j ; i < n ; i ++ ) { j = ( i + 1 ) % n ; let x1 = A [ i ] [ 0 ] * n , x2 = A [ j ] [ 0 ] * n ; let y1 = A [ i ] [ 1 ] * n , y2 = A [ j ] [ 1 ] * n ; let a1 = y1 - y2 ; let b1 = x2 - x1 ; let c1 = x1 * y2 - y1 * x2 ; let for_mid = a1 * mid [ 0 ] + b1 * mid [ 1 ] + c1 ; let for_p = a1 * p [ 0 ] * n + b1 * p [ 1 ] * n + c1 ; if ( for_mid * for_p < 0 ) return false ; } return true ; } function addPoint ( a , p ) { if ( inside ( a , p ) ) return ; let ind = 0 ; let n = a . length ; for ( let i = 1 ; i < n ; i ++ ) { if ( sqDist ( p , a [ i ] ) < sqDist ( p , a [ ind ] ) ) { ind = i ; } } let up = ind ; while ( orientation ( p , a [ up ] , a [ ( up + 1 ) % n ] ) >= 0 ) up = ( up + 1 ) % n ; let low = ind ; while ( orientation ( p , a [ low ] , a [ ( n + low - 1 ) % n ] ) <= 0 ) low = ( n + low - 1 ) % n ; let ret = [ ] ; let curr = up ; ret . push ( a [ curr ] ) ; while ( curr != low ) { curr = ( curr + 1 ) % n ; ret . push ( a [ curr ] ) ; } ret . push ( p ) ; a = [ ] ; for ( let i = 0 ; i < ret . length ; i ++ ) { a . push ( ret [ i ] ) ; } return a ; } let a = [ ] a . push ( [ 0 , 0 ] ) ; a . push ( [ 3 , - 1 ] ) ; a . push ( [ 4 , 5 ] ) ; a . push ( [ - 1 , 4 ] ) ; let n = a . length ; let p = [ 100 , 100 ] ; a = addPoint ( a , p ) ; for ( let e = 0 ; e < a . length ; e ++ ) { document . write ( " " + a [ e ] [ 0 ] + " " + a [ e ] [ 1 ] + " " ) ; }

Index/key variables: curr, e, i, ind, j, low, up
Accumulator variables: e, i
Iterator variables: e, i
Javascript program:
function getDistance ( x1 , y1 , x2 , y2 ) { return ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ; } function triangleWithNoPointInside ( points , N ) { var first = 0 ; var second = 0 ; var third = 0 ; var minD = Number . MAX_VALUE ; for ( i = 0 ; i < N ; i ++ ) { if ( i == first ) continue ; var d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( minD > d ) { minD = d ; second = i ; } } minD = Number . MAX_VALUE ; for ( i = 0 ; i < N ; i ++ ) { if ( i == first i == second ) continue ; var d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( ( points [ i ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ second ] [ 1 ] - points [ first ] [ 1 ] ) != ( points [ second ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ i ] [ 1 ] - points [ first ] [ 1 ] ) && minD > d ) { minD = d ; third = i ; } } document . write ( points [ first ] [ 0 ] + " " + points [ first ] [ 1 ] + " " ) ; document . write ( points [ second ] [ 0 ] + " " + points [ second ] [ 1 ] + " " ) ; document . write ( points [ third ] [ 0 ] + " " + points [ third ] [ 1 ] + " " ) ; } var points = [ [ 0 , 0 ] , [ 0 , 2 ] , [ 2 , 0 ] , [ 2 , 2 ] , [ 1 , 1 ] ] ; var N = points . length ; triangleWithNoPointInside ( points , N ) ;

Index/key variables: first, i, second, third
Accumulator variables: i
Iterator variables: i
Javascript program:
function getMinSteps ( n ) { let table = new Array ( n + 1 ) ; table . fill ( 0 ) ; table [ 1 ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( ! ( i % 2 ) && ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 2 ] ) ; else if ( ! ( i % 3 ) && ( i % 2 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 3 ] ) ; else if ( ! ( i % 2 ) && ! ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , Math . min ( table [ i / 2 ] , table [ i / 3 ] ) ) ; else table [ i ] = 1 + table [ i - 1 ] ; } return table [ n ] + 1 ; } ' ' ' ' ' ' let n = 10 ; document . write ( getMinSteps ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
const mxn = 1e4 + 1 ; let prime = new Array ( mxn + 1 ) ; function SieveOfEratosthenes ( ) { prime . fill ( true ) ; for ( let p = 2 ; p * p <= mxn ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= mxn ; i += p ) prime [ i ] = false ; } } } function countMin ( arr , n ) { let cMinSwaps = 0 ; let cPrimeIndices = 0 ; let cPrimeNos = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ i + 1 ] ) { cPrimeIndices ++ ; if ( ! prime [ arr [ i ] ] ) cMinSwaps ++ ; else cPrimeNos ++ ; } else if ( prime [ arr [ i ] ] ) { cPrimeNos ++ ; } } if ( cPrimeNos >= cPrimeIndices ) return cMinSwaps ; else return - 1 ; } SieveOfEratosthenes ( ) ; let n = 5 ; let arr = [ 2 , 7 , 8 , 5 , 13 ] ; document . write ( countMin ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: cMinSwaps, cPrimeIndices, cPrimeNos, i, p
Iterator variables: i, p
Javascript program:
function largestSubset ( a , N ) { let bit = new Array ( 32 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { let x = 31 ; while ( a [ i ] > 0 ) { if ( a [ i ] & 1 == 1 ) { bit [ x ] ++ ; } a [ i ] = a [ i ] >> 1 ; x -- ; } } let max = Number . MIN_VALUE ; for ( let i = 0 ; i < 32 ; i ++ ) { max = Math . max ( max , bit [ i ] ) ; } document . write ( max ) ; } let arr = [ 7 , 13 , 8 , 2 , 3 ] ; let N = arr . length ; largestSubset ( arr , N ) ;

Index/key variables: i, x
Accumulator variables: i, x
Iterator variables: i
Javascript program:
function Find ( parent , a ) { return ( parent [ a ] = parent [ a ] == a ? a : Find ( parent , parent [ a ] ) ) ; } function Union ( parent , rank , maxValue , a , b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( a == b ) return ; if ( rank [ a ] == rank [ b ] ) { rank [ a ] ++ ; } if ( rank [ a ] < rank [ b ] ) { let temp = a ; a = b ; b = temp ; } parent [ b ] = a ; maxValue [ a ] = Math . max ( maxValue [ a ] , maxValue [ b ] ) ; } function findMaxValueOfSet ( arr , queries , R , N , M ) { let parent = new Array ( R + 1 ) ; let rank = new Array ( R + 1 ) . fill ( 0 ) ; let maxValue = new Array ( R + 1 ) ; for ( let i = 1 ; i < R + 1 ; i ++ ) { parent [ i ] = maxValue [ i ] = i ; } for ( let i = 0 ; i < N ; i ++ ) { Union ( parent , rank , maxValue , arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } for ( let i = 0 ; i < M ; i ++ ) { let P = Find ( parent , queries [ i ] ) ; document . write ( maxValue [ P ] + " " ) ; } } let R = 5 ; let arr = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 4 , 5 ] , ] ; let queries = [ 2 , 4 , 1 , 3 ] ; let N = arr . length ; let M = queries . length ; findMaxValueOfSet ( arr , queries , R , N , M ) ;

Index/key variables: P, a, b, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxAns = - 2147483648 ; const Find = ( parent , a ) => { return parent [ a ] = ( parent [ a ] == a ) ? a : ( Find ( parent , parent [ a ] ) ) ; } const Union = ( parent , rank , setSum , a , b ) => { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( a == b ) return ; if ( rank [ a ] > rank [ b ] ) rank [ a ] ++ ; if ( rank [ b ] > rank [ a ] ) swap ( a , b ) ; parent [ b ] = a ; setSum [ a ] += setSum [ b ] ; } const maxValues = ( arr , queries , N ) => { let parent = new Array ( N + 1 ) . fill ( 0 ) ; let rank = new Array ( N + 1 ) . fill ( 0 ) ; let setSum = new Array ( N + 1 ) . fill ( 0 ) ; let currMax = [ ] ; for ( let i = 1 ; i < N + 1 ; i ++ ) { parent [ i ] = - 1 ; setSum [ i ] = arr [ i - 1 ] ; } currMax . push ( 0 ) ; for ( let i = N - 1 ; i > 0 ; i -- ) { if ( parent [ queries [ i ] ] == - 1 ) { parent [ queries [ i ] ] = queries [ i ] ; } if ( queries [ i ] - 1 >= 0 && parent [ queries [ i ] - 1 ] != - 1 ) { Union ( parent , rank , setSum , queries [ i ] , queries [ i ] - 1 ) ; } if ( queries [ i ] + 1 <= N && parent [ queries [ i ] + 1 ] != - 1 ) { Union ( parent , rank , setSum , queries [ i ] , queries [ i ] + 1 ) ; } maxAns = Math . max ( setSum [ queries [ i ] ] , maxAns ) ; currMax . push ( maxAns ) ; } for ( let i = currMax . length - 1 ; i >= 0 ; i -- ) { document . write ( ` ${ currMax [ i ] } ` ) ; } } let arr = [ 1 , 3 , 2 , 5 ] ; let queries = [ 3 , 4 , 1 , 2 ] ; let N = arr . length ; maxValues ( arr , queries , N ) ;

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( key ) { this . child = [ ] ; this . val = key ; } } function newNode ( key ) { let temp = new Node ( key ) ; return temp ; } function zigzagLevelOrder ( root ) { if ( root == null ) return ; let result = [ ] ; let q = [ ] ; q . push ( root ) ; while ( q . length > 0 ) { let size = q . length ; let curLevel = [ ] ; for ( let i = 0 ; i < size ; i ++ ) { let node = q [ 0 ] ; q . shift ( ) ; curLevel . push ( node . val ) ; for ( let j = 0 ; j < ( node . child ) . length ; j ++ ) q . push ( node . child [ j ] ) ; } result . push ( curLevel ) ; } for ( let i = 0 ; i < result . length ; i ++ ) { if ( ( i + 1 ) % 2 == 0 ) { result [ i ] . reverse ( ) ; } for ( let j = 0 ; j < result [ i ] . length ; j ++ ) document . write ( result [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let root = newNode ( 1 ) ; ( root . child ) . push ( newNode ( 2 ) ) ; ( root . child ) . push ( newNode ( 3 ) ) ; ( root . child [ 0 ] . child ) . push ( newNode ( 4 ) ) ; ( root . child [ 0 ] . child ) . push ( newNode ( 5 ) ) ; ( root . child [ 1 ] . child ) . push ( newNode ( 6 ) ) ; ( root . child [ 1 ] ) . child . push ( newNode ( 7 ) ) ; ( root . child [ 1 ] . child ) . push ( newNode ( 8 ) ) ; zigzagLevelOrder ( root ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Node
Javascript program:
function minDisIncludingNode ( 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 q = [ ] ; q . push ( [ 0 , 0 ] ) ; dist = new Array ( n ) . fill ( 1e9 ) ; dist [ 0 ] = 0 ; while ( q . length > 0 ) { let up = q [ 0 ] ; q . pop ( ) ; let x = up [ 0 ] ; let lev = up [ 1 ] ; if ( lev > dist [ x ] ) continue ; if ( x == n - 1 ) continue ; for ( let y of g [ x ] ) { if ( dist [ y ] > lev + 1 ) { dist [ y ] = lev + 1 ; q . push ( [ y , lev + 1 ] ) ; } } } let q1 = [ ] ; q1 . push ( [ n - 1 , 0 ] ) ; let dist1 = new Array ( n ) . fill ( 1e9 ) ; dist1 [ n - 1 ] = 0 ; while ( q1 . length > 0 ) { let up = q1 [ 0 ] ; q1 . pop ( ) ; let x = up [ 0 ] ; let lev = up [ 1 ] ; if ( lev > dist1 [ x ] ) continue ; if ( x == 0 ) continue ; for ( let y of g [ x ] ) { if ( dist1 [ y ] > lev + 1 ) { dist1 [ y ] = lev + 1 ; q1 . push ( [ y , lev + 1 ] ) ; } } } for ( let i = 0 ; i < n ; i ++ ) { if ( dist [ i ] + dist1 [ i ] > 1e9 ) document . write ( - 1 + " " ) ; else document . write ( dist [ i ] + dist1 [ i ] + " " ) ; } } let n = 5 ; let m = 7 ; let edges = [ [ 1 , 2 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 2 , 5 ] , [ 4 , 3 ] , [ 4 , 5 ] , [ 1 , 5 ] , ] ; minDisIncludingNode ( n , m , edges ) ;

Index/key variables: a, b, i, x, y
Accumulator variables: i
Iterator variables: i, y
Javascript program:
function canPossibleReplacement ( N , arr ) { var S = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) S += arr [ i ] ; var P = 1 ; for ( i = 0 ; i < N ; i ++ ) { P *= i ; } for ( i = 0 ; i < N ; i ++ ) { var x = arr [ i ] ; var y = ( S - x ) / ( P / x - 1 ) ; if ( ( S - x + y ) == ( P * y ) / x ) return 1 ; } return 0 ; } var N = 3 ; var arr = [ 1 , 3 , 4 ] if ( canPossibleReplacement ( N , arr ) == 1 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: P, S, i
Iterator variables: i
Javascript program:
function checkSameDigits ( N ) { var length = ( Math . log10 ( N ) ) + 1 ; var M = ( Math . pow ( 10 , length ) - 1 ) / ( 10 - 1 ) ; M *= N % 10 ; if ( M = N ) return " " ; return " " ; } var N = 222 ; document . write ( checkSameDigits ( N ) ) ;

Accumulator variables: M
Javascript program:
let maxSumPath = 0 ; class Node { constructor ( key ) { this . child = [ ] ; this . val = key ; } } function newNode ( key ) { let temp = new Node ( key ) ; return temp ; } function DFS ( root , sum ) { if ( root . child . length == 0 ) { maxSumPath = Math . max ( maxSumPath , sum ) ; return ; } for ( let i = 0 ; i < root . child . length ; i ++ ) { DFS ( root . child [ i ] , sum + root . child [ i ] . val ) ; } } let root = newNode ( 1 ) ; ( root . child ) . push ( newNode ( 2 ) ) ; ( root . child ) . push ( newNode ( 3 ) ) ; ( root . child [ 0 ] . child ) . push ( newNode ( 4 ) ) ; ( root . child [ 1 ] . child ) . push ( newNode ( 6 ) ) ; ( root . child [ 0 ] . child ) . push ( newNode ( 5 ) ) ; ( root . child [ 1 ] ) . child . push ( newNode ( 7 ) ) ; ( root . child [ 1 ] . child ) . push ( newNode ( 8 ) ) ; DFS ( root , root . val ) ; document . write ( maxSumPath ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function countTriplets ( size , queries , arr , Q ) { let arr_even = new Array ( size + 1 ) ; let arr_odd = new Array ( size + 1 ) ; let even = 0 ; let odd = 0 ; arr_even [ 0 ] = 0 ; arr_odd [ 0 ] = 0 ; for ( let i = 0 ; i < size ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } arr_even [ i + 1 ] = even ; arr_odd [ i + 1 ] = odd ; } for ( let i = 0 ; i < queries ; i ++ ) { let l = Q [ i ] [ 0 ] , r = Q [ i ] [ 1 ] ; odd = arr_odd [ r ] - arr_odd [ l - 1 ] ; even = arr_even [ r ] - arr_even [ l - 1 ] ; let ans = ( even * ( even - 1 ) * ( even - 2 ) ) / 6 + ( odd * ( odd - 1 ) / 2 ) * even ; document . write ( ans + " " ) ; } } let N = 6 , Q = 2 ; let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let queries = [ [ 1 , 3 ] , [ 2 , 5 ] ] ; countTriplets ( N , Q , arr , queries ) ;

Index/key variables: i, r
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function maxRightmostElement ( N , k , p , arr ) { while ( k ) { for ( let i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] >= p ) { arr [ i ] = arr [ i ] - p ; arr [ i + 1 ] = arr [ i + 1 ] + p ; break ; } } k -- ; } document . write ( arr [ N - 1 ] + " " ) ; } let N = 4 , p = 2 , k = 5 , arr = [ 3 , 8 , 1 , 4 ] ; maxRightmostElement ( N , k , p , arr ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function nCr ( n , r , f ) { if ( n < r ) { return 0 ; } return f [ n ] / ( f [ r ] * f [ n - r ] ) ; } function findMean ( N , X ) { let f = new Array ( N + 1 ) . fill ( 0 ) ; f [ 0 ] = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { f [ i ] = f [ i - 1 ] * i ; } let total = nCr ( N , X , f ) ; let count = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { count += nCr ( N - i , X - 1 , f ) * i ; } let E_X = count / total ; document . write ( parseFloat ( E_X ) . toFixed ( 9 ) ) ; return 0 ; } let N = 3 , X = 2 ; findMean ( N , X ) ;

Index/key variables: i, n, r
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function pairwiseProductSum ( a , l , r ) { let sum = 0 ; for ( let j = l - 1 ; j <= r - 1 ; j ++ ) { for ( let k = j + 1 ; k <= r - 1 ; k ++ ) { sum += a [ j ] * a [ k ] ; } } document . write ( sum + " " ) ; } function updateArray ( a , p , x ) { a [ p - 1 ] = x ; } function solveQueries ( a , n , Q , query ) { for ( let i = 0 ; i < Q ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) pairwiseProductSum ( a , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else updateArray ( a , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; } } let A = [ 5 , 7 , 2 , 3 , 1 ] ; let N = A . length ; let Q = 3 ; let query = [ [ 1 , 1 , 3 ] , [ 2 , 2 , 5 ] , [ 1 , 2 , 5 ] , ] ; solveQueries ( A , N , Q , query ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
function Reduced ( a , n ) { let original_array = [ ] ; original_array = a ; while ( a . length != 2 ) { let mid = Math . floor ( a . length / 2 ) ; let mid_ele = a [ mid ] ; let start = a [ 0 ] ; a . shift ( ) ; let end = a [ a . length - 1 ] ; a . pop ( ) ; let rmd = ( start * end ) % mid_ele ; a . push ( rmd ) ; let remainder = ( a [ 0 ] * a [ 1 ] ) % n ; for ( let i = 0 ; i < original_array . length ; i ++ ) { if ( original_array [ i ] == remainder ) { return 1 ; } } } return 0 ; } let x = Reduced ( Arr , N ) ; if ( x ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
let MaxBit = 32 ; function possiblePair ( X , Y ) { let Z = Y - X ; if ( Z < 0 ) { document . write ( " " ) ; return 0 ; } for ( let k = 0 ; k < MaxBit ; k ++ ) { let bit1 = ( Z >> k ) & 1 ; let bit2 = ( Z >> k ) & 1 ; if ( bit1 && ! bit2 ) { document . write ( " " ) ; return 0 ; } } document . write ( Z + " " + X ) ; return 0 ; } let X = 7 , Y = 11 ; possiblePair ( X , Y ) ;

Accumulator variables: k
Iterator variables: k
Javascript program:
function maxFrequencySubarrayUtil ( A , N , M ) { let m = new Map ( ) ; let val = 0 ; for ( let i = 0 ; i < M ; i ++ ) { if ( m . has ( A [ i ] ) ) { m . set ( m . get ( A [ i ] ) , m . get ( A [ i ] ) + 1 ) ; } else { m . set ( A [ i ] , 1 ) ; } val = Math . max ( val , m . get ( A [ i ] ) ) ; } document . write ( val + " " ) ; for ( i = M ; i < N ; i ++ ) { if ( m . has ( A [ i - m ] ) ) m . set ( m . get ( A [ i - M ] ) , m . get ( A [ i - M ] ) - 1 ) ; if ( m . has ( A [ i ] ) ) m . set ( m . get ( A [ i ] ) , m . get ( A [ i ] ) + 1 ) ; val = 0 ; for ( let [ key , value ] of m ) { val = Math . max ( val , value ) ; } document . write ( val + " " ) ; } } let A = [ 1 , 1 , 2 , 2 , 3 , 5 ] ; let N = A . length ; let M = 4 ; maxFrequencySubarrayUtil ( A , N , M ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumPairs ( a , n ) { var freq = new Map ( ) ; var count = 0 ; for ( var i = 0 ; i < n ; ++ i ) { if ( freq . has ( a [ i ] ) ) freq . set ( a [ i ] , freq . get ( a [ i ] ) + 1 ) else freq . set ( a [ i ] , 1 ) } var pq = [ ... freq . values ( ) ] ; pq . sort ( ( a , b ) => a - b ) ; while ( pq . length > 1 ) { var freq1 = pq [ pq . length - 1 ] ; pq . pop ( ) ; var freq2 = pq [ pq . length - 1 ] ; pq . pop ( ) ; count ++ ; freq1 -- ; freq2 -- ; if ( freq1 > 0 ) pq . push ( freq1 ) ; if ( freq2 > 0 ) pq . push ( freq2 ) ; pq . sort ( ( a , b ) => a - b ) ; } return count ; } var arr = [ 4 , 2 , 4 , 1 , 4 , 3 ] ; var N = arr . length ; document . write ( maximumPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, freq1, freq2
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . left = null ; this . right = null ; this . data = val ; } } function getNewNode ( val ) { let newNode = new Node ( val ) ; return newNode ; } function buildPerfectBT_helper ( preStart , preEnd , pre ) { if ( preStart > preEnd ) return null ; let root = getNewNode ( pre [ preStart ] ) ; if ( preStart == preEnd ) return root ; let leftPreStart = preStart + 1 ; let rightPreStart = leftPreStart + parseInt ( ( preEnd - leftPreStart + 1 ) / 2 ) ; let leftPreEnd = rightPreStart - 1 ; let rightPreEnd = preEnd ; root . left = buildPerfectBT_helper ( leftPreStart , leftPreEnd , pre ) ; root . right = buildPerfectBT_helper ( rightPreStart , rightPreEnd , pre ) ; return root ; } function buildPerfectBT ( pre , size ) { return buildPerfectBT_helper ( 0 , size - 1 , pre ) ; } function printInorder ( root ) { if ( root == null ) return ; printInorder ( root . left ) ; document . write ( root . data + " " ) ; printInorder ( root . right ) ; } let pre = [ 1 , 2 , 4 , 5 , 3 , 6 , 7 ] ; let N = pre . length ; let root = buildPerfectBT ( pre , N ) ; document . write ( " " ) ; printInorder ( root ) ;

Index/key variables: preStart
Class/struct names: Node
Javascript program:
let N = 3 ; let adj = [ ] ; for ( let i = 0 ; i < N + 1 ; i ++ ) { adj . push ( [ ] ) ; } let visited ; let ans ; function addEdges ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function DFSUtil ( u , foo , foo1 , initial , finall ) { visited [ u ] = true ; if ( ( initial [ u - 1 ] ^ foo ) ^ finall [ u - 1 ] == true ) { ans += 1 ; foo ^= true ; } for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( visited [ adj [ u ] [ i ] ] == false ) DFSUtil ( adj [ u ] [ i ] , foo1 , foo , initial , finall ) ; } } function DFS ( V , initial , finall ) { ans = 0 ; visited = new Array ( V ) ; visited . fill ( false ) ; for ( let u = 1 ; u <= 1 ; u ++ ) { if ( visited [ u ] == false ) DFSUtil ( u , 0 , 0 , initial , finall ) ; } document . write ( ans ) ; } function countOperations ( N , initial , finall , Edges ) { for ( let i = 0 ; i < N - 1 ; i ++ ) { addEdges ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } DFS ( N + 1 , initial , finall ) ; } let Edges = [ [ 1 , 2 ] , [ 1 , 3 ] ] ; let initial = [ true , true , false ] ; let finall = [ false , true , true ] ; countOperations ( N , initial , finall , Edges ) ;

Index/key variables: i, u, v
Accumulator variables: ans, foo, i, u
Iterator variables: i, u
Javascript program:
function countOperations ( N , M ) { let visited = new Array ( 100001 ) ; let Q = [ ] ; Q . push ( [ N , 0 ] ) ; visited [ N ] = true ; while ( Q . length > 0 ) { let aux = Q [ 0 ] [ 0 ] ; let cont = Q [ 0 ] [ 1 ] ; Q . shift ( ) ; if ( aux == M ) return cont ; for ( let i = 2 ; i * i <= aux ; i ++ ) if ( aux % i == 0 ) { if ( aux + i <= M && ! visited [ aux + i ] ) { Q . push ( [ aux + i , cont + 1 ] ) ; visited [ aux + i ] = true ; } if ( aux + parseInt ( aux / i , 10 ) <= M && ! visited [ aux + parseInt ( aux / i , 10 ) ] ) { Q . push ( [ aux + parseInt ( aux / i , 10 ) , cont + 1 ] ) ; visited [ aux + parseInt ( aux / i , 10 ) ] = true ; } } } return - 1 ; } let N = 4 , M = 24 ; document . write ( countOperations ( N , M ) ) ;

Index/key variables: N
Accumulator variables: i
Iterator variables: i
Javascript program:
let adj ; let visited ; let num ; function dfs ( v ) { visited [ v ] = true ; num ++ ; for ( let i = 0 ; i < adj [ v ] . length ; i ++ ) { if ( ! visited [ adj [ v ] [ i ] ] ) { dfs ( adj [ v ] [ i ] ) ; } } } function numberOfPairs ( N , arr ) { adj = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { adj . push ( [ ] ) ; } for ( let i = 0 ; i < arr . length ; i ++ ) { adj [ arr [ i ] [ 0 ] ] . push ( arr [ i ] [ 1 ] ) ; adj [ arr [ i ] [ 1 ] ] . push ( arr [ i ] [ 0 ] ) ; } visited = new Array ( N ) ; visited . fill ( false ) ; let v = [ ] ; num = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! visited [ i ] ) { dfs ( i ) ; v . push ( num ) ; num = 0 ; } } let ans = N * ( N - 1 ) / 2 ; for ( let i = 0 ; i < v . length ; i ++ ) { ans -= ( v [ i ] * ( v [ i ] - 1 ) / 2 ) ; } document . write ( ans ) ; } let N = 6 ; let arr = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 2 , 5 ] ] ; numberOfPairs ( N , arr ) ;

Index/key variables: i, v
Accumulator variables: ans, i, num
Iterator variables: i