dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function mostvisitedsector ( N , A ) { var maxVisited = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < A . length - 1 ; i ++ ) { var start = A [ i ] % N ; var end = A [ i + 1 ] % N ; while ( start != end ) { if ( start == 0 ) { if ( mp . has ( N ) ) mp . set ( N , mp . get ( N ) + 1 ) ; else mp . set ( N , 1 ) ; if ( mp . get ( N ) > maxVisited ) { maxVisited = mp . get ( N ) ; } } else { if ( mp . has ( start ) ) mp . set ( start , mp . get ( start ) + 1 ) else mp . set ( start , 1 ) ; if ( mp . get ( start ) > maxVisited ) { maxVisited = mp . get ( start ) ; } } start = ( start + 1 ) % N ; } } var back = A [ A . length - 1 ] ; if ( mp . has ( back ) ) mp . set ( back , mp . get ( back ) + 1 ) else mp . set ( back , 1 ) ; if ( mp . get ( back ) > maxVisited ) { maxVisited = mp . get ( back ) ; } mp . forEach ( ( value , key ) => { if ( value == maxVisited ) { document . write ( key + " " ) ; } } ) ; } var N = 4 ; var arr = [ 1 , 2 , 1 , 2 ] ; mostvisitedsector ( N , arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxRectangle ( sequence , size ) { let X_Cord = [ ] ; let Y_Cord = [ ] ; for ( let i = 0 ; i < size ; i ++ ) { X_Cord [ i ] = sequence [ i ] [ 0 ] ; Y_Cord [ i ] = sequence [ i ] [ 1 ] ; } X_Cord . sort ( ) ; Y_Cord . sort ( ) ; let X_Max = 0 , Y_Max = 0 ; for ( let i = 0 ; i < size - 1 ; i ++ ) { X_Max = Math . max ( X_Max , X_Cord [ i + 1 ] - X_Cord [ i ] ) ; Y_Max = Math . max ( Y_Max , Y_Cord [ i + 1 ] - Y_Cord [ i ] ) ; } return X_Max * Y_Max ; } let point = [ [ - 2 , 0 ] , [ 2 , 0 ] , [ 4 , 0 ] , [ 4 , 2 ] ] ; let n = point . length ; document . write ( maxRectangle ( point , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkArrangement ( A1 , A2 , n , k ) { A1 . sort ( ) ; A2 . sort ( ) ; A2 . reverse ( ) ; let flag = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( A1 [ i ] + A2 [ i ] > k ) || ( A1 [ i ] + A2 [ i ] < k / 2 ) ) { flag = 1 ; break ; } } if ( flag == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } let arr1 = [ 1 , 3 , 4 , 5 ] ; let arr2 = [ 2 , 0 , 1 , 1 ] ; let K = 6 ; let N = arr1 . length ; checkArrangement ( arr1 , arr2 , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function MaxRearrngeSum ( A , B , N ) { A . sort ( ) ; B . sort ( ) ; B . reverse ( ) ; let maxSum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { maxSum += Math . abs ( A [ i ] - B [ i ] ) ; } return maxSum ; } let A = [ 1 , 2 , 2 , 4 , 5 ] ; let B = [ 5 , 5 , 5 , 6 , 6 ] ; let N = A . length ; document . write ( MaxRearrngeSum ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i, maxSum
Iterator variables: i
Javascript program:
function largestArea ( arr1 , n , arr2 , m ) { var end = 0 , start = 0 , i = 0 , j = 0 ; arr1 . sort ( ) ; arr2 . sort ( ) ; while ( i < n && j < m ) { if ( arr1 [ i ] == arr2 [ j ] ) { if ( start == 0 ) start = arr1 [ i ] ; else end = arr1 [ i ] ; i ++ ; j ++ ; } else if ( arr1 [ i ] > arr2 [ j ] ) j ++ ; else i ++ ; } if ( end == 0 start == 0 ) return 0 ; else return ( end - start ) ; } var arr1 = [ 1 , 2 , 4 ] ; var N = arr1 . length ; var arr2 = [ 1 , 3 , 4 ] ; var M = arr2 . length ; document . write ( largestArea ( arr1 , N , arr2 , M ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function count_pairs ( arr , brr , N , M , K ) { let i = 0 ; let j = 0 ; let cntPairs = 0 ; ( arr ) . sort ( function ( a , b ) { return a - b ; } ) ; ( brr ) . sort ( function ( a , b ) { return a - b ; } ) ; while ( i < N && j < M ) { if ( brr [ j ] - arr [ i ] > K ) { cntPairs += ( M - j ) ; i ++ ; } else { j ++ ; } } return cntPairs ; } let arr = [ 5 , 9 , 1 , 8 ] ; let brr = [ 10 , 12 , 7 , 4 , 2 , 3 ] ; let K = 3 ; let N = arr . length ; let M = brr . length ; document . write ( count_pairs ( arr , brr , N , M , K ) ) ;

Index/key variables: i, j
Accumulator variables: cntPairs, i, j
Javascript program:
function minHeapify ( brr , i , M ) { let left = 2 * i + 1 ; let right = 2 * i + 2 ; let smallest = i ; if ( left < M && brr [ left ] < brr [ smallest ] ) { smallest = left ; } if ( right < M && brr [ right ] < brr [ smallest ] ) { smallest = right ; } if ( smallest != i ) { let temp = brr [ i ] ; brr [ i ] = brr [ smallest ] ; brr [ smallest ] = temp ; minHeapify ( brr , smallest , M ) ; } } function merge ( arr , brr , N , M ) { for ( let i = 0 ; i < N ; ++ i ) { if ( arr [ i ] > brr [ 0 ] ) { let temp = arr [ i ] ; arr [ i ] = brr [ 0 ] ; brr [ 0 ] = temp ; minHeapify ( brr , 0 , M ) ; } } brr . sort ( ) ; } function printArray ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 2 , 23 , 35 , 235 , 2335 ] ; let brr = [ 3 , 5 ] ; let N = arr . length ; let M = brr . length ; merge ( arr , brr , N , M ) ; printArray ( arr , N ) ; printArray ( brr , M ) ;

Index/key variables: i, left, right, smallest
Accumulator variables: i
Iterator variables: i
Javascript program:
function rankLessThanK ( arr , k , n ) { let rank = 1 ; let position = 1 ; arr . sort ( ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( i == n - 1 arr [ i ] != arr [ i + 1 ] ) { rank = position ; if ( rank > k ) return position - 1 ; } position ++ ; } return n ; } let arr = [ 2 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; let K = 4 ; document . write ( rankLessThanK ( arr , K , N ) ) ;

Index/key variables: i
Accumulator variables: i, position
Iterator variables: i
Javascript program:
function minCost ( arr , n ) { if ( n == 1 ) { document . write ( 0 ) ; return ; } arr . sort ( ( a , b ) => a - b ) ; var raised = 1 / ( n - 1 ) ; var temp = Math . pow ( arr [ n - 1 ] , raised ) ; var r = Math . round ( temp ) + 1 ; var i , j , min_cost = 1000000000 ; var common_ratio = 1 ; for ( j = 1 ; j <= r ; j ++ ) { var curr_cost = 0 , prod = 1 ; for ( i = 0 ; i < n ; i ++ ) { curr_cost += Math . abs ( arr [ i ] - prod ) ; prod *= j ; if ( curr_cost >= min_cost ) break ; } if ( i == n ) { min_cost = Math . min ( min_cost , curr_cost ) ; common_ratio = j ; } } document . write ( min_cost + ' ' ) ; document . write ( common_ratio + ' ' ) ; } var N = 6 ; var arr = [ 1 , 11 , 4 , 27 , 15 , 33 ] ; minCost ( arr , N ) ;

Index/key variables: i
Accumulator variables: curr_cost, i, j, prod
Iterator variables: i, j
Javascript program:
const maxN = 10 function calculateFib ( fib , n ) { fib [ 0 ] = fib [ 1 ] = 1 ; for ( let x = 2 ; x < n ; x ++ ) { fib [ x ] = fib [ x - 1 ] + fib [ x - 2 ] ; } } function find_mth_bit ( n , m , fib ) { if ( n <= 1 ) { return n ; } let len_left = fib [ n - 2 ] ; let len_right = fib [ n - 1 ] ; if ( m <= len_left ) { return find_mth_bit ( n - 2 , len_left + 1 - m , fib ) ; } else { return find_mth_bit ( n - 1 , len_right + 1 - ( m - len_left ) , fib ) ; } } function find_mth_bitUtil ( n , m ) { let fib = new Array ( maxN ) ; calculateFib ( fib , maxN ) ; let ans = find_mth_bit ( n , m , fib ) ; document . write ( ans + " " ) ; } let n = 5 , m = 3 ; find_mth_bitUtil ( n , m ) ;

Index/key variables: x
Accumulator variables: x
Iterator variables: x
Javascript program:
function minAdjSwaps ( mat ) { var N = mat . length ; var cntZero = Array ( N ) . fill ( 0 ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = N - 1 ; j >= 0 && mat [ i ] [ j ] == 0 ; j -- ) { cntZero [ i ] ++ ; } } var cntSwaps = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( cntZero [ i ] < ( N - i - 1 ) ) { var First = i ; while ( First < N && cntZero [ First ] < ( N - i - 1 ) ) { First ++ ; } if ( First == N ) { return - 1 ; } while ( First > i ) { cntZero = swap ( cntZero , First , First - 1 ) ; First -- ; cntSwaps ++ ; } } } return cntSwaps ; } function swap ( arr , i , j ) { var temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } var mat = [ [ 0 , 0 , 2 ] , [ 3 , 1 , 0 ] , [ 4 , 0 , 0 ] ] ; document . write ( minAdjSwaps ( mat ) ) ;

Index/key variables: First, i, j
Accumulator variables: First, cntSwaps, i, j
Iterator variables: i, j
Javascript program:
function maxArea ( polet_x , polet_y , n , length , width ) { polet_x . sort ( ( a , b ) => a - b ) ; ; polet_y . sort ( ( a , b ) => a - b ) ; ; let dx = polet_x [ 0 ] ; let dy = polet_y [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { dx = Math . max ( dx , polet_x [ i ] - polet_x [ i - 1 ] ) ; dy = Math . max ( dy , polet_y [ i ] - polet_y [ i - 1 ] ) ; } dx = Math . max ( dx , ( length + 1 ) - polet_x [ n - 1 ] ) ; dy = Math . max ( dy , ( width + 1 ) - polet_y [ n - 1 ] ) ; document . write ( ( dx - 1 ) * ( dy - 1 ) ) ; } let length = 15 , width = 8 ; let n = 3 ; let polet_x = [ 3 , 11 , 8 ] ; let polet_y = [ 8 , 2 , 6 ] ; maxArea ( polet_x , polet_y , n , length , width ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function make_cuts ( arr , n , K ) { var ans = 0 ; var poss = [ ] ; var ce = 0 ; var co = 0 ; var x ; for ( x = 0 ; x < n - 1 ; x ++ ) { if ( arr [ x ] % 2 == 0 ) ce ++ ; else co ++ ; if ( ce == co && co > 0 && ce > 0 ) { poss . push ( Math . abs ( arr [ x ] - arr [ x + 1 ] ) ) ; } } poss . sort ( ) ; var i ; for ( i = 0 ; i < poss . length ; i ++ ) { if ( K >= poss [ i ] ) { ans ++ ; K -= poss [ i ] ; } else break ; } return ans ; } var N = 6 ; var K = 4 ; var arr = [ 1 , 2 , 5 , 10 , 15 , 20 ] ; document . write ( make_cuts ( arr , N , K ) ) ;

Index/key variables: i, x
Accumulator variables: K, ans, ce, co, i, x
Iterator variables: i, x
Javascript program:
function Arrange ( arr , n ) { let cost = 0 ; let index = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { index . set ( arr [ i ] , i ) } arr . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { if ( arr [ i ] > arr [ i + 1 ] + arr [ n - 1 ] ) { document . write ( " " ) ; return ; } else { cost += Math . abs ( index . get ( arr [ i ] ) - i ) ; } } else if ( i == n - 1 ) { if ( arr [ i ] > arr [ i - 1 ] + arr [ 0 ] ) { document . write ( " " ) ; return ; } else { cost += Math . abs ( index . get ( arr [ i ] ) - i ) ; } } else { if ( arr [ i ] > arr [ i - 1 ] + arr [ i + 1 ] ) { document . write ( " " ) ; return ; } else { cost += Math . abs ( index . get ( arr [ i ] ) - i ) ; } } } document . write ( cost ) ; return ; } let arr = [ 2 , 4 , 5 , 1 , 3 ] ; let N = arr . length ; Arrange ( arr , N ) ;

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Javascript program:
function XorSum ( A , B , N ) { var ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { ans = ans ^ ( A [ i ] + B [ j ] ) ; } } return ans ; } var A = [ 4 , 6 , 0 , 0 , 3 , 3 ] ; var B = [ 0 , 5 , 6 , 5 , 0 , 3 ] ; var N = A . length ; document . write ( XorSum ( A , B , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxDistinctChar ( s , n , k ) { var freq = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freq . has ( s [ i ] ) ) freq . set ( s [ i ] , freq . get ( s [ i ] ) + 1 ) else freq . set ( s [ i ] , 1 ) } var v = [ ] ; freq . forEach ( ( value , key ) => { v . push ( value ) ; } ) ; v . sort ( ) for ( var i = 0 ; i < v . length ; i ++ ) { var mn = Math . min ( v [ i ] - 1 , k ) ; v [ i ] -= mn ; k -= mn ; } if ( k > 0 ) { for ( var i = 0 ; i < v . length ; i ++ ) { var mn = Math . min ( v [ i ] , k ) ; v [ i ] -= mn ; k -= mn ; } } var res = 0 ; for ( var i = 0 ; i < v . length ; i ++ ) if ( v [ i ] == 1 ) res ++ ; return res ; } var S = " " ; var N = S . length ; var K = 1 ; document . write ( maxDistinctChar ( S , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, k, res
Iterator variables: i
Javascript program:
let primes = new Array ( ) ; function SieveOfEratosthenes ( ) { let prime = new Array ( 10005 ) ; prime . fill ( true ) ; for ( let p = 2 ; p * p <= 1000 ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= 1000 ; i += p ) prime [ i ] = false ; } } for ( let p = 2 ; p <= 1000 ; p ++ ) if ( prime [ p ] ) primes . push ( p ) ; } function generate ( n , k ) { let prod = new Array ( ) ; SieveOfEratosthenes ( ) ; let l = primes . length ; for ( let i = 0 ; i < l ; i ++ ) { for ( let j = i + 1 ; j < l ; j ++ ) { if ( primes [ i ] * primes [ j ] > 0 ) prod . push ( primes [ i ] * primes [ j ] ) ; } } prod . sort ( ( a , b ) => a - b ) let sum = 0 ; for ( let i = 0 ; i < k - 1 ; i ++ ) sum += prod [ i ] ; if ( sum > n ) document . write ( " " ) ; else { for ( let i = 0 ; i < k - 1 ; i ++ ) { document . write ( prod [ i ] + " " ) ; } document . write ( n - sum + " " ) ; } } let n = 52 , k = 5 ; generate ( n , k ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, p, sum
Iterator variables: i, j, p
Javascript program:
function findMaxValue ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; let ans = arr [ n - 1 ] ; let maxPossible = arr [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; -- i ) { if ( maxPossible > 0 ) { if ( arr [ i ] >= maxPossible ) { ans += ( maxPossible - 1 ) ; maxPossible = maxPossible - 1 ; } else { maxPossible = arr [ i ] ; ans += maxPossible ; } } } return ans ; } let arr = [ 4 , 4 , 1 , 5 ] ; let n = arr . length ; document . write ( findMaxValue ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Javascript program:
function maximizeFinalElement ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; if ( arr [ 0 ] != 1 ) arr [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] > 1 ) { arr [ i ] = arr [ i - 1 ] + 1 ; } } return arr [ n - 1 ] ; } let n = 4 ; let arr = [ 3 , 1 , 3 , 4 ] ; let max = maximizeFinalElement ( arr , n ) ; document . write ( max ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubMatSum ( mat ) { var n = mat . length ; var m = mat [ 0 ] . length ; var i , j ; var dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( m ) . fill ( 0 ) ) ; dp [ n - 1 ] [ m - 1 ] = mat [ n - 1 ] [ m - 1 ] ; var res = dp [ n - 1 ] [ m - 1 ] ; for ( i = m - 2 ; i >= 0 ; i -- ) { dp [ n - 1 ] [ i ] = mat [ n - 1 ] [ i ] + dp [ n - 1 ] [ i + 1 ] ; res = Math . max ( res , dp [ n - 1 ] [ i ] ) ; } for ( i = n - 2 ; i >= 0 ; i -- ) { dp [ i ] [ m - 1 ] = mat [ i ] [ m - 1 ] + dp [ i + 1 ] [ m - 1 ] ; res = Math . max ( res , dp [ i ] [ m - 1 ] ) ; } for ( i = n - 2 ; i >= 0 ; i -- ) { for ( j = m - 2 ; j >= 0 ; j -- ) { dp [ i ] [ j ] = mat [ i ] [ j ] + dp [ i ] [ j + 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j + 1 ] ; res = Math . max ( res , dp [ i ] [ j ] ) ; } } return res ; } var mat = [ [ - 6 , - 4 , - 1 ] , [ - 3 , 2 , 4 ] , [ 2 , 5 , 8 ] ] ; document . write ( maxSubMatSum ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function formAnInequality ( integers , inequalities ) { ( integers ) . sort ( function ( a , b ) { return a - b ; } ) ; let lowerIndex = 0 ; let higherIndex = integers . length - 1 ; let sb = " " ; for ( let ch = 0 ; ch < inequalities . length ; ch ++ ) { if ( inequalities [ ch ] == ' ' ) { sb += " " + ( integers [ lowerIndex ++ ] ) + " " + inequalities [ ch ] ; } else { sb += " " + ( integers [ higherIndex -- ] ) + " " + inequalities [ ch ] ; } } sb += " " + ( integers [ lowerIndex ] ) ; return sb ; } let integers = [ 2 , 5 , 1 , 0 ] ; let inequalities = [ ' ' , ' ' , ' ' ] ; let output = formAnInequality ( integers , inequalities ) ; document . write ( output ) ;

Index/key variables: ch, lowerIndex
Accumulator variables: ch, higherIndex, lowerIndex, sb
Iterator variables: ch
Javascript program:
function canMadeEqual ( A , B , n ) { A . sort ( ) ; B . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) if ( A [ i ] != B [ i ] ) return false ; return true ; } var A = [ 1 , 2 , 3 ] ; var B = [ 1 , 3 , 2 ] ; var n = A . length ; if ( canMadeEqual ( A , B , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxMinDifference ( arr , n , k ) { if ( k >= n - 1 ) return 0 ; arr . sort ( ( a , b ) => a - b ) ; let ans = arr [ n - 1 ] - arr [ 0 ] ; for ( let i = k , j = n - 1 ; i >= 0 ; -- i , -- j ) { ans = Math . min ( arr [ j ] - arr [ i ] , ans ) ; } return ans ; } let arr = [ 1 , 4 , 6 , 11 , 15 ] ; let N = arr . length ; let K = 3 ; document . write ( maxMinDifference ( arr , N , K ) ) ;

Index/key variables: i, j
Iterator variables: i
Javascript program:
function sortarray ( arr , N ) { if ( N == 3 ) document . write ( " " ) ; else if ( N % 4 == 0 N % 4 == 1 ) { document . write ( " " ) ; document . write ( Math . floor ( N / 2 ) + " " ) ; let k = 1 , l ; for ( l = 0 ; l < Math . floor ( N / 4 ) ; l ++ ) { document . write ( k + " " + ( k + 1 ) + " " + N + " " ) ; document . write ( k + 1 + " " + N + " " + ( N - 1 ) + " " ) ; k = k + 2 ; N = N - 2 ; } } else document . write ( " " ) ; } let N = 5 ; let arr = [ 5 , 4 , 3 , 2 , 1 ] ; sortarray ( arr , N ) ;

Accumulator variables: l
Iterator variables: l
Javascript program:
var MAX = 100005 ; function find_missing ( interval ) { var vis = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < interval . length ; ++ i ) { var start = interval [ i ] [ 0 ] ; var end = interval [ i ] [ 1 ] ; vis [ start ] ++ ; vis [ end + 1 ] -- ; } for ( var i = 1 ; i < MAX ; i ++ ) { vis [ i ] += vis [ i - 1 ] ; if ( ! vis [ i ] ) { document . write ( i + " " ) ; return ; } } } var interval = [ [ 0 , 14 ] , [ 86 , 108 ] , [ 22 , 30 ] , [ 5 , 17 ] ] ; find_missing ( interval ) ;

Index/key variables: i, start
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMissing ( interval ) { interval . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; let mx = 0 ; for ( let i = 0 ; i < interval . length ; ++ i ) { if ( interval [ i ] [ 0 ] > mx ) { document . write ( mx + " " ) ; return ; } else mx = Math . max ( mx , interval [ i ] [ 1 ] + 1 ) ; } document . write ( mx ) ; } let interval = [ [ 0 , 14 ] , [ 86 , 108 ] , [ 22 , 30 ] , [ 5 , 17 ] ] ; findMissing ( interval ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function build_num ( bit ) { let ans = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) if ( bit [ i ] > 0 ) ans += ( 1 << i ) ; return ans ; } function maximumOR ( arr , n , k ) { let bit = new Array ( 32 ) ; bit . fill ( 0 ) ; for ( let i = 31 ; i >= 0 ; i -- ) { if ( bit [ i ] == 0 && k > 0 ) { let temp = build_num ( bit ) ; let temp1 = temp ; let val = - 1 ; for ( let j = 0 ; j < n ; j ++ ) { if ( temp1 < ( temp arr [ j ] ) ) { temp1 = temp | arr [ j ] ; val = arr [ j ] ; } } if ( val != - 1 ) { k -- ; for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( val & ( 1 << j ) ) > 0 ) bit [ j ] ++ ; } } } } return build_num ( bit ) ; } let arr = [ 5 , 9 , 7 , 19 ] ; let k = 3 ; let n = arr . length ; document . write ( maximumOR ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j, k
Iterator variables: i, j
Javascript program:
function minBox ( arr , n ) { var box = n ; arr . sort ( ) ; var curr_box = 0 , next_box = 1 ; while ( curr_box < n && next_box < n ) { if ( arr [ curr_box ] < arr [ next_box ] ) { box -- ; curr_box ++ ; next_box ++ ; } else if ( arr [ curr_box ] == arr [ next_box ] ) next_box ++ ; } document . write ( box ) ; } var size = [ 1 , 2 , 3 ] ; var n = size . length ; minBox ( size , n ) ;

Index/key variables: curr_box, next_box
Accumulator variables: box, curr_box, next_box
Javascript program:
var head1 = null ; var head2 = null ; class node { constructor ( ) { this . data = 0 ; this . next = null ; } } function setData ( head ) { var tmp ; tmp = head ; while ( tmp != null ) { document . write ( tmp . data + " " ) ; tmp = tmp . next ; } } function getData ( head , num ) { temp = new node ( ) ; var tail = head ; temp . data = num ; temp . next = null ; if ( head == null ) { head = temp ; tail = temp ; } else { while ( tail != null ) { if ( tail . next == null ) { tail . next = temp ; tail = tail . next ; } tail = tail . next ; } } return head ; } function mergelists ( ) { tail = head1 ; while ( tail != null ) { if ( tail . next == null && head2 != null ) { tail . next = head2 ; break ; } tail = tail . next ; } return head1 ; } function sortlist ( ) { curr = head1 ; temp = head1 ; while ( curr . next != null ) { temp = curr . next ; while ( temp != null ) { if ( temp . data < curr . data ) { var t = temp . data ; temp . data = curr . data ; curr . data = t ; } temp = temp . next ; } curr = curr . next ; } } head1 = getData ( head1 , 4 ) ; head1 = getData ( head1 , 7 ) ; head1 = getData ( head1 , 5 ) ; head2 = getData ( head2 , 2 ) ; head2 = getData ( head2 , 1 ) ; head2 = getData ( head2 , 8 ) ; head2 = getData ( head2 , 1 ) ; head1 = mergelists ( ) ; sortlist ( ) ; setData ( head1 ) ;

Class/struct names: node
Javascript program:
function findMedian ( a , n ) { if ( n % 2 != 0 ) return a [ Math . floor ( n / 2 ) ] ; return ( a [ Math . floor ( ( n - 1 ) / 2 ) ] + a [ Math . floor ( n / 2 ) ] ) / 2.0 ; } function kStrongest ( arr , n , k ) { arr . sort ( ) ; let median = findMedian ( arr , n ) ; let diff = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { diff [ i ] = Math . abs ( median - arr [ i ] ) ; } let i = 0 , j = n - 1 ; while ( k > 0 ) { if ( diff [ i ] > diff [ j ] ) { document . write ( arr [ i ] + " " ) ; i ++ ; } else { document . write ( arr [ j ] + " " ) ; j -- ; } k -- ; } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let k = 3 ; let n = arr . length ; kStrongest ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function sorting_possible ( a , b , n ) { let sorted = true ; let type1 = 0 , type0 = 0 , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { sorted = false ; break ; } } for ( i = 0 ; i < n ; i ++ ) { if ( b [ i ] == 0 ) type0 ++ ; else type1 ++ ; } if ( sorted ) return true ; else if ( type1 == n type0 == n ) return false ; else return true ; } let a = [ 15 , 1 , 2 , 17 , 6 ] ; let b = [ 1 , 1 , 0 , 1 , 1 ] ; let n = a . length ; let res = sorting_possible ( a , b , n ) ; if ( res ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, type0, type1
Iterator variables: i
Boolean variables: sorted
Javascript program:
function maximizeval10 ( a , n , k ) { let increments = 0 ; let ans = 0 ; let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { ans += Math . floor ( a [ i ] / 10 ) ; if ( a [ i ] == 1000 ) continue ; else { v . push ( 10 - a [ i ] % 10 ) ; increments += ( 100 - ( Math . floor ( a [ i ] ) / 10 ) - 1 ) ; } } v . sort ( function ( a , b ) { return a - b ; } ) ; let sum = 0 ; for ( let i = 0 ; i < v . length ; i ++ ) { sum += v [ i ] ; if ( sum <= k ) { ans ++ ; } else break ; } if ( sum < k ) { let remaining = k - sum ; ans += Math . min ( increments , Math . floor ( remaining / 10 ) ) ; } document . write ( ans ) ; } let N = 4 ; let X = 6 ; let A = [ 4 , 8 , 8 , 8 ] ; maximizeval10 ( A , N , X ) ;

Index/key variables: i
Accumulator variables: ans, i, increments, sum
Iterator variables: i
Javascript program:
function partition ( arr , l , h ) { let pivot = arr [ l ] ; let i = l + 1 ; let j = h ; while ( i <= j ) { while ( i <= h && arr [ i ] < pivot ) { i ++ ; } while ( j > l && arr [ j ] > pivot ) { j -- ; } if ( i < j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i ++ ; j -- ; } else i ++ ; } arr [ l ] = arr [ j ] ; arr [ j ] = pivot ; return j ; } function sortArray ( arr , l , h ) { if ( l >= h ) return ; let pivot = partition ( arr , l , h ) ; sortArray ( arr , l , pivot - 1 ) ; sortArray ( arr , pivot + 1 , h ) ; } function findMaxIntervals ( start , end , n , R ) { let ans = 0 ; let prev = 0 ; let currActive = 0 ; let i = 0 ; let j = 0 ; if ( start [ 0 ] > 0 ) ans ++ ; while ( i < n && j < n ) { if ( start [ i ] < end [ j ] ) { i ++ ; currActive ++ ; } else if ( start [ i ] > end [ j ] ) { j ++ ; currActive -- ; } else { i ++ ; j ++ ; } if ( currActive == 0 ) { ans ++ ; } } if ( end [ n - 1 ] < R ) ans ++ ; return ans ; } let R , N ; R = 10 ; N = 3 ; let start = [ 2 , 5 , 8 ] ; let end = [ 3 , 9 , 10 ] ; sortArray ( start , 0 , N - 1 ) ; sortArray ( end , 0 , N - 1 ) ; document . write ( findMaxIntervals ( start , end , N , R ) ) ;

Index/key variables: i, j, l
Accumulator variables: ans, currActive, i, j