dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function minSubarrays ( arr , n ) { var right = n - 1 ; var left = 0 ; var subarrays = 0 ; while ( right >= 0 ) { for ( left = 0 ; left <= right ; left += 1 ) { if ( __gcd ( arr [ left ] , arr [ right ] ) > 1 ) { subarrays += 1 ; right = left - 1 ; break ; } if ( left == right && __gcd ( arr [ left ] , arr [ right ] ) == 1 ) { return 0 ; } } } return subarrays ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var N = 6 ; var arr = [ 2 , 3 , 4 , 4 , 4 , 3 ] ; document . write ( minSubarrays ( arr , N ) ) ;

Index/key variables: left, right
Accumulator variables: left, subarrays
Iterator variables: left
Javascript program:
function findMaxSoln ( n , x , y ) { var ans = - 1000000000 ; for ( var k = 0 ; k <= n ; k ++ ) { if ( k % x == y ) { ans = Math . max ( ans , k ) ; } } return ( ( ans >= 0 && ans <= n ) ? ans : - 1 ) ; } var n = 15 , x = 10 , y = 5 ; document . write ( findMaxSoln ( n , x , y ) ) ;

Accumulator variables: k
Iterator variables: k
Javascript program:
function getCount ( N , M ) { let total_count = 0 total_count += Math . floor ( N / 10 ) let x = Math . floor ( N / 10 ) * 10 if ( ( N - x ) >= M ) { total_count = total_count + 1 } return total_count } let N = 100 let M = 1 document . write ( getCount ( N , M ) )

Accumulator variables: total_count
Javascript program:
function RightAngled ( a , n ) { var xpoints = { } ; var ypoints = { } ; for ( var i = 0 ; i < n ; i ++ ) { if ( xpoints . hasOwnProperty ( a [ i ] [ 0 ] ) ) { xpoints [ a [ i ] [ 0 ] ] = xpoints [ a [ i ] [ 0 ] ] + 1 ; } else { xpoints [ a [ i ] [ 0 ] ] = 1 ; } if ( ypoints . hasOwnProperty ( a [ i ] [ 1 ] ) ) { ypoints [ a [ i ] [ 1 ] ] = ypoints [ a [ i ] [ 1 ] ] + 1 ; } else { ypoints [ a [ i ] [ 1 ] ] = 1 ; } } var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( xpoints [ a [ i ] [ 0 ] ] >= 1 && ypoints [ a [ i ] [ 1 ] ] >= 1 ) { count += ( xpoints [ a [ i ] [ 0 ] ] - 1 ) * ( ypoints [ a [ i ] [ 1 ] ] - 1 ) ; } } return count ; } var N = 5 ; var arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 2 , 2 ] , [ 2 , 3 ] , [ 3 , 2 ] , ] ; document . write ( RightAngled ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function printArray ( brr ) { for ( let it of brr ) { document . write ( it + ' ' ) ; } } function RepeatingSubarray ( arr , N ) { if ( N < 2 ) { document . write ( " " ) ; } let brr = [ ] ; brr . push ( arr [ 0 ] ) ; brr . push ( arr [ 1 ] ) ; for ( let i = 2 ; i < Math . floor ( N / 2 ) + 1 ; i ++ ) { if ( N % i == 0 ) { let a = false ; let n = brr . length ; let j = i ; while ( j < N ) { let K = j % i ; if ( arr [ j ] == brr [ K ] ) { j ++ ; } else { a = true ; break ; } } if ( ! a && j == N ) { printArray ( brr ) ; return ; } } brr . push ( arr [ i ] ) ; } document . write ( " " ) ; return ; } let arr = [ 1 , 2 , 2 , 1 , 2 , 2 , 1 , 2 , 2 ] ; let N = arr . length ; RepeatingSubarray ( arr , N ) ;

Index/key variables: K, i, j
Accumulator variables: i, j
Iterator variables: i, it
Boolean variables: a
Javascript program:
function prletMissingElements ( arr , N ) { let diff = arr [ 0 ] - 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] - i != diff ) { while ( diff < arr [ i ] - i ) { document . write ( ( i + diff ) + " " ) ; diff ++ ; } } } } let arr = [ 6 , 7 , 10 , 11 , 13 ] ; let N = arr . length ; prletMissingElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: diff, i
Iterator variables: i
Javascript program:
function printMissingElements ( arr , N ) { let b = new Uint8Array ( arr [ N - 1 ] + 1 ) ; for ( let i = 0 ; i < N ; i ++ ) { b [ arr [ i ] ] = 1 ; } for ( let i = arr [ 0 ] ; i <= arr [ N - 1 ] ; i ++ ) { if ( b [ i ] == 0 ) { document . write ( i + " " ) ; } } } let arr = [ 6 , 7 , 10 , 11 , 13 ] ; let N = arr . length ; printMissingElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallestCommon ( a , b , c , d ) { if ( a == c ) return a ; if ( a > c ) { swap ( a , c ) ; swap ( b , d ) ; } let first_term_diff = ( c - a ) ; let possible_y ; for ( possible_y = 0 ; possible_y < b ; possible_y ++ ) { if ( ( first_term_diff % b + possible_y * d ) % b == 0 ) { break ; } } if ( possible_y != b ) { return c + possible_y * d ; } return - 1 ; } function swap ( x , y ) { let temp = x ; x = y ; y = temp ; } let A = 2 , B = 20 , C = 19 , D = 9 ; document . write ( smallestCommon ( A , B , C , D ) ) ;

Accumulator variables: possible_y
Iterator variables: possible_y
Javascript program:
function MinimumFlips ( s , n ) { let a = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = ( s [ i ] == ' ' ? 1 : 0 ) ; } let oddone = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; let evenone = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; oddone [ 0 ] = 0 ; evenone [ 0 ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) { oddone [ i + 1 ] = oddone [ i ] + ( a [ i ] == 1 ? 1 : 0 ) ; evenone [ i + 1 ] = evenone [ i ] + ( a [ i ] == 0 ? 1 : 0 ) ; } else { oddone [ i + 1 ] = oddone [ i ] + ( a [ i ] == 0 ? 1 : 0 ) ; evenone [ i + 1 ] = evenone [ i ] + ( a [ i ] == 1 ? 1 : 0 ) ; } } let minimum = Math . min ( oddone [ n ] , evenone [ n ] ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( n % 2 != 0 ) { minimum = Math . min ( minimum , oddone [ n ] - oddone [ i + 1 ] + evenone [ i + 1 ] ) ; minimum = Math . min ( minimum , evenone [ n ] - evenone [ i + 1 ] + oddone [ i + 1 ] ) ; } } return minimum ; } let S = " " ; let n = S . length ; document . write ( MinimumFlips ( S , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function isprm ( n ) { if ( n <= 1 ) return 0 ; if ( n <= 3 ) return 1 ; if ( n % 2 == 0 n % 3 == 0 ) return 0 ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return 0 ; return 1 ; } function shortestpath ( m , n ) { let mfactor = new Array ( ) let nfactor = new Array ( ) let fre = new Map ( ) ; mfactor . push ( m ) ; fre [ m ] = 1 ; while ( m != 1 ) { if ( isprm ( m ) ) { mfactor . push ( 1 ) ; fre [ 1 ] = 1 ; m = 1 ; } else { for ( let i = 2 ; i <= Math . sqrt ( m ) ; i ++ ) { if ( m % i == 0 ) { mfactor . push ( m / i ) ; fre [ m / i ] = 1 ; m = ( m / i ) ; break ; } } } } nfactor . push ( n ) ; while ( fre [ n ] != 1 ) { if ( isprm ( n ) ) { nfactor . push ( 1 ) ; n = 1 ; } else { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { nfactor . push ( n / i ) ; n = ( n / i ) ; break ; } } } } for ( let i = 0 ; i < mfactor . length ; i ++ ) { if ( mfactor [ i ] == n ) break ; document . write ( mfactor [ i ] + " " ) ; } for ( let i = nfactor . length - 1 ; i >= 0 ; i -- ) { if ( i == 0 ) document . write ( nfactor [ i ] ) ; else document . write ( nfactor [ i ] + " " ) ; } } let m = 18 , n = 19 ; shortestpath ( m , n ) ;

Index/key variables: i, m, n
Accumulator variables: i
Iterator variables: i
Javascript program:
let mod = ( 1e9 + 7 ) ; function NumberOfTrees ( arr , N ) { let maxElement = Math . max ( ... arr ) ; let level = Array . from ( { length : maxElement + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { level [ arr [ i ] ] ++ ; } if ( arr [ 0 ] != 0 level [ 0 ] != 1 ) { return 0 ; } let ans = 1 ; for ( let i = 0 ; i < maxElement ; i ++ ) { for ( let j = 0 ; j < level [ i + 1 ] ; j ++ ) { ans = ( ans * level [ i ] ) % mod ; } } return ans ; } let N = 7 ; let arr = [ 0 , 3 , 2 , 1 , 2 , 2 , 1 ] ; document . write ( NumberOfTrees ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let mod = 1e9 + 7 ; function power ( x , y ) { if ( y == 0 ) return 1 ; let p = power ( x , y / 2 ) % mod ; p = ( p * p ) % mod ; if ( ( y & 1 ) != 0 ) p = ( x * p ) % mod ; return p ; } function NumberOfTrees ( arr , N ) { let maxElement = Math . max ( ... arr ) ; let level = Array ( maxElement + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { level [ arr [ i ] ] ++ ; } if ( arr [ 0 ] != 0 level [ 0 ] != 1 ) { return 0 ; } let ans = 1 ; for ( let i = 0 ; i < maxElement ; i ++ ) { ans = ( ans * power ( level [ i ] , level [ i + 1 ] ) ) % mod ; } return ans ; } let N = 7 ; let arr = [ 0 , 3 , 2 , 1 , 2 , 2 , 1 ] ; document . write ( NumberOfTrees ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function gameMax ( S ) { let N = S . length ; let list = [ ] ; let one = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { one ++ ; } else { if ( one != 0 ) { list . push ( one ) ; } one = 0 ; } } if ( one != 0 ) { list . push ( one ) ; } list . sort ( ) ; list . reverse ( ) ; let score_1 = 0 , score_2 = 0 ; for ( let i = 0 ; i < list . length ; i ++ ) { if ( list [ i ] % 2 == 1 ) { score_1 += list [ i ] ; } else { score_2 += list [ i ] ; } } if ( score_1 == score_2 ) return " " ; return ( score_1 > score_2 ) ? " " : " " ; } let S = " " ; document . write ( gameMax ( S ) ) ;

Index/key variables: i
Accumulator variables: i, one, score_1, score_2
Iterator variables: i
Javascript program:
function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } function carryCount ( num1 , num2 ) { let count = 0 ; while ( num2 != 0 ) { let carry = num1 & num2 ; num1 = num1 ^ num2 ; num2 = carry << 1 ; count += countSetBits ( num2 ) ; } return count ; } let A = 15 , B = 10 ; document . write ( carryCount ( A , B ) ) ;

Accumulator variables: count, setBits
Javascript program:
var Mod = 1000000007 ; function power ( X , Y , Mod ) { if ( Y == 0 ) return 1 ; var p = power ( X , Y / 2 , Mod ) % Mod ; p = ( p * p ) % Mod ; if ( Y & 1 ) { p = ( X * p ) % Mod ; } return p ; } function Inversefactorial ( N ) { if ( N <= 0 ) return 1 ; var fact = 1 ; for ( var i = 1 ; i <= N ; i ++ ) { fact = ( fact * i ) % Mod ; } return power ( fact , Mod - 2 , Mod ) ; } function factorial ( N ) { if ( N <= 0 ) return 1 ; var fact = 1 ; for ( var i = 1 ; i <= N ; i ++ ) { fact = ( fact * i ) % Mod ; } return fact ; } function nck ( N , K ) { var factN = factorial ( N ) ; var inv = Inversefactorial ( K ) ; var invFact = Inversefactorial ( N - K ) ; return ( ( ( factN * inv ) % Mod ) * invFact ) % Mod ; } function TotalWaYs ( N , M ) { if ( ( N + M ) % 3 != 0 ) return 0 ; var X = N - ( N + M ) / 3 ; var Y = M - ( N + M ) / 3 ; if ( X < 0 Y < 0 ) return 0 ; return nck ( X + Y , Y ) ; } var N = 3 , M = 3 ; document . write ( TotalWaYs ( N , M ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateProfit ( n , earnings , cost , e ) { let profit = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let earning_per_day = 0 ; let daily_spent_food = 0 ; if ( i == ( n - 1 ) ) { earning_per_day = earnings [ i ] * e ; profit = profit + earning_per_day ; break ; } if ( cost [ i ] < earnings [ i ] ) { earning_per_day = earnings [ i ] * e ; daily_spent_food = cost [ i ] * e ; profit = profit + earning_per_day - daily_spent_food ; } } document . write ( profit ) ; } let n = 4 ; let earnings = [ 1 , 8 , 6 , 7 ] ; let cost = [ 1 , 3 , 4 , 1 ] ; let e = 5 ; calculateProfit ( n , earnings , cost , e ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkEvenSum ( arr , N , size ) { var even_freq = 0 , odd_freq = 0 ; for ( var i = 0 ; i < size ; i ++ ) { if ( arr [ i ] & 1 ) odd_freq ++ ; else even_freq ++ ; } if ( even_freq >= N ) return true ; else { if ( odd_freq & 1 ) { var taken = odd_freq - 1 ; var req = N - taken ; if ( even_freq < req ) { return false ; } else return true ; } else { var taken = odd_freq ; var req = N - taken ; if ( even_freq < req ) { return false ; } else return true ; } } return false ; } var arr = [ 9 , 2 , 3 , 4 , 18 , 7 , 7 , 6 ] ; var size = arr . length ; var N = 5 ; if ( checkEvenSum ( arr , N , size ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: even_freq, i, odd_freq
Iterator variables: i
Javascript program:
function minOperations ( a , N ) { var num_of_ops1 , num_of_ops2 , sum ; num_of_ops1 = num_of_ops2 = sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( i % 2 == 0 && sum >= 0 ) { num_of_ops1 += ( 1 + Math . abs ( sum ) ) ; sum = - 1 ; } else if ( i % 2 == 1 && sum <= 0 ) { num_of_ops1 += ( 1 + Math . abs ( sum ) ) ; sum = 1 ; } } sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( i % 2 == 1 && sum >= 0 ) { num_of_ops2 += ( 1 + Math . abs ( sum ) ) ; sum = - 1 ; } else if ( i % 2 == 0 && sum <= 0 ) { num_of_ops2 += ( 1 + Math . abs ( sum ) ) ; sum = 1 ; } } return Math . min ( num_of_ops1 , num_of_ops2 ) ; } var arr = [ 3 , - 4 , 5 , 0 , 1 ] ; var N = arr . length ; document . write ( minOperations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, num_of_ops1, num_of_ops2, sum
Iterator variables: i
Javascript program:
function checkEquall ( arr , N ) { let sumEven = 0 , sumOdd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i % 2 == 1 ) sumOdd += arr [ i ] ; else sumEven += arr [ i ] ; } if ( sumEven == sumOdd ) return true ; else return false ; } let arr = [ 2 , 7 , 3 , 5 , 7 ] ; let N = arr . length ; if ( checkEquall ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sumEven, sumOdd
Iterator variables: i
Javascript program:
function isSumOfPower ( n ) { let isSum = Array ( n + 1 ) . fill ( 0 ) ; let perfectPowers = [ ] ; perfectPowers . push ( 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { isSum [ i ] = false ; } for ( let i = 2 ; i < ( n + 1 ) ; i ++ ) { if ( isSum [ i ] == true ) { perfectPowers . push ( i ) ; continue ; } for ( let j = i * i ; j > 0 && j < ( n + 1 ) ; j *= i ) { isSum [ j ] = true ; } } for ( let i = 0 ; i < perfectPowers . length ; i ++ ) { isSum [ perfectPowers [ i ] ] = false ; } for ( let i = 0 ; i < perfectPowers . length ; i ++ ) { for ( let j = i ; j < perfectPowers . length ; j ++ ) { let sum = perfectPowers [ i ] + perfectPowers [ j ] ; if ( sum < ( n + 1 ) ) isSum [ sum ] = true ; } } return isSum [ n ] ; } let n = 9 ; if ( isSumOfPower ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j, n, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function update ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] += ( i + 1 ) ; } } function check ( arr , N ) { let f = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let count = 0 ; for ( let j = 0 ; j < N ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { count ++ ; } } if ( count >= 2 ) { f = 1 ; break ; } } if ( f == 1 ) return true ; else return false ; } function incrementCount ( arr , N ) { let min = 0 ; while ( check ( arr , N ) != true ) { update ( arr , N ) ; min ++ ; } document . write ( min ) ; } let N = 3 ; let arr = [ 12 , 8 , 4 ] ; incrementCount ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, min
Iterator variables: i, j
Javascript program:
function checkPossible ( a ) { let even_no_count = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] % 2 == 0 ) even_no_count ++ ; } if ( a . length / 2 > even_no_count ) { document . write ( " " ) ; return ; } document . write ( " " ) ; let j = 0 ; for ( let i = 1 ; i < a . length ; i += 2 ) { if ( a [ i ] % 2 == 0 ) continue ; else { while ( j < a . length && a [ j ] % 2 != 0 ) j += 2 ; a [ i ] += a [ j ] ; a [ j ] = a [ i ] - a [ j ] ; a [ i ] -= a [ j ] ; } } for ( let i = 0 ; i < a . length ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let arr = [ 2 , 3 , 4 , 5 , 6 , 7 ] ; checkPossible ( arr ) ;

Index/key variables: i, j
Accumulator variables: even_no_count, i, j
Iterator variables: i
Javascript program:
function maxORminusXOR ( N ) { let MSB = Math . ceil ( Math . log ( N ) ) ; let M = 0 ; for ( let i = 0 ; i <= MSB ; i ++ ) M += ( 1 << i ) ; return M ; } let N = 10 ; document . write ( maxORminusXOR ( N ) ) ;

Accumulator variables: M, i
Iterator variables: i
Javascript program:
function canMake ( n , ar ) { if ( n == 1 ) return true ; else { if ( ar [ 0 ] < ar [ 1 ] ) { let i = 1 ; while ( i < n && ar [ i - 1 ] < ar [ i ] ) { i ++ ; } while ( i + 1 < n && ar [ i ] > ar [ i + 1 ] ) { i ++ ; } if ( i >= n - 1 ) return true ; else return false ; } else if ( ar [ 0 ] > ar [ 1 ] ) { let i = 1 ; while ( i < n && ar [ i - 1 ] > ar [ i ] ) { i ++ ; } while ( i + 1 < n && ar [ i ] < ar [ i + 1 ] ) { i ++ ; } if ( i >= n - 1 ) return true ; else return false ; } else { for ( let i = 2 ; i < n ; i ++ ) { if ( ar [ i - 1 ] <= ar [ i ] ) return false ; } return true ; } } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; if ( ! canMake ( n , arr ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check_length ( n ) { let ans = 0 ; while ( n != 0 ) { n = n >> 1 ; ans ++ ; } return ans ; } function check_ith_bit ( n , i ) { return ( n & ( 1 << ( i - 1 ) ) ) != 0 ? true : false ; } function no_of_flips ( n ) { let len = check_length ( n ) ; let ans = 0 ; let right = 1 ; let left = len ; while ( right < left ) { if ( check_ith_bit ( n , right ) != check_ith_bit ( n , left ) ) ans ++ ; left -- ; right ++ ; } return ans ; } let n = 12 ; document . write ( no_of_flips ( n ) ) ;

Accumulator variables: ans, left, right
Javascript program:
function check ( a , n ) { let ma = a [ 1 ] - a [ 0 ] ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] > a [ i - 1 ] && a [ i + 1 ] < a [ i ] ) || ( a [ i ] < a [ i - 1 ] && a [ i + 1 ] > a [ i ] ) ) ma = Math . max ( ma , Math . abs ( a [ i ] - a [ i + 1 ] ) ) ; else return false ; } document . write ( " " + ma ) ; document . write ( " " ) ; return true ; } let a = [ 1 , 2 , 1 , 5 , 0 , 7 , - 6 ] ; let n = a . length ; let wave = ( n - 1 ) / 2 ; if ( check ( a , n ) ) document . write ( " " + wave ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function largestString ( n , k , s ) { var deq = [ ] ; for ( var i = 0 ; i < n ; ++ i ) { while ( deq . length > 0 && deq [ deq . length - 1 ] < s [ i ] && k > 0 ) { deq . shift ( ) ; k -- ; } deq . push ( s [ i ] ) ; } var st = " " ; deq . forEach ( c => { st = st + c ; } ) ; return st ; } var n = 4 ; var k = 2 ; var sc = " " ; var result = largestString ( n , k , sc ) ; document . write ( result ) ;

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Javascript program:
function countSetBit ( n ) { var i = 0 ; var ans = 0 ; while ( ( 1 << i ) <= n ) { var k = 0 ; var change = 1 << i ; for ( var j = 0 ; j <= n ; j ++ ) { ans += k ; if ( change == 1 ) { k = ! k ; change = 1 << i ; } else { change -- ; } } i ++ ; } return ans ; } function countSetBits ( L , R ) { return Math . abs ( countSetBit ( R ) - countSetBit ( L - 1 ) ) ; } var L = 3 , R = 5 ; document . write ( " " + countSetBits ( L , R ) ) ;

Accumulator variables: ans, change, i, j
Iterator variables: j
Javascript program:
function countSetBits ( L , R ) { let count = 0 ; for ( let i = L ; i <= R ; i ++ ) { let n = i ; while ( n > 0 ) { count += ( n & 1 ) ; n = n >> 1 ; } } return count ; } let L = 3 , R = 5 ; document . write ( " " + countSetBits ( L , R ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countSetBits ( L , R ) { let count = 0 ; for ( let i = L ; i <= R ; i ++ ) { count = Number ( i . toString ( ) . split ( " " ) . sort ( ) ) ; } return count ; } let L = 3 , R = 5 ; document . write ( " " + countSetBits ( L , R ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countElement ( A , N , B , M , K ) { let cnt = 0 ; for ( let i = 0 ; i < M ; i ++ ) { let currentElement = B [ i ] ; for ( let j = 0 ; j < N ; j ++ ) { let diff = Math . abs ( currentElement - A [ j ] ) ; if ( diff <= K ) { cnt ++ ; break ; } } } document . write ( cnt ) ; } let A = [ 100 , 65 , 35 , 85 , 55 ] ; let B = [ 30 , 60 , 75 , 95 ] ; let K = 5 ; let N = A . length ; let M = B . length ; countElement ( A , N , B , M , K ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function createString ( N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( ' ' ) ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( ' ' ) ; } } let N = 4 ; createString ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubset ( A , flag ) { let n = A . length ; let sum = 0 ; if ( flag ) { for ( let i = 1 ; i < n ; i ++ ) A [ i ] = - A [ i ] ; } for ( let i = 1 ; i < n ; i ++ ) { if ( A [ i ] > 0 ) { sum += A [ i ] ; } } return sum ; } function findBest ( A ) { let x = maxSubset ( A , false ) ; let y = maxSubset ( A , true ) ; y = - y ; y += A [ 0 ] ; y = - y ; return Math . max ( x , y ) ; } let A = [ 1 , 10 , 4 , - 6 , 3 ] ; document . write ( findBest ( A ) + " " ) ;

Index/key variables: i
Accumulator variables: i, sum, y
Iterator variables: i
Javascript program:
function solve ( n , arr ) { var s = [ ' ' , ' ' , ' ' ] var ans = [ ] ; ans . push ( s . join ( " " ) ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( s . length - 1 >= arr [ i ] ) { var ch = s [ arr [ i ] ] ; if ( ch == ' ' ) ch = ' ' ; else ch = ' ' ; s [ arr [ i ] ] = ch ; } ans . push ( s . join ( " " ) ) ; } return ans ; } var arr = [ 2 , 0 , 3 ] ; var n = arr . length ; var ans = solve ( n , arr ) ; for ( var i = ans . length - 1 ; i >= 0 ; i -- ) { document . write ( ans [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSwaps ( A , n ) { A . sort ( ) ; let ind = 1 , res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( ind < n && A [ ind ] == A [ i ] ) ind ++ ; if ( ind < n && A [ ind ] > A [ i ] ) { res ++ ; ind ++ ; } if ( ind >= n ) break ; } return res ; } let A = [ 4 , 3 , 3 , 2 , 5 ] ; document . write ( countSwaps ( A , 5 ) ) ;

Index/key variables: i, ind
Accumulator variables: i, ind, res
Iterator variables: i
Javascript program:
function countSwaps ( A , n ) { var mp = new Map ( ) ; var max_frequency = 0 ; for ( var 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 ) ; max_frequency = Math . max ( max_frequency , mp . get ( A [ i ] ) ) ; } return n - max_frequency ; } var A = [ 6 , 5 , 4 , 3 , 2 , 1 ] ; document . write ( countSwaps ( A , 6 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function min_operation ( a , n ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i > 0 ) ans += Math . abs ( a [ i ] - a [ i - 1 ] ) ; else ans += Math . abs ( a [ i ] ) ; } return ans ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; document . write ( min_operation ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function FindMatrix ( n , m , x , y ) { var a , b , i , j ; if ( n * m == 1 ) { if ( x > y ) { document . write ( y ) ; } else { document . write ( x ) ; } return ; } a = Math . min ( x , y ) ; b = Math . min ( 2 * x , y ) - a ; var flag = true ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( flag ) document . write ( a + " " ) ; else document . write ( b + " " ) ; flag = ! flag ; } if ( ( ( n % 2 != 0 && m % 2 == 0 ) || ( n % 2 == 0 && m % 2 == 0 ) ) ) flag = ! flag ; document . write ( " " ) ; } } var N , M , X , Y ; N = 3 ; M = 3 ; X = 5 ; Y = 3 ; FindMatrix ( N , M , X , Y ) ;

Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function findCount ( Arr1 , Arr2 ) { let MAX = Math . max ( Math . max ( ... Arr1 ) , Math . max ( ... Arr2 ) ) ; let Count = Array . from ( { length : 2 * MAX + 1 } , ( _ , i ) => 0 ) ; let n = Arr1 . length , m = Arr2 . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let element = Arr1 [ i ] + Arr2 [ j ] ; Count [ element ] ++ ; } } for ( let i = 1 ; i <= 2 * MAX ; i ++ ) { if ( Count [ i ] > 0 ) { document . write ( i + " " + Count [ i ] + " " ) ; } } } let arr1 = [ 1 , 2 ] ; let arr2 = [ 1 , 2 , 1 ] ; findCount ( arr1 , arr2 ) ;

Index/key variables: element, i, j
Accumulator variables: i, j
Iterator variables: i, j