dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countPairs ( arr , k , size ) { let count = 0 , x ; for ( let i = 0 ; i < size - 1 ; i ++ ) { for ( let j = i + 1 ; j < size ; j ++ ) { x = arr [ i ] | arr [ j ] ; if ( x == k ) count ++ ; } } document . write ( count ) ; } let arr = [ 2 , 38 , 44 , 29 , 62 ] ; let K = 46 ; let N = arr . length ; countPairs ( arr , K , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let adj = [ ] ; for ( let i = 0 ; i < 100005 ; i ++ ) { adj . push ( [ ] ) } let visited = new Array ( 100005 ) . fill ( 0 ) ; let ans = 0 ; function dfs ( node , xorr , k ) { visited [ node ] = 1 ; if ( node != 1 && xorr == k ) ans ++ ; for ( let x of adj [ node ] ) { if ( ! visited [ x [ 0 ] ] ) { let xorr1 = xorr ^ x [ 1 ] ; dfs ( x [ 0 ] , xorr1 , k ) ; } } } function countNodes ( N , K , R , edges ) { for ( let i = 0 ; i < N - 1 ; i ++ ) { let u = edges [ i ] [ 0 ] , v = edges [ i ] [ 1 ] , w = edges [ i ] [ 2 ] ; adj [ u ] . push ( [ v , w ] ) ; adj [ v ] . push ( [ u , w ] ) ; } dfs ( R , 0 , K ) ; document . write ( ans + " " ) ; } let K = 0 , R = 1 ; let edges = [ [ 1 , 2 , 3 ] , [ 1 , 3 , 1 ] , [ 2 , 4 , 3 ] , [ 2 , 5 , 4 ] , [ 3 , 6 , 1 ] , [ 3 , 7 , 2 ] ] ; let N = edges . length ; countNodes ( N , K , R , edges ) ;

Index/key variables: i, node, u, v
Accumulator variables: ans, i
Iterator variables: i, x
Javascript program:
function findMinXORSubarray ( arr , n , k ) { if ( n < k ) return ; let res_index = 0 ; let curr_xor = 0 ; for ( let i = 0 ; i < k ; i ++ ) curr_xor ^= arr [ i ] ; let min_xor = curr_xor ; for ( let i = k ; i < n ; i ++ ) { curr_xor ^= ( arr [ i ] ^ arr [ i - k ] ) ; if ( curr_xor < min_xor ) { min_xor = curr_xor ; res_index = ( i - k + 1 ) ; } } document . write ( min_xor ) ; } let arr = [ 3 , 7 , 90 , 20 , 10 , 50 , 40 ] ; let k = 3 ; let n = arr . length ; findMinXORSubarray ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: curr_xor, i
Iterator variables: i
Javascript program:
function findmax ( arr , n , k ) { let trav , i ; let c = 0 , maximum = 0 ; for ( i = 0 ; i < n - k + 1 ; i ++ ) { trav = i - 1 ; c = 0 ; while ( trav >= 0 && arr [ trav ] == 1 ) { trav -- ; c ++ ; } trav = i + k ; while ( trav < n && arr [ trav ] == 1 ) { trav ++ ; c ++ ; } c += k ; if ( c > maximum ) maximum = c ; } return maximum ; } let k = 3 ; let arr = [ 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 ] ; let n = arr . length ; let ans = findmax ( arr , n , k ) ; document . write ( ans )

Index/key variables: trav
Accumulator variables: c, i, trav
Iterator variables: i
Javascript program:
function powerOfTwo ( a , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( a [ i ] ) ) { mp . set ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ; } else { mp . set ( a [ i ] , 1 ) ; } } let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let f = false ; for ( let j = 0 ; j < 31 ; j ++ ) { let s = ( 1 << j ) - a [ i ] ; if ( mp . has ( s ) && ( mp . get ( s ) > 1 || mp . get ( s ) == 1 && s != a [ i ] ) ) f = true ; } if ( f == false ) count ++ ; } return count ; } let a = [ 6 , 2 , 11 ] ; let n = a . length ; document . write ( powerOfTwo ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i, j
Iterator variables: i, j
Boolean variables: f
Javascript program:
function findArray ( n , a , b , c ) { let arr = new Array ( n + 1 ) ; for ( let bit = 30 ; bit >= 0 ; bit -- ) { let set = a & ( 1 << bit ) ; if ( set ) { for ( let i = 0 ; i < n ; i ++ ) arr [ i ] |= set ; } else { if ( b & ( 1 << bit ) ) { arr [ 0 ] |= ( 1 << bit ) ; if ( ! ( c & ( 1 << bit ) ) ) { arr [ 1 ] |= ( 1 << bit ) ; } } } } let aa = Number . MAX_SAFE_INTEGER , bb = 0 , cc = 0 ; for ( let i = 0 ; i < n ; i ++ ) { aa &= arr [ i ] ; bb |= arr [ i ] ; cc ^= arr [ i ] ; } if ( a == aa && b == bb && c == cc ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } else document . write ( " " ) ; } let n = 3 , a = 4 , b = 6 , c = 6 ; findArray ( n , a , b , c ) ;

Index/key variables: i
Accumulator variables: aa, bb, bit, cc, i
Iterator variables: bit, i
Javascript program:
function maxAndXor ( arr , n ) { let ans = Number . MAX_VALUE ; arr . sort ( ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { ans = Math . min ( ans , arr [ i ] ^ arr [ i + 1 ] ) ; } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; document . write ( maxAndXor ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubarray ( arr , K , N ) { if ( K % 2 != 0 ) return 0 ; if ( N < K ) return 0 ; var start = 0 ; var i = 0 ; var count = 0 ; var currXor = arr [ i ] ; i ++ ; while ( i < K ) { currXor ^= arr [ i ] ; i ++ ; } if ( currXor == 0 ) count ++ ; currXor ^= arr [ start ] ; start ++ ; while ( i < N ) { currXor ^= arr [ i ] ; i ++ ; if ( currXor == 0 ) count ++ ; currXor ^= arr [ start ] ; start ++ ; } return count ; } var arr = [ 2 , 4 , 4 , 2 , 2 , 4 ] ; var K = 4 ; var N = arr . length ; document . write ( countSubarray ( arr , K , N ) ) ;

Index/key variables: i, start
Accumulator variables: count, currXor, i, start
Javascript program:
function keep_count ( arr , N ) { var count ; for ( i = 0 ; i < N ; i ++ ) { count = 0 ; while ( arr [ i ] != 0 ) { arr [ i ] = ( arr [ i ] - 1 ) & arr [ i ] ; count ++ ; } if ( count % 2 == 0 ) even ++ ; else odd ++ ; } return ; } function solveQueries ( arr , n , q , m ) { even = 0 ; odd = 0 ; keep_count ( arr , n ) ; for ( i = 0 ; i < m ; i ++ ) { var X = q [ i ] ; var count = 0 ; while ( X != 0 ) { X = ( X - 1 ) & X ; count ++ ; } if ( count % 2 == 0 ) { document . write ( even + " " + odd + " " ) ; } else { document . write ( odd + " " + even + " " ) ; } } } var arr = [ 2 , 7 , 4 , 5 , 3 ] ; var n = arr . length ; var q = [ 3 , 4 , 12 , 6 ] ; var m = q . length ; solveQueries ( arr , n , q , m ) ;

Index/key variables: i
Accumulator variables: count, even, i, odd
Iterator variables: i
Javascript program:
let pref = new Array ( 100001 ) . fill ( 0 ) ; function isEvenParity ( num ) { let parity = 0 ; let x = num ; while ( x != 0 ) { if ( x & 1 == 1 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return num ; else return 0 ; } function preCompute ( ) { for ( let i = 1 ; i < 100001 ; i ++ ) { pref [ i ] = pref [ i - 1 ] + isEvenParity ( i ) ; } } function printSum2 ( L , R ) { document . write ( pref [ R ] - pref [ L - 1 ] + " " ) ; } function printSum ( arr , Q ) { preCompute ( ) ; for ( let i = 0 ; i < Q ; i ++ ) { printSum2 ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } let N = 2 ; let Q = [ [ 1 , 10 ] , [ 121 , 211 ] ] ; printSum ( Q , N ) ;

Index/key variables: R, i
Accumulator variables: i, parity
Iterator variables: i
Javascript program:
function findLargestNumber ( arr ) { var k = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var m = Array ( k ) . fill ( 0 ) ; arr . forEach ( n => { ++ m [ n ] ; } ) ; for ( var n = arr . length ; n > 0 ; -- n ) { if ( n == m [ n ] ) return n ; } return - 1 ; } var arr = [ 3 , 2 , 5 , 2 , 4 , 5 ] ; document . write ( findLargestNumber ( arr ) ) ;

Index/key variables: n
Iterator variables: n
Javascript program:
function findLargestNumber ( arr ) { arr . forEach ( n => { n &= 0xFFFF ; if ( n <= arr . length ) { arr [ n - 1 ] += 0x10000 ; } } ) ; for ( var i = arr . length ; i > 0 ; -- i ) { if ( ( arr [ i - 1 ] >> 16 ) == i ) return i ; } return - 1 ; } var arr = [ 3 , 2 , 5 , 5 , 2 , 4 , 5 ] ; document . write ( findLargestNumber ( arr ) )

Accumulator variables: n
Iterator variables: i
Javascript program:
function CheckBits ( N , K ) { var check = 0 ; var count = 0 ; for ( var i = 31 ; i >= 0 ; i -- ) { if ( ( ( 1 << i ) & N ) > 0 ) { if ( check == 0 ) { check = 1 ; } else { if ( count < K ) { return false ; } } count = 0 ; } else { count ++ ; } } return true ; } var N = 5 ; var K = 1 ; if ( CheckBits ( N , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minimumFlips ( X , Y , Z ) { var res = 0 ; while ( X > 0 Y > 0 Z > 0 ) { if ( ( ( X & 1 ) || ( Y & 1 ) ) && ( Z & 1 ) ) { X = X >> 1 ; Y = Y >> 1 ; Z = Z >> 1 ; continue ; } else if ( ( X & 1 ) == 0 && ( Y & 1 ) == 0 && ( Z & 1 ) ) { res ++ ; } else if ( ( X & 1 ) || ( Y & 1 ) == 1 ) { if ( ( X & 1 ) && ( Y & 1 ) && ( Z & 1 ) == 0 ) { res += 2 ; } else if ( ( ( X & 1 ) || ( Y & 1 ) ) && ( Z & 1 ) == 0 ) { res ++ ; } } X = X >> 1 ; Y = Y >> 1 ; Z = Z >> 1 ; } return res ; } var X = 5 , Y = 8 , Z = 6 ; document . write ( minimumFlips ( X , Y , Z ) ) ;

Accumulator variables: res
Javascript program:
function countSubseq ( arr , n ) { let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mp [ arr [ i ] ] ++ ; if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) } else { mp . set ( arr [ i ] , 1 ) } } for ( let i of mp ) { if ( i [ 0 ] == 0 ) count += Math . pow ( 2 , i [ 1 ] ) - 1 ; else count += Math . pow ( 2 , i [ 1 ] - 1 ) ; } return count ; } let arr = [ 2 , 2 , 2 , 5 , 6 ] ; let n = arr . length ; document . write ( countSubseq ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function calculate ( section , pos ) { if ( pos < 0 ) return 0 ; let on_section = [ ] , off_section = [ ] ; for ( let el = 0 ; el < section . length ; el ++ ) { if ( ( ( section [ el ] >> pos ) & 1 ) == 0 ) off_section . push ( section [ el ] ) ; else on_section . push ( section [ el ] ) ; } if ( off_section . length == 0 ) return calculate ( on_section , pos - 1 ) ; if ( on_section . length == 0 ) return calculate ( off_section , pos - 1 ) ; return Math . min ( calculate ( off_section , pos - 1 ) , calculate ( on_section , pos - 1 ) ) + ( 1 << pos ) ; } function minXorValue ( a , n ) { let section = [ ] ; for ( let i = 0 ; i < n ; i ++ ) section . push ( a [ i ] ) ; return calculate ( section , 30 ) ; } let N = 4 ; let A = [ 3 , 2 , 5 , 6 ] ; document . write ( minXorValue ( A , N ) ) ;

Index/key variables: el, i
Accumulator variables: el, i
Iterator variables: el, i
Javascript program:
function findNthNum ( N ) { let bit_L = 1 , last_num = 0 ; while ( bit_L * ( bit_L + 1 ) / 2 < N ) { last_num = last_num + bit_L ; bit_L ++ ; } let bit_R = N - last_num - 1 ; document . write ( ( 1 << bit_L ) + ( 1 << bit_R ) + " " ) ; } let N = 13 ; findNthNum ( N ) ;

Accumulator variables: bit_L
Javascript program:
const MAX = 1000005 ; function SieveOfEratosthenes ( prime ) { prime [ 1 ] = false ; prime [ 0 ] = false ; for ( let p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } } function prime_xor ( arr , n , k ) { let prime = new Array ( MAX ) . fill ( true ) ; SieveOfEratosthenes ( prime ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { if ( ( i + 1 ) % k == 0 ) { ans ^= arr [ i ] ; } } } document . write ( ans ) ; } let arr = [ 2 , 3 , 5 , 7 , 11 , 8 ] ; let n = arr . length ; let K = 2 ; prime_xor ( arr , n , K ) ;

Index/key variables: i, p
Accumulator variables: ans, i, p
Iterator variables: i, p
Javascript program:
function xorOfArray ( arr , n ) { let xor_arr = 0 ; for ( let i = 0 ; i < n ; i ++ ) { xor_arr = xor_arr ^ arr [ i ] ; } return xor_arr ; } let arr = [ 3 , 9 , 12 , 13 , 15 ] ; let n = arr . length ; document . write ( xorOfArray ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countEvenBit ( A , B , n , m ) { let i , j , cntOdd = 0 , cntEven = 0 ; for ( i = 0 ; i < n ; i ++ ) { let x = bitCount ( A [ i ] ) ; if ( x & 1 ) { cntEven ++ ; } else { cntOdd ++ ; } } let CountB = new Array ( m ) ; for ( i = 0 ; i < m ; i ++ ) { let x = bitCount ( B [ i ] ) ; if ( x & 1 ) { CountB [ i ] = cntEven ; } else { CountB [ i ] = cntOdd ; } } for ( i = 0 ; i < m ; i ++ ) { document . write ( CountB [ i ] + " " ) ; } } function bitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let A = [ 4 , 2 , 15 , 9 , 8 , 8 ] ; let B = [ 3 , 4 , 22 ] ; countEvenBit ( A , B , 6 , 3 ) ;

Index/key variables: i
Accumulator variables: cntEven, cntOdd, i, setBits
Iterator variables: i
Javascript program:
function bitwiseOrTillN ( n ) { var result = 2 ; for ( var i = 4 ; i <= n ; i = i + 2 ) { result = result | i ; } return result ; } var n = 10 ; document . write ( bitwiseOrTillN ( n ) ) ;

Iterator variables: i
Javascript program:
function genSequence ( n , val ) { for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { let x = i ^ ( i >> 1 ) ^ val ; document . write ( x + " " ) ; } } let n = 3 , k = 2 ; genSequence ( n , k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function winner ( moves ) { let data = new Map ( ) ; data . set ( ' ' , 0 ) ; data . set ( ' ' , 1 ) ; data . set ( ' ' , 2 ) ; if ( moves [ 0 ] == moves [ 1 ] ) { return " " ; } if ( ( ( data . get ( moves [ 0 ] ) | 1 << ( 2 ) ) - ( data . get ( moves [ 1 ] ) | 0 << ( 2 ) ) ) % 3 != 0 ) { return " " ; } return " " ; } function performQueries ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( winner ( arr [ i ] ) + " " ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; performQueries ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxConsecutiveOnes ( x ) { var count = 0 ; while ( x != 0 ) { x = ( x & ( x << 1 ) ) ; count ++ ; } return count ; } function maxOnes ( arr , n ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { var currMax = maxConsecutiveOnes ( arr [ i ] ) ; ans = Math . max ( ans , currMax ) ; } return ans ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; document . write ( maxOnes ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function maxOR ( L , R ) { let maximum = Number . MIN_VALUE ; for ( let i = L ; i < R ; i ++ ) for ( let j = i + 1 ; j <= R ; j ++ ) maximum = Math . max ( maximum , ( i j ) ) ; return maximum ; } let L = 4 , R = 5 ; document . write ( maxOR ( L , R ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 64 ; function maxOR ( L , R ) { if ( L == R ) { return L ; } let ans = 0 ; for ( let i = MAX - 1 ; i >= 0 ; i -- ) { let p , lbit , rbit ; p = 1 << i ; if ( ( rbit == 1 ) && ( lbit == 0 ) ) { ans += ( p << 1 ) - 1 ; break ; } if ( rbit == 1 ) { ans += p ; } } return ans ; } let L = 4 , R = 5 ; document . write ( maxOR ( L , R ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findLen ( arr , n , m ) { var filter = [ ] ; for ( var i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & m ) == m ) filter . push ( arr [ i ] ) ; if ( filter . length == 0 ) return 0 ; var c_and = filter [ 0 ] ; for ( var i = 1 ; i < filter . length ; i ++ ) c_and &= filter [ i ] ; if ( c_and == m ) return filter . length ; return 0 ; } var arr = [ 7 , 3 , 3 , 1 , 3 ] ; var n = arr . length ; var m = 3 ; document . write ( findLen ( arr , n , m ) ) ;

Index/key variables: i
Accumulator variables: c_and, i
Iterator variables: i
Javascript program:
let MAX = 32 ; function maximizeExpression ( a , b ) { let result = a ; for ( let bit = MAX - 1 ; bit >= 0 ; bit -- ) { let bitOfD = 1 << bit ; let x = b & bitOfD ; if ( x == bitOfD ) { let y = result & bitOfD ; if ( y == 0 ) { result = result ^ bitOfD ; } } } return result ; } let a = 11 , b = 14 ; document . write ( maximizeExpression ( a , b ) ) ;

Accumulator variables: bit
Iterator variables: bit
Javascript program:
var MAX = 10 ; function findSubarray ( array , n ) { var mp = new Map ( ) ; mp . set ( 0 , 1 ) ; var answer = 0 ; var preXor = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var value = 1 ; preXor ^= array [ i ] ; for ( var j = 1 ; j <= MAX ; j ++ ) { var Y = value ^ preXor ; if ( mp . has ( Y ) ) { answer += mp . get ( Y ) ; } value *= 2 ; } if ( mp . has ( preXor ) ) { mp . set ( preXor , mp . get ( preXor ) + 1 ) ; } else { mp . set ( preXor , 1 ) ; } } return answer ; } var array = [ 2 , 6 , 7 , 5 , 8 ] ; var n = array . length ; document . write ( findSubarray ( array , n ) ) ;

Index/key variables: i
Accumulator variables: answer, i, j, preXor, value
Iterator variables: i, j
Javascript program:
function max_xor ( arr , n ) { let maxXor = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { maxXor = Math . max ( maxXor , arr [ i ] ^ arr [ j ] ) ; } } return maxXor ; } let arr = [ 25 , 10 , 2 , 8 , 5 , 3 ] ; let n = arr . length ; document . write ( max_xor ( arr , n ) ) ;

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

Index/key variables: i, j
Accumulator variables: ans, first, i, j
Iterator variables: i, j
Javascript program:
function findMajority ( arr , n ) { let len = 32 ; let number = 0 ; for ( let i = 0 ; i < len ; i ++ ) { let countt = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) != 0 ) countt ++ ; } if ( countt > parseInt ( n / 2 , 10 ) ) number += ( 1 << i ) ; } let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] == number ) count ++ ; if ( count > parseInt ( n / 2 , 10 ) ) document . write ( number ) ; else document . write ( " " ) ; } let arr = [ 3 , 3 , 4 , 2 , 4 , 4 , 2 , 4 , 4 ] ; let n = arr . length ; findMajority ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: count, countt, i, j, number
Iterator variables: i, j
Javascript program:
function countBits ( a , b ) { var count = 0 ; while ( a b ) { var last_bit_a = a & 1 ; var last_bit_b = b & 1 ; if ( last_bit_a != last_bit_b ) count ++ ; a = a >> 1 ; b = b >> 1 ; } return count ; } var a = 10 , b = 7 ; document . write ( countBits ( a , b ) ) ;

Accumulator variables: count
Javascript program:
function pairORSum ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) ans += arr [ i ] | arr [ j ] ; return ans ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; document . write ( pairORSum ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( let i = 2 ; i < n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function countPrimePosition ( arr , n ) { let c0 = 0 , c1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 && isPrime ( i ) ) c0 ++ ; if ( arr [ i ] == 1 && isPrime ( i ) ) c1 ++ ; } document . write ( " " + c0 + " " ) ; document . write ( " " + c1 ) ; } let arr = [ 1 , 0 , 1 , 0 , 1 ] ; let n = arr . length ; countPrimePosition ( arr , n ) ;

Index/key variables: i
Accumulator variables: c0, c1, i
Iterator variables: i
Javascript program:
var N = 101 ; function prefix ( arr , prefix_xor , n ) { for ( var i = 1 ; i < n ; i ++ ) { for ( var j = 1 ; j < n ; j ++ ) { prefix_xor [ i ] [ j ] = arr [ i ] [ j ] ^ prefix_xor [ i - 1 ] [ j ] ^ prefix_xor [ i ] [ j - 1 ] ^ prefix_xor [ i - 1 ] [ j - 1 ] ; } } } function Max_xor ( prefix_xor , n ) { var max_value = 0 ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { for ( var i1 = i ; i1 <= n ; i1 ++ ) { for ( var j1 = j ; j1 <= n ; j1 ++ ) { var x = 0 ; x ^= prefix_xor [ i1 ] [ j1 ] ; x ^= prefix_xor [ i - 1 ] [ j - 1 ] ; x ^= prefix_xor [ i1 ] [ j - 1 ] ; x ^= prefix_xor [ i - 1 ] [ j1 ] ; max_value = Math . max ( max_value , x ) ; } } } } document . write ( max_value ) ; } var arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; var n = 4 ; var prefix_xor = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( 0 ) ) ; prefix ( arr , prefix_xor , n ) ; Max_xor ( prefix_xor , n ) ;

Index/key variables: i, i1, j, j1
Accumulator variables: i, i1, j, j1, x
Iterator variables: i, i1, j, j1
Javascript program:
function multiplyByFifteen ( n ) { var prod = ( n << 3 ) ; prod += ( n << 2 ) ; prod += ( n << 1 ) ; prod += n ; return prod ; } var n = 7 ; document . write ( multiplyByFifteen ( n ) ) ;

Accumulator variables: prod
Javascript program:
function findX ( arr , n ) { let itr = Math . max ( ... arr ) ; let p = parseInt ( Math . log ( itr ) / Math . log ( 2 ) ) + 1 ; let X = 0 ; for ( let i = 0 ; i < p ; i ++ ) { let count = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( arr [ j ] & ( 1 << i ) ) { count ++ ; } } if ( count > parseInt ( n / 2 ) ) { X += 1 << i ; } } let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += ( X ^ arr [ i ] ) ; document . write ( " " + X + " " + sum ) ; } let arr = [ 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; findX ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: X, count, i, j, sum
Iterator variables: i, j
Javascript program:
let arr = new Array ( 33 ) ; function balTernary ( ter ) { let carry = 0 , base = 10 ; let i = 32 ; while ( ter > 0 ) { let rem = ter % base ; rem = rem + carry ; if ( rem == 0 ) { arr [ i -- ] = 0 ; carry = 0 ; } else if ( rem == 1 ) { arr [ i -- ] = 1 ; carry = 0 ; } else if ( rem == 2 ) { arr [ i -- ] = - 1 ; carry = 1 ; } else if ( rem == 3 ) { arr [ i -- ] = 0 ; carry = 1 ; } ter = Math . floor ( ter / base ) ; } if ( carry == 1 ) arr [ i ] = 1 ; } function ternary ( number ) { let ans = 0 , rem = 1 , base = 1 ; while ( number > 0 ) { rem = number % 3 ; ans = ans + rem * base ; number = Math . floor ( number / 3 ) ; base = base * 10 ; } return ans ; } let number = 3056 ; let ter = ternary ( number ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 0 ; } balTernary ( ter ) ; let i = 0 ; while ( arr [ i ] == 0 ) { i ++ ; } for ( let j = i ; j <= 32 ; j ++ ) { if ( arr [ j ] == - 1 ) document . write ( ' ' ) ; else document . write ( arr [ j ] ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minAND ( arr , n ) { let s = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { s = s & arr [ i ] ; } document . write ( ( s ) + " " ) ; } let arr = [ 1 , 2 , 3 ] ; let n = arr . length ; minAND ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( a , n ) { for ( var i = 0 ; i < n ; i ++ ) if ( a [ i ] ) return true ; return false ; } var a = [ 0 , 1 , 0 , 1 ] ; var n = a . length ; check ( a , n ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function findArray ( q , n ) { let arr = new Array ( n ) , ans ; for ( let k = 0 , j = 0 ; j < parseInt ( n / 4 ) ; j ++ ) { ans = q [ k ] ^ q [ k + 3 ] ; arr [ k + 1 ] = q [ k + 1 ] ^ ans ; arr [ k + 2 ] = q [ k + 2 ] ^ ans ; arr [ k ] = q [ k ] ^ ( ( arr [ k + 1 ] ) ^ ( arr [ k + 2 ] ) ) ; arr [ k + 3 ] = q [ k + 3 ] ^ ( arr [ k + 1 ] ^ arr [ k + 2 ] ) ; k += 4 ; } printArray ( arr , n ) ; } let q = [ 4 , 1 , 7 , 0 ] ; let n = q . length ; findArray ( q , n ) ;

Index/key variables: i, k
Accumulator variables: i, j, k
Iterator variables: i, k
Javascript program:
function countX ( n ) { let binary = ( n >>> 0 ) . toString ( 2 ) ; let count = 0 ; for ( let i = 0 ; i < binary . length ; i ++ ) { if ( binary [ i ] == ' ' ) count ++ ; } let answer = Math . floor ( Math . pow ( 2 , count ) ) ; return answer ; } let n = 5 ; let answer = countX ( n ) ; document . write ( answer ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isEqualBlock ( n ) { var first_bit = n % 2 ; var first_count = 1 ; n = n / 2 ; while ( n % 2 == first_bit && n > 0 ) { n = n / 2 ; first_count ++ ; } if ( n == 0 ) return false ; while ( n > 0 ) { first_bit = n % 2 ; var curr_count = 1 ; n = n / 2 ; while ( n % 2 == first_bit ) { n = n / 2 ; curr_count ++ ; } if ( curr_count != first_count ) return false ; } return true ; } var n = 51 ; if ( isEqualBlock ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: curr_count, first_count