dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxLen ( arr ) { let hM = new Map ( ) ; let sum = 0 ; let max_len = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ; if ( sum == 0 ) max_len = i + 1 ; let prev_i = hM . get ( sum ) ; if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ; else hM . set ( sum , i ) ; } return max_len ; } let arr = [ 15 , - 2 , 2 , - 8 , 1 , 7 , 10 , 23 ] ; document . write ( " " + maxLen ( arr ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function printAlter ( arr , N ) { for ( var currIndex = 0 ; currIndex < N ; currIndex += 2 ) { document . write ( arr [ currIndex ] + " " ) ; } } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var N = 5 ; printAlter ( arr , N ) ;

Index/key variables: currIndex
Accumulator variables: currIndex
Iterator variables: currIndex
Javascript program:
function longestSubsequence ( a , n ) { var mp = new Map ( ) ; var dp = Array ( n ) . fill ( 0 ) ; var maximum = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { if ( mp . has ( a [ i ] - 1 ) ) { var lastIndex = mp . get ( a [ i ] - 1 ) - 1 ; dp [ i ] = 1 + dp [ lastIndex ] ; } else dp [ i ] = 1 ; mp . set ( a [ i ] , i + 1 ) ; maximum = Math . max ( maximum , dp [ i ] ) ; } return maximum ; } var a = [ 3 , 10 , 3 , 11 , 4 , 5 , 6 , 7 , 8 , 12 ] ; var n = a . length ; document . write ( longestSubsequence ( a , n ) ) ;

Index/key variables: i, lastIndex
Accumulator variables: i
Iterator variables: i
Javascript program:
function longLenSub ( arr , n ) { let um = new Map ( ) ; let longLen = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let len = 0 ; if ( um . has ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ; if ( um . has ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ; um . set ( arr [ i ] , len + 1 ) ; if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ; } return longLen ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 3 , 2 ] ; let n = arr . length ; document . write ( " " + longLenSub ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxn = 1e6 + 5 ; let BITree = new Array ( maxn ) ; BITree . fill ( 0 ) ; function is_prime ( n ) { if ( n <= 1 ) return false ; for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function update_bitree ( BITree , index , value ) { while ( index <= maxn ) { BITree [ index ] += value ; index += ( index & ( - index ) ) ; } } function sum_bitree ( BITree , index ) { let s = 0 ; while ( index > 0 ) { s += BITree [ index ] ; index -= ( index & ( - index ) ) ; } return s ; } function countSmallerPrimes ( BITree , ar , N ) { let ans = new Array ( N ) ; for ( let i = N - 1 ; i >= 0 ; i -- ) { ans [ i ] = sum_bitree ( BITree , ar [ i ] ) ; if ( is_prime ( ar [ i ] ) ) update_bitree ( BITree , ar [ i ] , 1 ) ; } for ( let i = 0 ; i < N ; i ++ ) document . write ( ans [ i ] + " " ) ; } let ar = [ 5 , 5 , 17 , 9 , 12 , 15 , 11 , 7 , 39 , 3 ] ; let N = ar . length ; countSmallerPrimes ( BITree , ar , N ) ;

Index/key variables: i, index
Accumulator variables: i, index, s
Iterator variables: i
Javascript program:
function countWindowDistinct ( win , k ) { let dist_count = 0 ; for ( let i = 0 ; i < k ; i ++ ) { let j ; for ( j = 0 ; j < i ; j ++ ) if ( win [ i ] == win [ j ] ) break ; if ( j == i ) dist_count ++ ; } return dist_count ; } function countDistinct ( arr , n , k ) { for ( let i = 0 ; i <= n - k ; i ++ ) document . write ( countWindowDistinct ( arr . slice ( i , arr . length ) , k ) + " " ) ; } let arr = [ 1 , 2 , 1 , 3 , 4 , 2 , 3 ] , k = 4 ; countDistinct ( arr , arr . length , k ) ;

Index/key variables: i, j
Accumulator variables: dist_count, i, j
Iterator variables: i, j
Javascript program:
function maximumSum ( a , b , n , index , lastpicked , dp ) { if ( index == n ) return 0 ; if ( dp [ index ] [ lastpicked + 1 ] != - 1 ) return dp [ index ] [ lastpicked + 1 ] ; let option1 = 0 , option2 = 0 ; if ( lastpicked == - 1 a [ lastpicked ] != a [ index ] ) { option1 = b [ index ] + maximumSum ( a , b , n , index + 1 , index , dp ) ; } option2 = maximumSum ( a , b , n , index + 1 , lastpicked , dp ) ; return dp [ index ] [ lastpicked + 1 ] = Math . max ( option1 , option2 ) ; } function maximumPolets ( arr , brr , n ) { let index = 0 , lastPicked = - 1 ; let dp = new Array ( n + 5 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < dp . length ; i ++ ) { for ( var j = 0 ; j < dp . length ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( maximumSum ( arr , brr , n , index , lastPicked , dp ) ) ; } let arr = [ 1 , 2 , 3 , 3 , 3 , 1 ] ; let brr = [ - 1 , 2 , 10 , 20 , - 10 , - 9 ] ; let N = arr . length ; maximumPolets ( arr , brr , N ) ;

Index/key variables: i, index, j, lastpicked
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( key ) { this . left = null ; this . right = null ; this . key = key ; } } function newNode ( key ) { let temp = new Node ( key ) ; return ( temp ) ; } function calculateMin ( root , levelMin ) { let qt = [ ] ; qt . push ( root ) ; let count = 1 ; let min_v = Number . MAX_VALUE ; while ( qt . length > 0 ) { let temp = qt [ 0 ] ; min_v = Math . min ( min_v , temp . key ) ; qt . shift ( ) ; if ( temp . left != null ) { qt . push ( temp . left ) ; } if ( temp . right != null ) { qt . push ( temp . right ) ; } count -- ; if ( count == 0 ) { levelMin . push ( min_v ) ; min_v = Number . MAX_VALUE ; count = qt . length ; } } } function findNodes ( root , levelMin , levelResult , level ) { if ( root == null ) return ; findNodes ( root . left , levelMin , levelResult , level + 1 ) ; findNodes ( root . right , levelMin , levelResult , level + 1 ) ; for ( let i = 0 ; i < level ; i ++ ) { if ( root . key <= levelMin [ i ] ) { levelResult [ i ] += 1 ; } } } function printNodes ( root ) { let levelMin = [ ] ; calculateMin ( root , levelMin ) ; let numLevels = levelMin . length ; let levelResult = new Array ( numLevels ) ; levelResult . fill ( 0 ) ; findNodes ( root , levelMin , levelResult , 0 ) ; for ( let i = 0 ; i < levelResult . length ; i ++ ) { document . write ( levelResult [ i ] + " " ) ; } } let root = newNode ( 4 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 5 ) ; root . right . left = newNode ( 3 ) ; root . right . right = newNode ( 1 ) ; root . left . left = newNode ( 10 ) ; root . left . right = newNode ( 2 ) ; printNodes ( root ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Node
Javascript program:
function countSubArray ( arr , n ) { if ( n < 2 ) return n ; let i = max_element ( arr ) ; let j = min_element ( arr ) ; if ( i > j ) { let tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; } return ( i + 1 ) * ( n - j ) ; } function max_element ( arr ) { let idx = 0 ; let max = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { if ( max < arr [ i ] ) { max = arr [ i ] ; idx = i ; } } return idx ; } function min_element ( arr ) { let idx = 0 ; let min = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { if ( arr [ i ] < min ) { min = arr [ i ] ; idx = i ; } } return idx ; } let arr = [ 4 , 1 , 2 , 3 ] ; let n = arr . length ; document . write ( countSubArray ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( item ) { this . left = null ; this . right = null ; this . data = item ; } } let root ; class GFG { } let result ; function dfs ( root , distance ) { if ( root == null ) { let arr = new Array ( distance + 1 ) ; arr . fill ( 0 ) ; return arr ; } if ( root . left == null && root . right == null ) { let res = new Array ( distance + 1 ) ; res . fill ( 0 ) ; res [ 1 ] ++ ; return res ; } let left = dfs ( root . left , distance ) ; let right = dfs ( root . right , distance ) ; let res = new Array ( distance + 1 ) ; res . fill ( 0 ) ; for ( let i = res . length - 2 ; i >= 1 ; i -- ) { res [ i + 1 ] = left [ i ] + right [ i ] ; } for ( let l = 1 ; l < left . length ; l ++ ) { for ( let r = 0 ; r < right . length ; r ++ ) { if ( l + r <= distance ) { result += left [ l ] * right [ r ] ; } } } return res ; } let tree = new GFG ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; result = 0 ; let K = 3 ; dfs ( tree . root , K ) ; document . write ( result ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r, result
Iterator variables: i, l, r
Class/struct names: GFG, Node
Javascript program:
function maxAbsDiffLevelSum ( N , M , cost , Edges ) { let adj = new Array ( N ) ; for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; for ( let i = 0 ; i < M ; i ++ ) { let u = Edges [ i ] [ 0 ] ; let v = Edges [ i ] [ 1 ] ; adj [ u ] . push ( v ) ; } let maxSum = cost [ 0 ] , minSum = cost [ 0 ] ; let q = [ ] ; q . push ( 0 ) ; while ( q . length != 0 ) { let count = q . length ; let sum = 0 ; while ( count -- > 0 ) { let temp = q [ 0 ] ; q . shift ( ) ; sum = sum + cost [ temp ] ; for ( let i = 0 ; i < adj [ temp ] . length ; i ++ ) { q . push ( adj [ temp ] [ i ] ) ; } } maxSum = Math . max ( sum , maxSum ) ; minSum = Math . min ( sum , minSum ) ; } document . write ( Math . abs ( maxSum - minSum ) ) ; } let N = 10 , M = 9 ; let Edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 0 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 3 , 6 ] , [ 6 , 7 ] , [ 6 , 8 ] , [ 6 , 9 ] ] ; let cost = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 ] ; maxAbsDiffLevelSum ( N , M , cost , Edges ) ;

Index/key variables: i, temp, u
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findMinCost ( a , k ) { var n = a . length ; var max_ele = a . reduce ( ( a , b ) => Math . max ( a , b ) ) var dp = Array ( n + 1 ) . fill ( 1000000000 ) ; dp [ 0 ] = 0 ; for ( var i = 0 ; i < n ; ++ i ) { var freq = Array ( max_ele + 1 ) . fill ( 0 ) ; for ( var j = i ; j < n ; ++ j ) { freq [ a [ j ] ] ++ ; var cost = 0 ; for ( var x = 0 ; x <= max_ele ; ++ x ) { cost += ( freq [ x ] == 1 ) ? 0 : freq [ x ] ; } dp [ j + 1 ] = Math . min ( dp [ i ] + cost + k , dp [ j + 1 ] ) ; } } return dp [ n ] ; } var arr = [ 1 , 2 , 1 , 1 , 1 ] ; var K = 2 ; document . write ( findMinCost ( arr , K ) ) ;

Index/key variables: i, j, n, x
Accumulator variables: cost
Iterator variables: i, j, x
Javascript program:
function subArraySum ( arr , n , sum ) { let cur_sum = 0 ; let start = 0 ; let end = - 1 ; let hashMap = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { cur_sum = cur_sum + arr [ i ] ; if ( cur_sum - sum == 0 ) { start = 0 ; end = i ; break ; } if ( hashMap . has ( cur_sum - sum ) ) { start = hashMap . get ( cur_sum - sum ) + 1 ; end = i ; break ; } hashMap . set ( cur_sum , i ) ; } if ( end == - 1 ) { document . write ( " " ) ; } else { document . write ( " " + start + " " + end ) ; } } let arr = [ 10 , 2 , - 2 , - 20 , 10 ] ; let n = arr . length ; let sum = - 10 ; subArraySum ( arr , n , sum ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxn = 100005 ; let BITree = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { BITree [ i ] = new Array ( maxn ) ; for ( let j = 0 ; j < maxn ; j ++ ) { BITree [ i ] [ j ] = 0 ; } } let N ; function update_BITree ( index , C , val ) { while ( index <= N ) { BITree [ C . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ index ] += val ; index += ( index & - index ) ; } } function sum_BITree ( index , C ) { let s = 0 ; while ( index > 0 ) { s += BITree [ C . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ index ] ; index -= ( index & - index ) ; } return s ; } function buildTree ( str ) { for ( let i = 1 ; i <= N ; i ++ ) { update_BITree ( i , str [ i ] , 1 ) ; } document . write ( " " ) ; } function printCharacter ( str , l , r , k ) { let count = 0 ; let ans = 0 ; for ( let C = ' ' . charCodeAt ( 0 ) ; C >= ' ' . charCodeAt ( 0 ) ; C -- ) { let times = sum_BITree ( r , String . fromCharCode ( C ) ) - sum_BITree ( l - 1 , String . fromCharCode ( C ) ) ; count += times ; if ( count >= k ) { ans = String . fromCharCode ( C ) ; break ; } } return ans ; } function updateTree ( str , pos , s ) { let index = pos ; update_BITree ( index , str [ index ] , - 1 ) ; str = str . substring ( 0 , index ) + s + str . substring ( index + 1 ) ; update_BITree ( index , s , 1 ) ; } let str = " " ; N = str . length ; str = ' ' + str ; let Q = 3 ; buildTree ( str ) ; document . write ( printCharacter ( str , 1 , 2 , 2 ) + " " ) ; updateTree ( str , 4 , ' ' ) ; document . write ( printCharacter ( str , 1 , 5 , 4 ) + " " ) ;

Index/key variables: i, index, j
Accumulator variables: C, count, i, index, j, s
Iterator variables: C, i, j
Javascript program:
let vec = new Array ( 100001 ) ; let vis = new Array ( 100001 ) ; vis . fill ( false ) ; let cc = 1 ; function dfs ( node ) { vis [ node ] = true ; for ( let x = 0 ; x < vec [ node ] . length ; x ++ ) { if ( ! vis [ vec [ node ] [ x ] ] ) { cc ++ ; dfs ( vec [ node ] [ x ] ) ; } } } function addEdge ( u , v ) { vec [ u ] . push ( v ) ; vec [ v ] . push ( u ) ; } function minEdgeRemoved ( N , M , Edges ) { for ( let i = 0 ; i < M ; i ++ ) { addEdge ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } let k = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( ! vis [ i ] ) { cc = 1 ; dfs ( i ) ; k ++ ; } } document . write ( ( M - N + k ) + " " ) ; } let N = 3 , M = 2 ; let Edges = [ [ 1 , 2 ] , [ 2 , 3 ] ] ; for ( let i = 0 ; i < vec . length ; i ++ ) vec [ i ] = [ ] ; minEdgeRemoved ( N , M , Edges ) ;

Index/key variables: i, node, u, v, x
Accumulator variables: cc, i, k, x
Iterator variables: i, x
Javascript program:
let pairFound = false ; class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function pairSum ( root , target , S ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( S . has ( target - root . data ) ) { document . write ( target - root . data + " " + root . data ) ; pairFound = true ; return ; } else S . add ( root . data ) ; } pairSum ( root . left , target , S ) ; pairSum ( root . right , target , S ) ; } let root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; let S = new Set ( ) ; let K = 13 ; pairSum ( root , K , S ) ; if ( pairFound == false ) document . write ( " " ) ;

Boolean variables: pairFound
Class/struct names: Node
Javascript program:
function countRooks ( n , k , pos ) { let row = new Array ( n ) . fill ( 0 ) ; let col = new Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { row [ i ] = 0 ; col [ i ] = 0 ; } for ( let i = 0 ; i < k ; i ++ ) { row [ pos [ i ] [ 0 ] - 1 ] = 1 ; col [ pos [ i ] [ 1 ] - 1 ] = 1 ; } let res = n - k ; document . write ( res + " " + " " ) ; let ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } document . write ( ( ri + 1 ) + " " + ( ci + 1 ) + " " + " " ) ; ri ++ ; ci ++ ; } } let N = 4 ; let K = 2 ; let pos = [ [ 1 , 4 ] , [ 2 , 2 ] ] ; countRooks ( N , K , pos ) ;

Index/key variables: ci, i, ri
Accumulator variables: ci, i, res, ri
Iterator variables: i
Javascript program:
function minInsertion ( str ) { let n = str . length ; let res = 0 ; let count = new Array ( 26 ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] % 2 == 1 ) res ++ ; } return ( res == 0 ) ? 0 : res - 1 ; } let str = " " ; document . write ( minInsertion ( str ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function check ( ans , s , n , m ) { for ( var i = 1 ; i < n ; ++ i ) { var count = 0 ; for ( var j = 0 ; j < m ; ++ j ) { if ( ans [ j ] !== s [ i ] [ j ] ) count ++ ; } if ( count > 1 ) return false ; } return true ; } function findString ( s ) { var n = s . length ; var ans = s [ 0 ] ; var m = ans . length ; var flag = 0 ; for ( var i = 0 ; i < m ; ++ i ) { for ( var j = 0 ; j < 26 ; ++ j ) { var x = ans ; x = x . replace ( x [ i ] , String . fromCharCode ( j + " " . charCodeAt ( 0 ) ) ) ; if ( check ( x , s , n , m ) ) { ans = x ; flag = 1 ; break ; } } if ( flag === 1 ) break ; } if ( flag === 0 ) return " " ; else return ans ; } var s = [ " " , " " ] ; document . write ( findString ( s ) ) ;

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Javascript program:
function getMinOps ( arr ) { let ans = 0 ; for ( let i = 0 ; i < arr . length - 1 ; i ++ ) { ans += Math . max ( arr [ i ] - arr [ i + 1 ] , 0 ) ; } return ans ; } let arr = [ 1 , 3 , 1 , 2 , 4 ] ; document . write ( getMinOps ( arr ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function maxdiff ( arr , n ) { let freq = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) freq . set ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ; else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ; } } return ans ; } let arr = [ 3 , 1 , 3 , 2 , 3 , 2 ] ; let n = arr . length ; document . write ( maxdiff ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findDiff ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; let count = 0 , max_count = 0 , min_count = n ; for ( let i = 0 ; i < ( n - 1 ) ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { count += 1 ; continue ; } else { max_count = Math . max ( max_count , count ) ; min_count = Math . min ( min_count , count ) ; count = 0 ; } } return ( max_count - min_count ) ; } let arr = [ 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 ] ; let n = arr . length ; document . write ( findDiff ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function min_operations ( A ) { if ( A . length == 0 ) return 0 ; let ans = A [ 0 ] ; for ( let i = 1 ; i < A . length ; i ++ ) { ans += Math . max ( A [ i ] - A [ i - 1 ] , 0 ) ; } return ans ; } let A = [ 1 , 2 , 3 , 2 , 1 ] ; document . write ( min_operations ( A ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let MAX_NODES = 100005 ; let parent = new Array ( MAX_NODES ) ; let size_set = new Array ( MAX_NODES ) ; function make_set ( v ) { parent [ v ] = v ; size_set [ v ] = 1 ; } function find_set ( v ) { if ( v == parent [ v ] ) return v ; return parent [ v ] = find_set ( parent [ v ] ) ; } function union_set ( a , b ) { a = find_set ( a ) ; b = find_set ( b ) ; if ( a != b ) { if ( size_set [ a ] < size_set [ b ] ) { let temp = a ; a = b ; b = temp ; } parent [ b ] = a ; size_set [ a ] += size_set [ b ] ; } } function check ( a , b ) { a = find_set ( a ) ; b = find_set ( b ) ; return ( a == b ) ? " " : " " ; } let n = 5 , m = 3 ; make_set ( 1 ) ; make_set ( 2 ) ; make_set ( 3 ) ; make_set ( 4 ) ; make_set ( 5 ) ; union_set ( 1 , 3 ) ; union_set ( 3 , 4 ) ; union_set ( 3 , 5 ) ; let q = 3 ; document . write ( check ( 1 , 5 ) + " " ) ; document . write ( check ( 3 , 2 ) + " " ) ; document . write ( check ( 5 , 2 ) + " " ) ;

Index/key variables: a, b, v
Javascript program:
function count ( N , A , B ) { if ( N == 1 ) { return 9 / B + 1 ; } let max_sum = 9 * N ; let odd_count = N / 2 + N % 2 ; let even_count = N - odd_count ; let dp = new Array ( even_count ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < even_count ; i ++ ) { for ( var j = 0 ; j < max_sum + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= 9 ; i ++ ) dp [ 0 ] [ i % A ] ++ ; for ( let i = 1 ; i < even_count ; i ++ ) { for ( let j = 0 ; j <= 9 ; j ++ ) { for ( let k = 0 ; k <= max_sum ; k ++ ) { if ( dp [ i - 1 ] [ k ] > 0 ) dp [ i ] [ ( j + k ) % A ] += dp [ i - 1 ] [ k ] ; } } } let dp1 = new Array ( odd_count ) ; for ( var i = 0 ; i < dp1 . length ; i ++ ) { dp1 [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < odd_count ; i ++ ) { for ( var j = 0 ; j < max_sum + 1 ; j ++ ) { dp1 [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= 9 ; i ++ ) dp1 [ 0 ] [ i % B ] ++ ; for ( let i = 1 ; i < odd_count ; i ++ ) { for ( let j = 0 ; j <= 9 ; j ++ ) { for ( let k = 0 ; k <= max_sum ; k ++ ) { if ( dp1 [ i - 1 ] [ k ] > 0 ) dp1 [ i ] [ ( j + k ) % B ] += dp1 [ i - 1 ] [ k ] ; } } } return dp [ even_count - 1 ] [ 0 ] * dp1 [ odd_count - 1 ] [ 0 ] ; } let N = 2 , A = 2 , B = 5 ; document . write ( count ( N , A , B ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function maxDiff ( arr , n ) { let SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( let i = 0 ; i <= n - 1 ; i ++ ) { let isSingleOccurance = true ; for ( let j = i + 1 ; j <= n - 1 ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { isSingleOccurance = false ; arr [ i ] = arr [ j ] = 0 ; break ; } } if ( isSingleOccurance ) { if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ; else SubsetSum_2 += arr [ i ] ; } } return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ; } let arr = [ 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 ] ; let n = arr . length ; document . write ( " " + maxDiff ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: SubsetSum_1, SubsetSum_2, i, j
Iterator variables: i, j
Boolean variables: isSingleOccurance
Javascript program:
let NN = 3e5 ; let G = new Array ( NN + 1 ) ; function dfs ( node , A , subtree_size , visited , check_subtree ) { visited [ node ] = 1 ; subtree_size [ node ] = 1 ; if ( node == A ) { check_subtree [ node ] = 1 ; } else check_subtree [ node ] = 0 ; for ( let v = 0 ; v < G [ node ] . length ; v ++ ) { if ( visited [ G [ node ] [ v ] ] == 0 ) { subtree_size [ node ] += dfs ( G [ node ] [ v ] , A , subtree_size , visited , check_subtree ) ; check_subtree [ node ] = check_subtree [ node ] | check_subtree [ G [ node ] [ v ] ] ; } } return subtree_size [ node ] ; } function addedge ( node1 , node2 ) { G [ node1 ] . push ( node2 ) ; G [ node2 ] . push ( node1 ) ; } function numberOfPairs ( N , B , A ) { let subtree_size = new Array ( N + 1 ) ; subtree_size . fill ( 0 ) ; let visited = new Array ( N + 1 ) ; visited . fill ( 0 ) ; let check_subtree = new Array ( N + 1 ) ; check_subtree . fill ( 0 ) ; dfs ( B , A , subtree_size , visited , check_subtree ) ; let difference = 0 ; for ( let v = 0 ; v < G [ B ] . length ; v ++ ) { if ( check_subtree [ G [ B ] [ v ] ] > 0 ) { difference = N - subtree_size [ G [ B ] [ v ] ] ; break ; } } return ( N * ( N - 1 ) ) - difference * ( subtree_size [ A ] ) ; } let N = 9 ; let X = 5 , Y = 3 ; for ( let i = 0 ; i < G . length ; i ++ ) G [ i ] = [ ] ; addedge ( 0 , 2 ) ; addedge ( 1 , 2 ) ; addedge ( 2 , 3 ) ; addedge ( 3 , 4 ) ; addedge ( 4 , 6 ) ; addedge ( 4 , 5 ) ; addedge ( 5 , 7 ) ; addedge ( 5 , 8 ) ; document . write ( numberOfPairs ( N , Y , X ) ) ;

Index/key variables: A, B, i, node, node1, node2, v
Accumulator variables: i, v
Iterator variables: i, v
Javascript program:
function equalXORandOR ( n ) { var m = 0 ; var MSB = parseInt ( Math . log ( n ) ) ; for ( i = 0 ; i <= MSB ; i ++ ) { if ( ( n & ( 1 << i ) ) <= 0 ) { m += ( 1 << i ) ; } } return m ; } var n = 14 ; document . write ( equalXORandOR ( n ) ) ;

Accumulator variables: i, m
Iterator variables: i