dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maximum ( a , b ) { if ( a > b ) return a ; return b ; } function maxSubarrayRatio ( arr , n ) { var maxRatio = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { var ratio = arr [ i ] ; for ( var k = i + 1 ; k <= j ; k ++ ) { ratio = ratio / arr [ k ] ; } maxRatio = maximum ( maxRatio , ratio ) ; } } return maxRatio ; } var arr = [ 2 , 2 , 4 , - 0.2 , - 1 ] ; var n = arr . length ; document . write ( maxSubarrayRatio ( arr , n ) ) ;

Index/key variables: i, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function check ( num ) { let root = Math . floor ( Math . sqrt ( num ) ) ; let pow = Math . floor ( Math . log ( root ) / Math . log ( 2 ) ) ; if ( num == Math . floor ( Math . pow ( 2 , pow ) * ( Math . pow ( 2 , pow + 1 ) - 1 ) ) ) { if ( isPrime ( pow + 1 ) ) { if ( isPrime ( Math . floor ( Math . pow ( 2 , pow + 1 ) ) - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ; } else document . write ( " " ) ; } else document . write ( " " ) ; } function isPrime ( n ) { if ( n <= 1 ) return false ; else if ( n == 2 n == 3 ) return true ; else { if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i <= Math . floor ( Math . sqrt ( n ) ) ; i += 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; } return true ; } } let num = 6 ; check ( num ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isTriplet ( ar , n ) { for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { for ( var k = j + 1 ; k < n ; k ++ ) { if ( Math . abs ( ar [ i ] - ar [ j ] ) == 1 || Math . abs ( ar [ j ] - ar [ k ] ) == 1 || Math . abs ( ar [ i ] - ar [ k ] ) == 1 ) { var x = ar [ i ] * ar [ i ] , y = ar [ j ] * ar [ j ] , z = ar [ k ] * ar [ k ] ; if ( x == y + z y == x + z z == x + y ) return true ; } } } } return false ; } var arr = [ 3 , 1 , 4 , 6 , 5 ] ; var ar_size = arr . length ; isTriplet ( arr , ar_size ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function closestDivisors ( n ) { for ( var i = parseInt ( Math . sqrt ( n + 2 ) ) ; i > 0 ; i -- ) { if ( ( n + 1 ) % i == 0 ) { document . write ( i + " " + parseInt ( ( n + 1 ) / i ) ) ; break ; } if ( ( n + 2 ) % i == 0 ) { document . write ( i + " " + parseInt ( ( n + 2 ) / i ) ) ; break ; } } } N = 123 ; closestDivisors ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( n ) { let phi = [ ] ; let divs = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { phi [ i ] = 0 ; divs [ i ] = 0 ; } for ( let i = 1 ; i <= n ; i ++ ) { phi [ i ] += i ; for ( let j = i * 2 ; j <= n ; j += i ) phi [ j ] -= phi [ i ] ; for ( let j = i ; j <= n ; j += i ) divs [ j ] ++ ; } return ( n - phi [ n ] - divs [ n ] + 1 ) ; } let N = 42 ; document . write ( count ( N ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sum_of_differences ( arr , N ) { let sum = 0 ; let i , j , flag ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] < arr [ i + 1 ] ) { flag = 0 ; for ( j = i + 1 ; j < N - 1 ; j ++ ) { if ( arr [ j ] >= arr [ j + 1 ] ) { sum += ( arr [ j ] - arr [ i ] ) ; i = j ; flag = 1 ; break ; } } if ( flag == 0 && arr [ i ] < arr [ N - 1 ] ) { sum += ( arr [ N - 1 ] - arr [ i ] ) ; break ; } } } return sum ; } let arr = [ 6 , 1 , 2 , 5 , 3 , 4 ] ; let N = arr . length ; document . write ( sum_of_differences ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } function newNode ( data ) { return new Node ( data , null , null ) ; } function inorder ( node ) { if ( node == null ) return ; inorder ( node . left ) ; document . write ( node . data + " " ) ; inorder ( node . right ) ; } function MaximumBinaryTree ( t1 , t2 ) { if ( t1 == null ) return t2 ; if ( t2 == null ) return t1 ; t1 . data = Math . max ( t1 . data , t2 . data ) ; t1 . left = MaximumBinaryTree ( t1 . left , t2 . left ) ; t1 . right = MaximumBinaryTree ( t1 . right , t2 . right ) ; return t1 ; } var root1 = newNode ( 3 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 6 ) ; root1 . left . left = newNode ( 20 ) ; var root2 = newNode ( 5 ) ; root2 . left = newNode ( 1 ) ; root2 . right = newNode ( 8 ) ; root2 . left . right = newNode ( 2 ) ; root2 . right . right = newNode ( 8 ) ; var root3 = MaximumBinaryTree ( root1 , root2 ) ; inorder ( root3 ) ;

Class/struct names: Node
Javascript program:
function MinimumString ( x ) { let b = 1 ; let left_lim = Math . sqrt ( x ) + 1.0 ; let right_lim = Math . sqrt ( x ) + 2.0 ; let r = 0 ; for ( let i = Math . floor ( left_lim ) ; i <= Math . floor ( right_lim ) ; i ++ ) { if ( i > left_lim && i < right_lim ) { r = i ; break ; } } return b + r ; } let X = 2 ; document . write ( MinimumString ( X ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPerfectSquare ( N ) { let floorSqrt = Math . floor ( Math . sqrt ( N ) ) ; return ( N == floorSqrt * floorSqrt ) ; } function legendreFunction ( N ) { while ( N % 4 == 0 ) N = Math . floor ( N / 4 ) ; if ( N % 8 != 7 ) return true ; else return false ; } function minSquares ( N ) { if ( isPerfectSquare ( N ) ) return 1 ; for ( let i = 1 ; i * i < N ; i ++ ) { if ( isPerfectSquare ( N - i * i ) ) return 2 ; } if ( legendreFunction ( N ) ) return 3 ; return 4 ; } let N = 123 ; document . write ( minSquares ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function is_distinct ( n , k ) { let s = new Set ( ) ; for ( let i = 1 ; i <= k ; i ++ ) { let tmp = n % i ; if ( s . has ( tmp ) ) { return false ; } s . add ( tmp ) ; } return true ; } let N = 5 , K = 3 ; if ( is_distinct ( N , K ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getDivisors ( min , n ) { var total = 0 ; for ( var i = min ; i < n ; ++ i ) { if ( n % i == 0 && n / i >= i ) { ++ total ; if ( n / i > i ) total += getDivisors ( i , n / i ) ; } } return total ; } var n = 30 ; document . write ( 1 + getDivisors ( 2 , n ) ) ;

Accumulator variables: total
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . val = val ; this . next = null ; } } ; function getLastTwoPerson ( n ) { var total = n ; var head = new Node ( 1 ) ; var temp = head ; for ( var i = 2 ; i <= n ; i ++ ) { temp . next = new Node ( i ) ; temp = temp . next ; } temp . next = head ; temp = head ; var del ; while ( total != 2 ) { del = temp . next . next ; temp . next . next = temp . next . next . next ; temp = temp . next ; total -= 1 ; } document . write ( temp . val + " " + temp . next . val ) ; } var n = 2 ; getLastTwoPerson ( n ) ;

Accumulator variables: i, total
Iterator variables: i
Class/struct names: Node
Javascript program:
function findContent ( arr , n ) { var content = arr [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) { content = __gcd ( content , arr [ i ] ) ; } return content ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var n = 3 ; var arr = [ 9 , 6 , 12 ] ; document . write ( findContent ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function inverseEqual ( arr , n ) { var brr = Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var present_index = arr [ i ] - 1 ; brr [ present_index ] = i + 1 ; } for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var n = 4 ; var arr = [ 1 , 4 , 3 , 2 ] ; inverseEqual ( arr , n ) ;

Index/key variables: i, present_index
Accumulator variables: i
Iterator variables: i
Javascript program:
function inverseEqual ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( arr [ arr [ i ] - 1 ] != i + 1 ) return false ; return true ; } let n = 4 ; let arr = [ 1 , 4 , 3 , 2 ] ; document . write ( inverseEqual ( arr , n ) ? " " : " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function linearCongruentialMethod ( Xo , m , a , c , randomNums , noOfRandomNums ) { randomNums [ 0 ] = Xo ; for ( let i = 1 ; i < noOfRandomNums ; i ++ ) { randomNums [ i ] = ( ( randomNums [ i - 1 ] * a ) + c ) % m ; } } let Xo = 5 ; let m = 7 ; let a = 3 ; let c = 3 ; let noOfRandomNums = 10 ; let randomNums = new Array ( noOfRandomNums ) . fill ( 0 ) ; linearCongruentialMethod ( Xo , m , a , c , randomNums , noOfRandomNums ) ; for ( let i = 0 ; i < noOfRandomNums ; i ++ ) { document . write ( randomNums [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function multiplicativeCongruentialMethod ( Xo , m , a , randomNums , noOfRandomNums ) { randomNums [ 0 ] = Xo ; for ( let i = 1 ; i < noOfRandomNums ; i ++ ) { randomNums [ i ] = ( randomNums [ i - 1 ] * a ) % m ; } } let Xo = 3 ; let m = 15 ; let a = 7 ; let noOfRandomNums = 10 ; let randomNums = new Array ( noOfRandomNums ) . fill ( 0 ) ; multiplicativeCongruentialMethod ( Xo , m , a , randomNums , noOfRandomNums ) ; for ( let i = 0 ; i < noOfRandomNums ; i ++ ) { document . write ( randomNums [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var MOD = 1000000007 ; function power ( a , b , m ) { a %= m ; var res = 1 ; while ( b > 0 ) { if ( b & 1 ) res = ( ( res % m ) * ( a % m ) ) % m ; a = ( ( a % m ) * ( a % m ) ) % m ; b >>= 1 ; } return res % m ; } function productOfDivisors ( p , n ) { var prime = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( prime . has ( p [ i ] ) ) prime . set ( p [ i ] , prime . get ( p [ i ] ) + 1 ) else prime . set ( p [ i ] , 1 ) } var product = 1 , d = 1 ; prime . forEach ( ( value , key ) => { var val = power ( key , ( value ) * ( value + 1 ) / 2 , MOD ) ; product = ( power ( product , value + 1 , MOD ) * power ( val , d , MOD ) ) % MOD ; d = ( d * ( value + 1 ) ) % ( MOD - 1 ) ; } ) ; return product ; } var arr = [ 11 , 11 ] ; var n = arr . length ; document . write ( productOfDivisors ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const printFractions = ( n ) => { for ( var i = 1 ; i < n ; i ++ ) { for ( var j = i + 1 ; j <= n ; j ++ ) { if ( __gcd ( i , j ) == 1 ) { let a = ` ${ i } ` ; let b = ` ${ j } ` ; document . write ( ` ${ a } ${ b } ` ) } } } } const __gcd = ( a , b ) => { if ( b == 0 ) { return a ; } else { return __gcd ( b , a % b ) ; } } let n = 3 ; printFractions ( n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function SquareRoot ( num ) { let count = 0 ; for ( let n = 1 ; n <= num ; n += 2 ) { num = num - n ; count += 1 ; if ( num == 0 ) break ; } return count ; } let N = 81 ; document . write ( SquareRoot ( N ) ) ;

Accumulator variables: count, n
Iterator variables: n
Javascript program:
function gcd ( x , y ) { if ( x == 0 ) return y ; return gcd ( y % x , x ) ; } function findDistinct ( arr , n ) { let maximum = Math . max ( ... arr ) ; if ( n == 1 ) return 1 ; if ( n == 2 ) { return ( maximum / gcd ( arr [ 0 ] , arr [ 1 ] ) ) ; } let k = gcd ( arr [ 0 ] , arr [ 1 ] ) ; for ( let i = 2 ; i < n ; i ++ ) { k = gcd ( k , arr [ i ] ) ; } return ( maximum / k ) ; } let arr = [ 1 , 2 , 3 , 5 ] ; let n = arr . length ; document . write ( findDistinct ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function power ( a , b ) { if ( b == 0 ) return 1 ; if ( b == 1 ) return a ; let tmp = power ( a , Math . floor ( b / 2 ) ) ; let result = tmp * tmp ; if ( b % 2 == 1 ) result *= a ; return result ; } function check ( n ) { let temp = n ; while ( temp > 0 ) { let last_digit = temp % 10 ; if ( last_digit == 0 last_digit == 1 ) return false ; if ( n % last_digit == 0 ) return false ; temp = Math . floor ( temp / 10 ) ; } return true ; } function solve ( n ) { let L = power ( 10 , n - 1 ) ; let R = power ( 10 , n ) - 1 ; let flag = 0 ; for ( let i = L ; i <= R ; i ++ ) { let answer = check ( i ) ; if ( answer === true ) { document . write ( i + " " ) ; flag ++ ; break ; } } if ( flag === 0 ) document . write ( " " + " " ) ; } let N = 4 ; solve ( N ) ;

Accumulator variables: flag, i, result
Iterator variables: i
Javascript program:
function costOfSubsequence ( N , arr , costArray ) { let i , temp ; let cost = 0 ; let removedElements = new Set ( ) ; let ans = 0 ; for ( i = 1 ; i < ( N - 1 ) ; i ++ ) { temp = arr [ i ] ; if ( ( ( arr [ i - 1 ] < temp ) && ( temp < arr [ i + 1 ] ) ) || ( ( arr [ i - 1 ] > temp ) && ( temp > arr [ i + 1 ] ) ) ) { removedElements . add ( temp ) ; } } for ( i = 0 ; i < ( N ) ; i ++ ) { temp = arr [ i ] ; if ( ! removedElements . has ( temp ) ) { ans += arr [ i ] ; } else { cost += costArray [ i ] ; } } document . write ( ans + " " ) ; document . write ( cost ) ; } let N ; N = 4 ; let arr = [ 1 , 3 , 4 , 2 ] ; let costArray = [ 0 , 1 , 0 , 0 ] ; costOfSubsequence ( N , arr , costArray ) ;

Index/key variables: i
Accumulator variables: ans, cost, i
Iterator variables: i
Javascript program:
let maxN = 100000000 ; let prime = [ ] ; function sieve ( n ) { let check = new Array ( 1000007 ) ; for ( let i = 0 ; i < 1000007 ; i ++ ) check [ i ] = false ; let i , j ; check [ 0 ] = false ; check [ 1 ] = true ; check [ 2 ] = false ; for ( i = 4 ; i <= n ; i += 2 ) check [ i ] = true ; for ( i = 3 ; i * i <= n ; i += 2 ) if ( ! check [ i ] ) { for ( j = i * i ; j <= n ; j += 2 * i ) check [ j ] = true ; } prime . push ( 2 ) ; for ( i = 3 ; i <= n ; i += 2 ) if ( ! check [ i ] ) prime . push ( i ) ; return ; } function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function count ( a , n , m ) { let parity = new Array ( 3 ) ; for ( let i = 0 ; i < 3 ; i ++ ) parity [ i ] = 0 ; for ( let i = 1 ; i < ( 1 << n ) ; i ++ ) { let mult = 1 ; for ( let j = 0 ; j < n ; j ++ ) if ( ( i & ( 1 << j ) ) != 0 ) mult *= a [ j ] ; parity [ countSetBits ( i ) & 1 ] += ( m / mult ) ; } return parity [ 1 ] - parity [ 0 ] ; } function countRelPrime ( n , m ) { let a = new Array ( 20 ) ; let i = 0 , j = 0 ; let pz = prime . length ; while ( n != 1 && i < pz ) { if ( prime [ i ] * prime [ i ] > n ) break ; if ( n % prime [ i ] == 0 ) { a [ j ] = prime [ i ] ; j ++ ; } while ( n % prime [ i ] == 0 ) n = Math . floor ( n / prime [ i ] ) ; i ++ ; } if ( n != 1 ) { a [ j ] = n ; j ++ ; } return m - count ( a , j , m ) ; } function countRelPrimeInRange ( n , l , r ) { sieve ( Math . floor ( Math . sqrt ( maxN ) ) ) ; let result = countRelPrime ( n , r ) - countRelPrime ( n , l - 1 ) ; document . write ( result ) ; } let N = 7 , L = 3 , R = 9 ; countRelPrimeInRange ( N , L , R ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, mult
Iterator variables: i, j
Javascript program:
function find_Xor ( arr , query , N , Q ) { for ( var i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i ] ^ arr [ i - 1 ] ; } var ans = 0 ; for ( var i = 0 ; i < Q ; i ++ ) { if ( query [ i ] [ 0 ] == 0 ) ans = arr [ query [ i ] [ 1 ] ] ; else ans = arr [ query [ i ] [ 0 ] - 1 ] ^ arr [ query [ i ] [ 1 ] ] ; document . write ( ans + " " ) ; } } var arr = [ 3 , 2 , 4 , 5 , 1 , 1 , 5 , 3 ] ; var N = 8 ; var Q = 2 ; var query = [ [ 1 , 4 ] , [ 3 , 7 ] ] ; find_Xor ( arr , query , N , Q ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function DiStirngMatch ( Str ) { var N = Str . length ; var arr = Array ( N ) . fill ( 0 ) ; var START = 0 , END = N ; for ( var i = 0 ; i < N ; i ++ ) { if ( Str [ i ] == ' ' ) arr [ i ] = START ++ ; if ( Str [ i ] == ' ' ) arr [ i ] = END -- ; } arr [ N ] = START ; return arr ; } var Str = " " ; var N = Str . length ; var ptr = DiStirngMatch ( Str ) ; for ( var i = 0 ; i <= N ; i ++ ) document . write ( ptr [ i ] + " " ) ;

Index/key variables: N, i
Accumulator variables: END, START, i
Iterator variables: i
Javascript program:
function IsPrime ( i ) { if ( i % 2 == 0 && i != 2 ) return false ; else { for ( j = 3 ; j <= Math . sqrt ( i ) ; j += 2 ) { if ( i % j == 0 ) return false ; } return true ; } } var c = 0 ; var N = 72 ; for ( i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( IsPrime ( i ) ) { if ( N % i == 0 ) { c ++ ; if ( IsPrime ( N / i ) && i != ( N / i ) ) c ++ ; } } } document . write ( Math . pow ( 2 , c ) - 1 ) ;

Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function find_seq ( arr , m , n ) { let b = new Array ( n ) ; let x = 0 ; b [ 0 ] = x ; for ( let i = 0 ; i < n - 1 ; i ++ ) { b [ i + 1 ] = x + arr [ i ] + b [ i ] ; } let mn = n ; for ( let i = 0 ; i < n ; i ++ ) { mn = Math . min ( mn , b [ i ] ) ; } x = 1 - mn ; for ( let i = 0 ; i < n ; i ++ ) { b [ i ] += x ; } for ( let i = 0 ; i < n ; i ++ ) { document . write ( b [ i ] + " " ) ; } document . write ( " " ) ; } let N = 3 ; let arr = [ - 2 , 1 ] ; let M = arr . length ; find_seq ( arr , M , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isEqualFactors ( N ) { let ev_count = 0 , od_count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) { if ( i == N / i ) { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } else { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; if ( ( N / i ) % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } } } if ( ev_count == od_count ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let N = 10 ; isEqualFactors ( N ) ;

Accumulator variables: ev_count, i, od_count
Iterator variables: i
Javascript program:
function count_crazy_primes ( L , R ) { let prime = Array . from ( { length : R + 1 } , ( _ , i ) => 0 ) ; let countPrime = Array . from ( { length : R + 1 } , ( _ , i ) => - 1 ) ; let freqPrime = Array . from ( { length : R + 1 } , ( _ , i ) => 0 ) ; prime [ 0 ] = 1 ; prime [ 1 ] = 1 ; for ( let p = 2 ; p * p <= R ; p ++ ) { if ( prime [ p ] == 0 ) { for ( let i = p * p ; i <= R ; i += p ) prime [ i ] = 1 ; } } for ( let i = 1 ; i <= R ; i ++ ) { countPrime [ i ] = countPrime [ i - 1 ] ; if ( prime [ i ] != 0 ) { countPrime [ i ] ++ ; } } for ( let i = 1 ; i <= R ; i ++ ) { freqPrime [ i ] = freqPrime [ i - 1 ] ; if ( ! prime [ countPrime [ i ] ] ) { freqPrime [ i ] ++ ; } } return ( freqPrime [ R ] - freqPrime [ L - 1 ] ) ; } let L = 4 , R = 12 ; document . write ( count_crazy_primes ( L , R ) ) ;

Index/key variables: R, i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function maximizedArray ( arr , N ) { let num , i = 0 ; for ( let l = N ; l > 0 ; l -- ) { num = arr [ i ] ; let one = 0 ; let zero = 0 ; while ( num != 0 ) { if ( num % 2 == 0 ) { zero ++ ; } else { one ++ ; } num = num >> 1 ; } for ( let j = zero ; j < ( one + zero ) ; j ++ ) { num += ( 1 << j ) ; } document . write ( num ) ; i ++ ; if ( N > 0 ) document . write ( " " ) ; } } let arr = [ 8 , 15 , 9 , 10 , 14 ] ; let N = arr . length ; maximizedArray ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, j, l, num, one, zero
Iterator variables: j, l
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function findGCD ( arr , n ) { var gcd = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) { gcd = __gcd ( arr [ i ] , gcd ) ; if ( gcd == 1 ) { return 1 ; } } return gcd ; } function findLCM ( arr , n ) { var lcm = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) { lcm = ( ( ( arr [ i ] * lcm ) ) / ( __gcd ( arr [ i ] , lcm ) ) ) ; } return lcm ; } function findRatio ( arr , n ) { var gcd = findGCD ( arr , n ) ; var lcm = findLCM ( arr , n ) ; document . write ( ( lcm / gcd ) ) ; document . write ( " " ) ; } var arr = [ 6 , 12 , 36 ] ; var N = 3 ; findRatio ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function compute ( a , N , K ) { let eqVal = new Map ( ) ; let maxX = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let val = a [ i ] % K ; val = ( val == 0 ? 0 : K - val ) ; if ( val == 0 ) continue ; if ( eqVal . has ( val ) ) { let numVal = eqVal . get ( val ) ; maxX = Math . max ( maxX , val + ( K * numVal ) ) ; eqVal . set ( val , eqVal . get ( val ) + 1 ) ; } else { eqVal . set ( val , 1 ) ; maxX = Math . max ( maxX , val ) ; } } document . write ( maxX == 0 ? 0 : maxX + 1 ) ; } let K = 3 ; let a = [ 1 , 2 , 2 , 18 ] ; let N = a . length ; compute ( a , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfTheArrayForQuery ( A , N , X , Y , Q ) { var sum = 0 ; var count = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; if ( count . has ( A [ i ] ) ) count . set ( A [ i ] , count . get ( A [ i ] ) + 1 ) else count . set ( A [ i ] , 1 ) } for ( var i = 0 ; i < Q ; i ++ ) { var x = X [ i ] , y = Y [ i ] ; if ( count . has ( X [ i ] ) ) { sum -= count . get ( X [ i ] ) * X [ i ] ; sum += count . get ( X [ i ] ) * Y [ i ] ; } if ( count . has ( Y [ i ] ) ) { count . set ( Y [ i ] , count . get ( Y [ i ] ) + count . get ( X [ i ] ) ) ; } count . set ( X [ i ] , 0 ) ; document . write ( sum + " " ) ; } } var arr = [ 1 , 2 , 1 , 3 , 2 ] ; var X = [ 2 , 3 , 5 ] ; var Y = [ 3 , 1 , 2 ] ; var N = arr . length ; var Q = X . length ; sumOfTheArrayForQuery ( arr , N , X , Y , Q ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function maxOR ( arr , n ) { let max_value = Math . max ( ... arr ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , ( max_value arr [ i ] ) ) ; } return ans ; } let arr = [ 3 , 6 , 8 , 16 ] ; let n = 4 ; document . write ( maxOR ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function IncrementFactors ( count , val ) { for ( let i = 1 ; i * i <= val ; i ++ ) { if ( val % i == 0 ) { if ( i == parseInt ( val / i ) ) { count [ i ] ++ ; } else { count [ i ] ++ ; count [ parseInt ( val / i ) ] ++ ; } } } } function generateArr ( A , n ) { let B = new Array ( n ) ; let maxi = Math . max ( ... A ) ; let count = new Array ( maxi + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { B [ i ] = count [ A [ i ] ] ; IncrementFactors ( count , A [ i ] ) ; } printArr ( B , n ) ; } let arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] ; let n = arr . length ; generateArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function SieveOfEratosthenes ( n ) { let prime = new Array ( 2 * n + 1 ) ; prime . fill ( true ) for ( let p = 2 ; p * p <= 2 * n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= 2 * n ; i += p ) prime [ i ] = false ; } } let primes = new Array ( ) ; for ( let p = 2 ; p <= 2 * n ; p ++ ) if ( prime [ p ] ) primes . push ( p ) ; return primes ; } function minChanges ( arr ) { let n = arr . length ; let ans = 0 ; let maxi = arr . sort ( ( a , b ) => b - a ) [ 0 ] ; let primes = SieveOfEratosthenes ( maxi ) ; for ( let i = 0 ; i < n ; i ++ ) { let x = - 1 for ( let j = 0 ; j < primes . length ; j ++ ) { if ( arr [ i ] == primes [ j ] ) { x = j break } else if ( arr [ i ] < primes [ j ] ) { x = j break } } let minm = Math . abs ( primes [ x ] - arr [ i ] ) ; if ( x > 1 ) { minm = Math . min ( minm , Math . abs ( primes [ x - 1 ] - arr [ i ] ) ) ; } ans += minm ; } return ans ; } let arr = [ 4 , 25 , 13 , 6 , 20 ] ; document . write ( minChanges ( arr ) ) ;

Index/key variables: i, j, p, x
Accumulator variables: ans, i, j, p
Iterator variables: i, j, p