dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . left = null ; this . right = null ; } } ; function newNode ( data ) { var newNode = new Node ; newNode . data = data ; newNode . left = newNode . right = null ; return ( newNode ) ; } function Solve ( root , xr , max_xor ) { xr = xr ^ root . data ; if ( root . left == null && root . right == null ) { max_xor = Math . max ( max_xor , xr ) ; return max_xor ; } if ( root . left != null ) { max_xor = Solve ( root . left , xr , max_xor ) ; } if ( root . right != null ) { max_xor = Solve ( root . right , xr , max_xor ) ; } return max_xor ; } function findMaxXor ( root ) { var xr = 0 , max_xor = 0 ; max_xor = Solve ( root , xr , max_xor ) ; return max_xor ; } var root = newNode ( 2 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 4 ) ; root . left . left = newNode ( 10 ) ; root . left . right = newNode ( 8 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 10 ) ; document . write ( findMaxXor ( root ) ) ;

Class/struct names: Node
Javascript program:
function constructXORArray ( A , n , K ) { let B = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) B [ i ] = A [ i ] ^ K ; for ( let i = 0 ; i < n ; i ++ ) document . write ( B [ i ] + " " ) ; document . write ( " " ) } let A = [ 2 , 4 , 1 , 3 , 5 ] ; let K = 5 ; let n = A . length ; constructXORArray ( A , n , K ) ; let B = [ 4 , 75 , 45 , 42 ] ; K = 2 ; n = B . length ; constructXORArray ( B , n , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function find_and ( arr ) { let ans = arr [ 0 ] ; for ( let i = 0 ; i < arr . length ; i ++ ) { ans = ( ans & arr [ i ] ) ; } return ans ; } let arr = [ 1 , 3 , 5 , 9 , 11 ] ; document . write ( find_and ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var maxsize = 100005 ; var xor_tree = Array ( maxsize ) ; function construct_Xor_Tree_Util ( current , start , end , x ) { if ( start == end ) { xor_tree [ x ] = current [ start ] ; return ; } var left = x * 2 + 1 ; var right = x * 2 + 2 ; var mid = start + parseInt ( ( end - start ) / 2 ) ; construct_Xor_Tree_Util ( current , start , mid , left ) ; construct_Xor_Tree_Util ( current , mid + 1 , end , right ) ; xor_tree [ x ] = ( xor_tree [ left ] ^ xor_tree [ right ] ) ; } function construct_Xor_Tree ( arr , n ) { construct_Xor_Tree_Util ( arr , 0 , n - 1 , 0 ) ; } var leaf_nodes = [ 40 , 32 , 12 , 1 , 4 , 3 , 2 , 7 ] ; var n = leaf_nodes . length ; construct_Xor_Tree ( leaf_nodes , n ) ; var x = ( Math . ceil ( Math . log2 ( n ) ) ) ; var max_size = 2 * Math . pow ( 2 , x ) - 1 ; document . write ( " " ) ; for ( var i = 0 ; i < max_size ; i ++ ) { document . write ( xor_tree [ i ] + " " ) ; } var root = 0 ; document . write ( " " + xor_tree [ root ] ) ;

Index/key variables: i, left, right, root, start, x
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( arr , n , m , d ) { var i = 0 ; while ( i < n && m > 0 ) { m -- ; i += d ; } return m == 0 ? true : false ; } function maximumDistance ( arr , n , m ) { var low = 1 , high = n - 1 ; var ans = 0 ; while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; var flag = check ( arr , n , m , mid ) ; if ( flag ) { ans = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } return ans ; } var n = 5 , m = 3 ; var arr = new Array ( n ) ; arr . fill ( 0 ) ; document . write ( maximumDistance ( arr , n , m ) ) ;

Accumulator variables: i, m
Javascript program:
function maximumXor ( arr , n ) { let sForward = [ ] ; let sBackward = [ ] ; let ans = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { while ( sForward . length != 0 && arr [ i ] < arr [ sForward [ sForward . length - 1 ] ] ) { ans = Math . max ( ans , arr [ i ] ^ arr [ sForward [ sForward . length - 1 ] ] ) ; sForward . pop ( ) ; } sForward . push ( i ) ; while ( sBackward . length != 0 && arr [ n - i - 1 ] < arr [ sBackward [ sBackward . length - 1 ] ] ) { ans = Math . max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward [ sBackward . length - 1 ] ] ) ; sBackward . pop ( ) ; } sBackward . push ( n - i - 1 ) ; } return ans ; } let arr = [ 8 , 1 , 2 ] ; let n = arr . length ; document . write ( maximumXor ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minTrees ( n ) { let count = 0 ; while ( n > 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } let n = 7 ; document . write ( minTrees ( n ) ) ;

Accumulator variables: count, n
Javascript program:
function getMinSteps ( K ) { return countSetBits ( K ) ; } function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let n = 343 ; document . write ( getMinSteps ( n ) ) ;

Accumulator variables: setBits
Javascript program:
function isDefeat ( s1 , s2 , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) ) continue ; else if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) ) continue ; else { return true ; } } return false ; } let s1 = ( " " ) ; let s2 = ( " " ) ; let n = 10 ; if ( isDefeat ( s1 , s2 , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var N = 3 , M = 3 ; function check ( a , b ) { for ( i = 1 ; i < N ; i ++ ) { for ( j = 1 ; j < M ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) { a [ i ] [ j ] ^= 1 ; a [ 0 ] [ 0 ] ^= 1 ; a [ 0 ] [ j ] ^= 1 ; a [ i ] [ 0 ] ^= 1 ; } } } for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) return false ; } } return true ; } var a = [ [ 0 , 1 , 0 ] , [ 0 , 1 , 0 ] , [ 1 , 0 , 0 ] ] ; var b = [ [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] ] ; if ( check ( a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function FindIndexKthBit ( n , k ) { let cnt = 0 ; let ind = 0 ; while ( n > 0 ) { if ( n & 1 > 0 ) cnt ++ ; if ( cnt == k ) return ind ; ind ++ ; n = n >> 1 ; } return - 1 ; } let n = 15 , k = 3 ; let ans = FindIndexKthBit ( n , k ) ; if ( ans != - 1 ) document . write ( ans ) ; else document . write ( " " ) ;

Accumulator variables: cnt, ind
Javascript program:
function hasEqualBlockFrequency ( N ) { let S = N . toString ( 2 ) ; let p = new Set ( ) ; let c = 1 ; for ( let i = 0 ; i < S . length - 1 ; i ++ ) { if ( S [ i ] == S [ i + 1 ] ) c += 1 ; else { p . add ( c ) ; c = 1 ; } p . add ( c ) ; } if ( p . size == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 5 ; hasEqualBlockFrequency ( N ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function printMaxAfterRemoval ( s ) { let flag = false ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' && flag == false ) { flag = true ; continue ; } else document . write ( s [ i ] ) ; } return 0 ; } let s = " " ; printMaxAfterRemoval ( s ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function countOddPair ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( ! ( A [ i ] & 1 ) ) count ++ ; let evenPairCount = parseInt ( count * ( count - 1 ) / 2 ) ; let totPairs = parseInt ( N * ( N - 1 ) / 2 ) ; return totPairs - evenPairCount ; } let A = [ 5 , 6 , 2 , 8 ] ; let N = A . length ; document . write ( countOddPair ( A , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function ReplaceElements ( arr , n ) { if ( n <= 1 ) return ; let prev = arr [ 0 ] ; arr [ 0 ] = arr [ 0 ] ^ arr [ 1 ] ; for ( let i = 1 ; i < n - 1 ; i ++ ) { let curr = arr [ i ] ; arr [ i ] = prev ^ arr [ i + 1 ] ; prev = curr ; } arr [ n - 1 ] = prev ^ arr [ n - 1 ] ; } let arr = [ 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; ReplaceElements ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function luckiest_person ( n ) { let len = parseInt ( Math . log ( n ) / Math . log ( 2 ) ) + 1 ; let n2 = n ; for ( let i = 0 ; i < len ; i ++ ) { n2 = n2 ^ ( 1 << i ) ; } return Math . abs ( n - n2 ) ; } let N = 3 ; let lucky_p = luckiest_person ( N ) ; document . write ( lucky_p ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function maxTriplet ( a , n ) { let f = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { f [ i ] = true ; } let bits = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { bits [ i ] = new Array ( 33 ) ; for ( let j = 0 ; j < 33 ; j ++ ) { bits [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; ++ i ) { let num = a [ i ] ; let j = 32 ; while ( num > 0 ) { if ( num % 2 == 1 ) { bits [ i ] [ j ] = 1 ; } j -- ; num >>= 1 ; } } let ans = 0 ; for ( let i = 0 ; i <= 32 ; ++ i ) { let cnt = 0 ; for ( let j = 0 ; j < n ; ++ j ) { if ( bits [ j ] [ i ] == 1 & f [ j ] ) { cnt ++ ; } } if ( cnt >= 3 ) { ans += Math . pow ( 2 , 32 - i ) ; for ( let j = 0 ; j < n ; ++ j ) { if ( bits [ j ] [ i ] != 1 ) { f [ j ] = false ; } } } } let cnt = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( f [ i ] ) { cnt ++ ; } } let NumberOfTriplets = ( cnt * ( cnt - 1 ) * ( cnt - 2 ) ) / 6 ; document . write ( NumberOfTriplets + " " + ans ) ; } let a = [ 4 , 11 , 10 , 15 , 26 ] ; let n = a . length ; maxTriplet ( a , n ) ;

Index/key variables: i, j
Accumulator variables: ans, cnt, i, j
Iterator variables: i, j
Javascript program:
function OR ( a , n ) { var ans = a [ 0 ] ; for ( var i = 1 ; i < n ; ++ i ) ans |= a [ i ] ; return ans ; } var a = [ 1 , 4 , 6 ] ; var n = a . length ; document . write ( OR ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Javascript program:
function bit ( n ) { let count = 0 ; while ( n > 0 ) { count ++ ; n = n & ( n - 1 ) ; } return count ; } function maxSumOfBits ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = bit ( arr [ i ] ) ; } let incl = arr [ 0 ] ; let excl = 0 ; let excl_new ; for ( let i = 1 ; i < n ; i ++ ) { excl_new = ( incl > excl ) ? incl : excl ; incl = excl + arr [ i ] ; excl = excl_new ; } return ( ( incl > excl ) ? incl : excl ) ; } let arr = [ 1 , 2 , 4 , 5 , 6 , 7 , 20 , 25 ] ; let n = arr . length ; document . write ( maxSumOfBits ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findOddPair ( A , N ) { let i , count = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) count ++ ; } return count * ( N - count ) ; } let a = [ 5 , 4 , 7 , 2 , 1 ] ; let n = a . length ; document . write ( findOddPair ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function MSBPosition ( N ) { let msb_p = - 1 ; while ( N > 0 ) { N = N >> 1 ; msb_p ++ ; } return msb_p ; } function findBitwiseOR ( L , R ) { let res = 0 ; let msb_p1 = MSBPosition ( L ) ; let msb_p2 = MSBPosition ( R ) ; while ( msb_p1 == msb_p2 ) { let res_val = ( 1 << msb_p1 ) ; res += res_val ; L -= res_val ; R -= res_val ; msb_p1 = MSBPosition ( L ) ; msb_p2 = MSBPosition ( R ) ; } msb_p1 = Math . max ( msb_p1 , msb_p2 ) ; for ( let i = msb_p1 ; i >= 0 ; i -- ) { let res_val = ( 1 << i ) ; res += res_val ; } return res ; } let L = 12 , R = 18 ; document . write ( findBitwiseOR ( L , R ) ) ;

Accumulator variables: L, R, i, msb_p, res
Iterator variables: i
Javascript program:
function maxOR ( arr , n , k , x ) { let preSum = new Array ( n + 1 ) ; let suffSum = new Array ( n + 1 ) ; let res = 0 , pow = 1 ; for ( let i = 0 ; i < k ; i ++ ) pow *= x ; preSum [ 0 ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) preSum [ i + 1 ] = preSum [ i ] | arr [ i ] ; suffSum [ n ] = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) suffSum [ i ] = suffSum [ i + 1 ] | arr [ i ] ; res = 0 ; for ( let i = 0 ; i < n ; i ++ ) res = Math . max ( res , preSum [ i ] | ( arr [ i ] * pow ) suffSum [ i + 1 ] ) ; return res ; } let arr = [ 1 , 2 , 4 , 8 ] ; let n = 4 ; let k = 2 , x = 3 ; let ans = maxOR ( arr , n , k , x ) ; document . write ( ans ) ;

Index/key variables: i, n
Accumulator variables: i, pow
Iterator variables: i
Javascript program:
function minSum ( a , n ) { a . sort ( ) ; let num1 = 0 ; let num2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) num1 = num1 * 10 + a [ i ] ; else num2 = num2 * 10 + a [ i ] ; } return num2 + num1 ; } let arr = [ 5 , 3 , 0 , 7 , 4 ] ; let n = arr . length ; document . write ( " " + minSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 100010 ; let id = new Array ( N ) ; let sz = new Array ( N ) ; function Root ( idx ) { let i = idx ; while ( i != id [ i ] ) { id [ i ] = id [ id [ i ] ] ; i = id [ i ] ; } return i ; } function Union ( a , b ) { let i = Root ( a ) , j = Root ( b ) ; if ( i != j ) { if ( sz [ i ] >= sz [ j ] ) { id [ j ] = i ; sz [ i ] += sz [ j ] ; sz [ j ] = 0 ; } else { id [ i ] = j ; sz [ j ] += sz [ i ] ; sz [ i ] = 0 ; } } } function UnionUtil ( e , W , q ) { for ( let i = 0 ; i < q ; i ++ ) { let u , v ; u = e [ i ] [ 0 ] ; v = e [ i ] [ 1 ] ; u -- ; v -- ; if ( W [ u ] % 2 == 0 && W [ v ] % 2 == 0 ) Union ( u , v ) ; } } function findMax ( n , W ) { let maxi = 0 ; for ( let i = 1 ; i < n ; i ++ ) if ( W [ i ] % 2 == 0 ) maxi = Math . max ( maxi , sz [ i ] ) ; return maxi ; } let W = [ 1 , 2 , 6 , 4 , 2 , 0 , 3 ] ; let n = W . length ; for ( let i = 0 ; i < n ; i ++ ) { id [ i ] = i ; sz [ i ] = 1 ; } let e = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 4 , 6 ] , [ 6 , 7 ] ] ; let q = e . length ; UnionUtil ( e , W , q ) ; let maxi = findMax ( n , W ) ; document . write ( " " ) ; document . write ( " " + maxi ) ;

Index/key variables: i, j, u, v
Accumulator variables: i, u, v
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function countOfOddsPascal ( n ) { let c = countSetBits ( n ) ; return Math . pow ( 2 , c ) ; } let n = 20 ; document . write ( countOfOddsPascal ( n ) ) ;

Accumulator variables: count
Javascript program:
function ansQueries ( prefeven , prefodd , l , r ) { if ( ( r - l + 1 ) % 2 == 0 ) document . write ( " " ) ; else { if ( l % 2 == 0 ) document . write ( prefeven [ r ] ^ prefeven [ l - 1 ] ) ; else document . write ( prefodd [ r ] ^ prefodd [ l - 1 ] ) ; } document . write ( " " ) ; } function wrapper ( arr , n , l , r , q ) { let prefodd = [ ] ; let prefeven = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { if ( ( i ) % 2 == 0 ) { prefeven [ i ] = arr [ i - 1 ] ^ prefeven [ i - 1 ] ; prefodd [ i ] = prefodd [ i - 1 ] ; } else { prefeven [ i ] = prefeven [ i - 1 ] ; prefodd [ i ] = prefodd [ i - 1 ] ^ arr [ i - 1 ] ; } } let i = 0 ; while ( i != q ) { ansQueries ( prefeven , prefodd , l [ i ] , r [ i ] ) ; i ++ ; } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; let l = [ 1 , 1 , 2 ] ; let r = [ 2 , 3 , 4 ] ; let q = l . length ; wrapper ( arr , n , l , r , q ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( p , n ) { let G = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( p [ i ] % 2 != 0 ) G ^= ( p [ i ] + 1 ) ; else G ^= ( p [ i ] - 1 ) ; } return G ; } let n = 3 ; let p = [ 32 , 49 , 58 ] ; let res = solve ( p , n ) ; if ( res == 0 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: G, i
Iterator variables: i
Javascript program:
function checkBit ( pattern , arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( ( pattern & arr [ i ] ) == pattern ) count ++ ; return count ; } function maxAND ( arr , n ) { let res = 0 , count ; for ( let bit = 31 ; bit >= 0 ; bit -- ) { count = checkBit ( res | ( 1 << bit ) , arr , n ) ; if ( count >= 2 ) res |= ( 1 << bit ) ; } return res ; } let arr = [ 4 , 8 , 6 , 2 ] ; let n = arr . length ; document . write ( " " + maxAND ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: bit, count, i, res
Iterator variables: bit, i
Javascript program:
function findMiniFlip ( nums ) { let n = nums . length ; let s = " " ; for ( let i = 0 ; i < n ; i ++ ) s += nums [ i ] ; let num = parseInt ( s , 2 ) ; let minXor = n ; let mask = ( 1 << ( n - 1 ) ) ; while ( n - 1 > 0 ) { let temp = ( num ^ mask ) ; minXor = Math . min ( minXor , countones ( temp ) ) ; n -- ; mask = ( mask | ( 1 << n - 1 ) ) ; } return minXor ; } function countones ( n ) { let c = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; c ++ ; } return c ; } let nums = [ 1 , 0 , 1 , 1 , 0 , 0 , 0 ] ; let n = findMiniFlip ( nums ) ; document . write ( n ) ;

Index/key variables: i
Accumulator variables: c, i, n, s
Iterator variables: i
Javascript program:
function convertStringToInt ( s ) { let ans = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) ans += 1 << i ; } return ans ; } function getNthNumber ( n ) { let q = [ ] ; if ( n == 1 ) return 1 ; n = n - 1 ; q . push ( " " ) ; while ( n -- > 0 ) { let curr = q . shift ( ) ; if ( n == 0 ) return convertStringToInt ( curr ) ; let len = curr . length ; let len2 = Math . floor ( len / 2 ) ; if ( len % 2 == 0 ) { q . push ( curr . substring ( 0 , len2 ) + " " + curr . substring ( len2 ) ) ; q . push ( curr . substring ( 0 , len2 ) + " " + curr . substring ( len2 ) ) ; } else { let midChar = curr [ len2 ] ; q . push ( curr . substring ( 0 , len2 ) + midChar + curr . substring ( len2 ) ) ; } } return - 1 ; } let n = 9 ; document . write ( getNthNumber ( n ) ) ;

Index/key variables: i, len2
Accumulator variables: ans, i, n
Iterator variables: i
Javascript program:
function findSum ( n ) { let sum = 0 ; for ( let i = 1 ; 1 << i < n ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { let num = ( 1 << i ) + ( 1 << j ) ; if ( num <= n ) sum += num ; } } return sum ; } let n = 10 ; document . write ( findSum ( n ) ) ;

Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function reversearray ( arr , n ) { let x = parseInt ( - 2147483648 / 2147483647 , 10 ) ; for ( let i = 0 ; i < parseInt ( n / 2 , 10 ) ; i ++ ) { let temp = arr [ i ] ; arr [ i ] = arr [ n + ( x * i ) + x ] ; arr [ n + ( x * i ) + x ] = temp ; } } let arr = [ 5 , 3 , 7 , 2 , 1 , 6 ] ; let n = arr . length ; reversearray ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function reverseArray ( arr , n ) { for ( let i = 0 ; i < parseInt ( n / 2 , 10 ) ; i ++ ) { swap ( arr , i , ( n + ~ i + 1 ) + ~ 1 + 1 ) ; } } function swap ( arr , i , j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } let arr = [ 5 , 3 , 7 , 2 , 1 , 6 ] ; let n = arr . length ; reverseArray ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxXORInRange ( L , R ) { let LXR = L ^ R ; let msbPos = 0 ; while ( LXR > 0 ) { msbPos ++ ; LXR >>= 1 ; } let maxXOR = 0 ; let two = 1 ; while ( msbPos -- > 0 ) { maxXOR += two ; two <<= 1 ; } return maxXOR ; } let L = 8 ; let R = 20 ; document . write ( maxXORInRange ( L , R ) ) ;

Accumulator variables: maxXOR, msbPos
Javascript program:
function CountZeroBit ( n ) { let count = 0 ; while ( n > 0 ) { if ( n % 2 != 0 ) count ++ ; n >>= 1 ; } return count ; } function CountORandSumEqual ( N ) { let count = CountZeroBit ( N ) ; return ( 1 << count ) ; } let N = 10 ; document . write ( CountORandSumEqual ( N ) ) ;

Accumulator variables: count
Javascript program:
function countNumbers ( n ) { let k = 0 ; let count = 0 ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) count += ( Math . pow ( 2 , k ) ) ; k += 1 ; n >>= 1 ; } return count ; } let n = 11 ; document . write ( countNumbers ( n ) ) ;

Accumulator variables: count, k
Javascript program:
function xorPairCount ( arr , n , x ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( s . has ( x ^ arr [ i ] ) ) { result ++ ; } s . add ( arr [ i ] ) ; } return result ; } let arr = [ 5 , 4 , 10 , 15 , 7 , 6 ] ; let n = arr . length ; let x = 5 ; document . write ( " " + xorPairCount ( arr , n , x ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function isMultipleOf4 ( n ) { if ( n == 1 ) return false ; let XOR = 0 ; for ( let i = 1 ; i <= n ; i ++ ) XOR = XOR ^ i ; return ( XOR == n ) ; } for ( let n = 0 ; n <= 42 ; n ++ ) document . write ( isMultipleOf4 ( n ) ? n : " " ) ;

Accumulator variables: i, n
Iterator variables: i, n
Javascript program:
function isMultipleOf4 ( n ) { if ( n == 0 ) return true ; return ( ( ( n >> 2 ) << 2 ) == n ) ; } for ( let n = 0 ; n <= 42 ; n ++ ) if ( isMultipleOf4 ( n ) ) document . write ( n + " " ) ;

Accumulator variables: n
Iterator variables: n
Javascript program:
function countSetBits ( x ) { let count = 0 ; while ( x != 0 ) { x &= ( x - 1 ) ; count ++ ; } return count ; } function ceilLog2 ( x ) { let count = 0 ; x -- ; while ( x > 0 ) { x = x >> 1 ; count ++ ; } return count ; } function isBleak ( n ) { for ( let x = n - ceilLog2 ( n ) ; x < n ; x ++ ) if ( x + countSetBits ( x ) == n ) return false ; return true ; } if ( isBleak ( 3 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isBleak ( 4 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: count, x
Iterator variables: x
Javascript program:
function countStrings ( n ) { let a = [ ] , b = [ ] ; a [ 0 ] = b [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ] ; b [ i ] = a [ i - 1 ] ; } return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ; } document . write ( countStrings ( 5 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function swapBits ( n , p1 , p2 ) { n ^= 1 << p1 ; n ^= 1 << p2 ; return n ; } document . write ( " " + swapBits ( 28 , 0 , 3 ) ) ;

Accumulator variables: n
Javascript program:
function stack_push ( stack ) { for ( var i = 0 ; i < 5 ; i ++ ) { stack . push ( i ) ; } return stack ; } function stack_pop ( stack ) { document . write ( " " ) ; for ( var i = 0 ; i < 5 ; i ++ ) { var y = parseInt ( stack [ stack . length - 1 ] ) ; stack . pop ( ) ; document . write ( y + " " ) ; } return stack ; } function stack_peek ( stack ) { var element = parseInt ( stack [ stack . length - 1 ] ) ; document . write ( " " + element + " " ) ; } function stack_search ( stack , element ) { var pos = - 1 , co = 0 ; while ( stack . length > 0 ) { co ++ ; if ( stack [ stack . length - 1 ] == element ) { pos = co ; break ; } stack . pop ( ) ; } if ( pos == - 1 ) document . write ( " " + " " ) ; else document . write ( " " + pos + " " ) ; } stack = [ ] ; stack = stack_push ( stack ) ; stack = stack_pop ( stack ) ; stack = stack_push ( stack ) ; stack_peek ( stack ) ; stack_search ( stack , 2 ) ; stack_search ( stack , 6 ) ;

Accumulator variables: co, i
Iterator variables: i
Javascript program:
class Node { constructor ( key ) { this . key = key ; this . left = this . right = null ; } } function count ( node ) { if ( node == null ) return 0 ; return count ( node . left ) + count ( node . right ) + 1 ; } function checkRec ( node , n ) { if ( node == null ) return false ; if ( count ( node ) == n - count ( node ) ) return true ; return checkRec ( node . left , n ) || checkRec ( node . right , n ) ; } function check ( node ) { let n = count ( node ) ; return checkRec ( node , n ) ; } let root = new Node ( 5 ) ; root . left = new Node ( 1 ) ; root . right = new Node ( 6 ) ; root . left . left = new Node ( 3 ) ; root . right . left = new Node ( 7 ) ; root . right . right = new Node ( 4 ) ; if ( check ( root ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Class/struct names: Node