dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let fact = new Array ( 10 ) ; function ncr ( n , r ) { return ( fact [ n ] / fact [ r ] ) / fact [ n - r ] ; } function findSum ( arr , n ) { fact [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) fact [ i ] = i * fact [ i - 1 ] ; let mul = 0 ; for ( let i = 0 ; i <= n - 1 ; i ++ ) mul += Math . pow ( 2 , i ) * ncr ( n - 1 , i ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans += mul * arr [ i ] ; return ans ; } let arr = [ 1 , 1 ] ; let n = arr . length ; document . write ( findSum ( arr , n ) ) ;

Index/key variables: i, n, r
Accumulator variables: ans, i, mul
Iterator variables: i
Javascript program:
var R = 4 var C = 4 function countPaths ( maze ) { if ( maze [ 0 ] [ 0 ] == - 1 ) return 0 ; for ( var i = 0 ; i < R ; i ++ ) { if ( maze [ i ] [ 0 ] == 0 ) maze [ i ] [ 0 ] = 1 ; else break ; } for ( var i = 1 ; i < C ; i ++ ) { if ( maze [ 0 ] [ i ] == 0 ) maze [ 0 ] [ i ] = 1 ; else break ; } for ( var i = 1 ; i < R ; i ++ ) { for ( var j = 1 ; j < C ; j ++ ) { if ( maze [ i ] [ j ] == - 1 ) continue ; if ( maze [ i - 1 ] [ j ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i - 1 ] [ j ] ) ; if ( maze [ i ] [ j - 1 ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i ] [ j - 1 ] ) ; } } return ( maze [ R - 1 ] [ C - 1 ] > 0 ) ? maze [ R - 1 ] [ C - 1 ] : 0 ; } function numberOfPaths ( m , n ) { var path = 1 ; for ( var i = n ; i < ( m + n - 1 ) ; i ++ ) { path *= i ; path /= ( i - n + 1 ) ; } return path ; } function solve ( maze ) { var ans = numberOfPaths ( R , C ) - countPaths ( maze ) ; return ans ; } var maze = [ [ 0 , 0 , 0 , 0 ] , [ 0 , - 1 , 0 , 0 ] , [ - 1 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] ; document . write ( solve ( maze ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, path
Iterator variables: i, j
Javascript program:
let N = 4 ; function printSolution ( sol ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( sol [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function isSafe ( maze , x , y ) { if ( x >= 0 && x < N && y >= 0 && y < N && maze [ x ] [ y ] != 0 ) { return true ; } return false ; } function solveMaze ( maze ) { let sol = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] ; if ( solveMazeUtil ( maze , 0 , 0 , sol ) == false ) { document . write ( " " ) ; return false ; } printSolution ( sol ) ; return true ; } function solveMazeUtil ( maze , x , y , sol ) { if ( x == N - 1 && y == N - 1 ) { sol [ x ] [ y ] = 1 ; return true ; } if ( isSafe ( maze , x , y ) == true ) { sol [ x ] [ y ] = 1 ; for ( let i = 1 ; i <= maze [ x ] [ y ] && i < N ; i ++ ) { if ( solveMazeUtil ( maze , x + i , y , sol ) == true ) { return true ; } if ( solveMazeUtil ( maze , x , y + i , sol ) == true ) { return true ; } } sol [ x ] [ y ] = 0 ; return false ; } return false ; } let maze = [ [ 2 , 1 , 0 , 0 ] , [ 3 , 0 , 0 , 1 ] , [ 0 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 1 ] ] ; solveMaze ( maze ) ;

Index/key variables: i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var set = [ ] ; var prime = [ ] ; function isPrime ( x ) { var sqroot = Math . sqrt ( x ) ; var flag = true ; if ( x == 1 ) return false ; for ( var i = 2 ; i <= sqroot ; i ++ ) if ( x % i == 0 ) return false ; return true ; } function display ( ) { var length = set . length ; for ( var i = 0 ; i < length ; i ++ ) document . write ( set [ i ] + " " ) ; document . write ( " " ) ; } function primeSum ( total , N , S , index ) { if ( total == S && set . length == N ) { display ( ) ; return ; } if ( total > S index == prime . length ) return ; set . push ( prime [ index ] ) ; primeSum ( total + prime [ index ] , N , S , index + 1 ) ; set . pop ( ) ; primeSum ( total , N , S , index + 1 ) ; } function allPrime ( N , S , P ) { for ( var i = P + 1 ; i <= S ; i ++ ) { if ( isPrime ( i ) ) prime . push ( i ) ; } if ( prime . length < N ) return ; primeSum ( 0 , N , S , 0 ) ; } var S = 54 , N = 2 , P = 3 ; allPrime ( N , S , P ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function grayCodeUtil ( res , n , num ) { if ( n == 0 ) { res . push ( num [ 0 ] ) ; return ; } grayCodeUtil ( res , n - 1 , num ) ; num [ 0 ] = num [ 0 ] ^ ( 1 << ( n - 1 ) ) ; grayCodeUtil ( res , n - 1 , num ) ; } function grayCodes ( n ) { let res = [ ] ; let num = [ 0 ] ; grayCodeUtil ( res , n , num ) ; return res ; } let n = 3 ; let code = grayCodes ( n ) ; for ( let i = 0 ; i < code . length ; i ++ ) document . write ( code [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isParenthesis ( c ) { return ( ( c == ' ' ) || ( c == ' ' ) ) ; } function isValidString ( str ) { let cnt = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) cnt ++ ; else if ( str [ i ] == ' ' ) cnt -- ; if ( cnt < 0 ) return false ; } return ( cnt == 0 ) ; } function removeInvalidParenthesis ( str ) { if ( str . length == 0 ) return ; let visit = new Set ( ) ; let q = [ ] ; let temp ; let level = false ; q . push ( str ) ; visit . add ( str ) ; while ( q . length != 0 ) { str = q . shift ( ) ; if ( isValidString ( str ) ) { document . write ( str + " " ) ; level = true ; } if ( level ) continue ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( ! isParenthesis ( str [ i ] ) ) continue ; temp = str . substring ( 0 , i ) + str . substring ( i + 1 ) ; if ( ! visit . has ( temp ) ) { q . push ( temp ) ; visit . add ( temp ) ; } } } } let expression = " " ; removeInvalidParenthesis ( expression ) ; expression = " " ; removeInvalidParenthesis ( expression ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Boolean variables: level
Javascript program:
function printPairs ( a , n , x ) { let i ; let rem = new Array ( x ) ; for ( i = 0 ; i < x ; i ++ ) { rem [ i ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] < x ) { rem [ a [ i ] % x ] ++ ; } } for ( i = 1 ; i < x / 2 ; i ++ ) { if ( rem [ i ] > 0 && rem [ x - i ] > 0 ) { document . write ( " " + " " ) ; break ; } } if ( i >= x / 2 ) { if ( x % 2 == 0 ) { if ( rem [ x / 2 ] > 1 ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } else { if ( rem [ x / 2 ] > 0 && rem [ x - x / 2 ] > 0 ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } } } let A = [ 1 , 4 , 45 , 6 , 10 , 8 ] ; let n = 16 ; let arr_size = A . length ; printPairs ( A , arr_size , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function fact ( n ) { let ans = 1 ; for ( let i = 2 ; i <= n ; i ++ ) ans *= i ; return ans ; } function remainder ( n , a , p ) { let len = fact ( n ) ; let ans = 1 ; for ( let i = 1 ; i <= len ; i ++ ) ans = ( ans * a ) % p ; return ans ; } let A = 2 , N = 1 , P = 2 ; document . write ( remainder ( N , A , P ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function check ( n , w ) { var a = Array ( 105 ) . fill ( 0 ) ; var p = 0 ; while ( n > 0 ) { a [ p ++ ] = n % w ; n /= w ; n = parseInt ( n ) ; } var flag = true ; for ( i = 0 ; i <= 100 ; i ++ ) { if ( a [ i ] == 0 a [ i ] == 1 ) continue ; else if ( a [ i ] == w a [ i ] == w - 1 ) a [ i + 1 ] ++ ; else flag = false ; } return flag ; } var B = 3 , N = 7 ; if ( check ( N , B ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, n, p
Iterator variables: i
Boolean variables: flag
Javascript program:
var maxSize = 50 ; function matrix_product ( a , b ) { var c = Array . from ( Array ( 7 ) , ( ) => Array ( 7 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < 7 ; i ++ ) for ( var j = 0 ; j < 7 ; j ++ ) for ( var k = 0 ; k < 7 ; k ++ ) c [ i ] [ j ] += a [ i ] [ k ] * b [ k ] [ j ] ; return c ; } function mul_expo ( mul , p ) { var s = [ [ 1 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ] ; while ( p != 1 ) { if ( p % 2 == 1 ) s = matrix_product ( s , mul ) ; mul = matrix_product ( mul , mul ) ; p = parseInt ( p / 2 ) ; } return matrix_product ( mul , s ) ; } function expectedSteps ( x ) { if ( x == 0 ) return 0 ; if ( x <= 6 ) return 6 ; var mul = [ [ 7 / 6 , 1 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 ] , [ - 1 / 6 , 0 , 0 , 0 , 0 , 0 , 0 ] ] ; mul = mul_expo ( mul , x - 6 ) ; return ( mul [ 0 ] [ 0 ] + mul [ 1 ] [ 0 ] + mul [ 2 ] [ 0 ] + mul [ 3 ] [ 0 ] + mul [ 4 ] [ 0 ] + mul [ 5 ] [ 0 ] ) * 6 ; } var n = 10 ; document . write ( expectedSteps ( n - 1 ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function canPlace ( a , n , p , sep ) { var prisoners_placed = 1 ; var last_prisoner_placed = a [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) { var current_cell = a [ i ] ; if ( current_cell - last_prisoner_placed >= sep ) { prisoners_placed ++ ; last_prisoner_placed = current_cell ; if ( prisoners_placed == p ) { return true ; } } } return false ; } function maxDistance ( cell , n , p ) { cell . sort ( ) ; var start = 0 ; var end = cell [ n - 1 ] - cell [ 0 ] ; var ans = 0 ; while ( start <= end ) { var mid = start + parseInt ( ( ( end - start ) / 2 ) ) ; if ( canPlace ( cell , n , p , mid ) ) { ans = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } return ans ; } var cell = [ 1 , 2 , 8 , 4 , 9 ] ; var n = cell . length ; var p = 3 ; document . write ( maxDistance ( cell , n , p ) ) ;

Index/key variables: i
Accumulator variables: i, prisoners_placed
Iterator variables: i
Javascript program:
let maxLen = 30 ; let seg = new Array ( 3 * maxLen ) ; function build ( l , r , In , arr ) { if ( l == r ) return seg [ In ] = arr [ l ] ; let mid = Math . floor ( ( l + r ) / 2 ) ; return seg [ In ] = __gcd ( build ( l , mid , 2 * In + 1 , arr ) , build ( mid + 1 , r , 2 * In + 2 , arr ) ) ; } function query ( l , r , l1 , r1 , In ) { if ( l1 <= l && r <= r1 ) return seg [ In ] ; if ( l > r1 r < l1 ) return 0 ; let mid = Math . floor ( ( l + r ) / 2 ) ; return __gcd ( query ( l , mid , l1 , r1 , 2 * In + 1 ) , query ( mid + 1 , r , l1 , r1 , 2 * In + 2 ) ) ; } function findLen ( arr , n ) { build ( 0 , n - 1 , 0 , arr ) ; let i = 0 , j = 0 ; let ans = Number . MAX_VALUE ; while ( i < n ) { while ( j < n && query ( 0 , n - 1 , i , j , 0 ) != 1 ) j ++ ; if ( j == n ) break ; ans = Math . min ( ( j - i + 1 ) , ans ) ; i ++ ; j = Math . max ( j , i ) ; } if ( ans == Number . MAX_VALUE ) return - 1 ; else return ans ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let arr = [ 2 , 2 , 2 ] ; let n = arr . length ; document . write ( findLen ( arr , n ) ) ;

Index/key variables: In, l
Accumulator variables: i, j
Javascript program:
function findGrid ( n ) { let arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = new Array ( n ) ; let x = 0 ; for ( let i = 0 ; i < parseInt ( n / 4 ) ; i ++ ) { for ( let j = 0 ; j < parseInt ( n / 4 ) ; j ++ ) { for ( let k = 0 ; k < 4 ; k ++ ) { for ( let l = 0 ; l < 4 ; l ++ ) { arr [ i * 4 + k ] [ j * 4 + l ] = x ; x ++ ; } } } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( arr [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let n = 4 ; findGrid ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j, k, l, x
Iterator variables: i, j, k, l
Javascript program:
var maxLen = 30 ; class node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } ; var segtree = Array ( maxLen * 4 ) . fill ( 0 ) ; function buildTree ( l , r , i , arr ) { if ( l == r ) { segtree [ i ] = l ; return l ; } var l1 = buildTree ( l , parseInt ( ( l + r ) / 2 ) , 2 * i + 1 , arr ) ; var r1 = buildTree ( parseInt ( ( l + r ) / 2 ) + 1 , r , 2 * i + 2 , arr ) ; if ( arr [ l1 ] > arr [ r1 ] ) segtree [ i ] = l1 ; else segtree [ i ] = r1 ; return segtree [ i ] ; } function rangeMax ( l , r , rl , rr , i , arr ) { if ( r < rl l > rr ) return - 1 ; if ( l >= rl && r <= rr ) return segtree [ i ] ; var l1 = rangeMax ( l , parseInt ( ( l + r ) / 2 ) , rl , rr , 2 * i + 1 , arr ) ; var r1 = rangeMax ( parseInt ( ( l + r ) / 2 ) + 1 , r , rl , rr , 2 * i + 2 , arr ) ; if ( l1 == - 1 ) return r1 ; if ( r1 == - 1 ) return l1 ; if ( arr [ l1 ] > arr [ r1 ] ) return l1 ; else return r1 ; } function inorder ( curr ) { if ( curr == null ) return ; inorder ( curr . left ) ; document . write ( curr . data + " " ) ; inorder ( curr . right ) ; } function createCartesianTree ( l , r , arr , n ) { if ( r < l ) return null ; var m = rangeMax ( 0 , n - 1 , l , r , 0 , arr ) ; var curr = new node ( arr [ m ] ) ; curr . left = createCartesianTree ( l , m - 1 , arr , n ) ; curr . right = createCartesianTree ( m + 1 , r , arr , n ) ; return curr ; } var arr = [ 8 , 11 , 21 , 100 , 5 , 70 , 55 ] ; var n = arr . length ; buildTree ( 0 , n - 1 , 0 , arr ) ; inorder ( createCartesianTree ( 0 , n - 1 , arr , n ) ) ;

Index/key variables: i, l1, m, r1
Class/struct names: node
Javascript program:
function kthSmallest ( arr , k , n ) { let temp = [ ... arr ] ; let low = temp . sort ( ( a , b ) => a - b ) [ 0 ] ; let high = temp [ temp . length - 1 ] ; while ( low <= high ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; let countless = 0 , countequal = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( arr [ i ] < mid ) ++ countless ; else if ( arr [ i ] == mid ) ++ countequal ; } if ( countless < k && ( countless + countequal ) >= k ) { return mid ; } else if ( countless >= k ) { high = mid - 1 ; } else if ( countless < k && countless + countequal < k ) { low = mid + 1 ; } } } let arr = [ 7 , 10 , 4 , 3 , 20 , 15 ] ; let n = arr . length ; let k = 3 ; document . write ( kthSmallest ( arr , k , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
var MAX = 1000 ; var tree = Array ( MAX ) . fill ( 0 ) ; var lazy = Array ( MAX ) . fill ( 0 ) ; function updateRangeUtil ( si , ss , se , us , ue , diff ) { if ( lazy [ si ] != 0 ) { tree [ si ] += lazy [ si ] ; if ( ss != se ) { lazy [ si * 2 + 1 ] += lazy [ si ] ; lazy [ si * 2 + 2 ] += lazy [ si ] ; } lazy [ si ] = 0 ; } if ( ss > se ss > ue se < us ) return ; if ( ss >= us && se <= ue ) { tree [ si ] += diff ; if ( ss != se ) { lazy [ si * 2 + 1 ] += diff ; lazy [ si * 2 + 2 ] += diff ; } return ; } var mid = parseInt ( ( ss + se ) / 2 ) ; updateRangeUtil ( si * 2 + 1 , ss , mid , us , ue , diff ) ; updateRangeUtil ( si * 2 + 2 , mid + 1 , se , us , ue , diff ) ; tree [ si ] = Math . max ( tree [ si * 2 + 1 ] , tree [ si * 2 + 2 ] ) ; } function updateRange ( n , us , ue , diff ) { updateRangeUtil ( 0 , 0 , n - 1 , us , ue , diff ) ; } function getSumUtil ( ss , se , qs , qe , si ) { if ( lazy [ si ] != 0 ) { tree [ si ] += lazy [ si ] ; if ( ss != se ) { lazy [ si * 2 + 1 ] += lazy [ si ] ; lazy [ si * 2 + 2 ] += lazy [ si ] ; } lazy [ si ] = 0 ; } if ( ss > se ss > qe se < qs ) return 0 ; if ( ss >= qs && se <= qe ) return tree [ si ] ; var mid = ( ss + se ) / 2 ; return Math . max ( getSumUtil ( ss , mid , qs , qe , 2 * si + 1 ) , getSumUtil ( mid + 1 , se , qs , qe , 2 * si + 2 ) ) ; } function getSum ( n , qs , qe ) { if ( qs < 0 qe > n - 1 qs > qe ) { document . write ( " " ) ; return - 1 ; } return getSumUtil ( 0 , n - 1 , qs , qe , 0 ) ; } function constructSTUtil ( arr , ss , se , si ) { if ( ss > se ) return ; if ( ss == se ) { tree [ si ] = arr [ ss ] ; return ; } var mid = parseInt ( ( ss + se ) / 2 ) ; constructSTUtil ( arr , ss , mid , si * 2 + 1 ) ; constructSTUtil ( arr , mid + 1 , se , si * 2 + 2 ) ; tree [ si ] = Math . max ( tree [ si * 2 + 1 ] , tree [ si * 2 + 2 ] ) ; } function constructST ( arr , n ) { constructSTUtil ( arr , 0 , n - 1 , 0 ) ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; constructST ( arr , n ) ; updateRange ( n , 0 , 3 , 4 ) ; document . write ( getSum ( n , 1 , 4 ) ) ;

Index/key variables: si, ss
Javascript program:
MOD = 1000000007 function rangeSum ( l , r ) { var a = 1 , b = 9 , res = 0 ; for ( var i = 1 ; i <= 10 ; i ++ ) { var L = Math . max ( l , a ) ; var R = Math . min ( r , b ) ; if ( L <= R ) { var sum = ( L + R ) * ( R - L + 1 ) / 2 ; res += ( i * i ) * ( sum % MOD ) ; res %= MOD ; } a = a * 10 ; b = b * 10 + 9 ; } return res ; } var l = 98 , r = 102 ; document . write ( rangeSum ( l , r ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
const INF = 99999 ; const size = 10 ; function getSetBitsFromOneToN ( N ) { let two = 2 , ans = 0 ; let n = N ; while ( n ) { ans += parseInt ( N / two ) * ( two >> 1 ) ; if ( ( N & ( two - 1 ) ) > ( two >> 1 ) - 1 ) ans += ( N & ( two - 1 ) ) - ( two >> 1 ) + 1 ; two <<= 1 ; n >>= 1 ; } return ans ; } function findMinimum ( x ) { let low = 0 , high = 100000 ; let ans = high ; while ( low <= high ) { let mid = ( low + high ) >> 1 ; if ( getSetBitsFromOneToN ( mid ) >= x ) { ans = Math . min ( ans , mid ) ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } let x = 20 ; document . write ( findMinimum ( x ) ) ;

Accumulator variables: ans
Javascript program:
function trailingZeroes ( n ) { var cnt = 0 ; while ( n > 0 ) { n = parseInt ( n / 5 ) ; cnt += n ; } return cnt ; } function binarySearch ( n ) { var low = 0 ; while ( low < high ) { var mid = parseInt ( ( low + high ) / 2 ) ; var count = trailingZeroes ( mid ) ; if ( count < n ) low = mid + 1 ; else high = mid ; } var result = [ ] ; while ( trailingZeroes ( low ) == n ) { result . push ( low ) ; low ++ ; } for ( var i = 0 ; i < result . length ; i ++ ) document . write ( result [ i ] + " " ) ; } var n = 2 ; binarySearch ( n ) ;

Index/key variables: i
Accumulator variables: cnt, i, low
Iterator variables: i
Javascript program:
function kth ( arr1 , arr2 , m , n , k ) { var sorted1 = Array ( m + n ) . fill ( 0 ) ; var i = 0 , j = 0 , d = 0 ; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; else sorted1 [ d ++ ] = arr2 [ j ++ ] ; } while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ; return sorted1 [ k - 1 ] ; } var arr1 = [ 2 , 3 , 6 , 7 , 9 ] ; var arr2 = [ 1 , 4 , 8 , 10 ] ; var k = 5 ; document . write ( kth ( arr1 , arr2 , 5 , 4 , k ) ) ;

Index/key variables: i, j
Accumulator variables: d, i, j
Javascript program:
let MAX = 100 ; function binarySearch ( mat , i , j_low , j_high , x ) { while ( j_low <= j_high ) { let j_mid = Math . floor ( ( j_low + j_high ) / 2 ) ; if ( mat [ i ] [ j_mid ] == x ) { document . write ( " " + i + " " + j_mid + " " ) ; return ; } else if ( mat [ i ] [ j_mid ] > x ) j_high = j_mid - 1 ; else j_low = j_mid + 1 ; } document . write ( " " ) ; } function sortedMatrixSearch ( mat , n , m , x ) { if ( n == 1 ) { binarySearch ( mat , 0 , 0 , m - 1 , x ) ; return ; } let i_low = 0 ; let i_high = n - 1 ; let j_mid = Math . floor ( m / 2 ) ; while ( ( i_low + 1 ) < i_high ) { let i_mid = Math . floor ( ( i_low + i_high ) / 2 ) ; if ( mat [ i_mid ] [ j_mid ] == x ) { document . write ( " " + i_mid + " " + j_mid + " " ) ; return ; } else if ( mat [ i_mid ] [ j_mid ] > x ) i_high = i_mid ; else i_low = i_mid ; } if ( mat [ i_low ] [ j_mid ] == x ) document . write ( " " + i_low + " " + j_mid + " " ) ; else if ( mat [ i_low + 1 ] [ j_mid ] == x ) document . write ( " " + ( i_low + 1 ) + " " + j_mid + " " ) ; else if ( x <= mat [ i_low ] [ j_mid - 1 ] ) binarySearch ( mat , i_low , 0 , j_mid - 1 , x ) ; else if ( x >= mat [ i_low ] [ j_mid + 1 ] && x <= mat [ i_low ] [ m - 1 ] ) binarySearch ( mat , i_low , j_mid + 1 , m - 1 , x ) ; else if ( x <= mat [ i_low + 1 ] [ j_mid - 1 ] ) binarySearch ( mat , i_low + 1 , 0 , j_mid - 1 , x ) ; else binarySearch ( mat , i_low + 1 , j_mid + 1 , m - 1 , x ) ; } let n = 4 , m = 5 , x = 8 ; let mat = [ [ 0 , 6 , 8 , 9 , 11 ] , [ 20 , 22 , 28 , 29 , 31 ] , [ 36 , 38 , 50 , 61 , 63 ] , [ 64 , 66 , 100 , 122 , 128 ] ] ; sortedMatrixSearch ( mat , n , m , x ) ;

Index/key variables: i, i_low, i_mid, j_mid
Javascript program:
let R = 2 ; let C = 2 ; function bsearch ( low , high , n , arr ) { let mid = ( low + high ) / 2 ; if ( low <= high ) { if ( arr [ mid ] < n ) return bsearch ( mid + 1 , high , n , arr ) ; return bsearch ( low , mid - 1 , n , arr ) ; } return low ; } function mindiff ( arr , n , m ) { for ( let i = 0 ; i < n ; i ++ ) arr . sort ( ) ; let ans = + 2147483647 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let p = bsearch ( 0 , m - 1 , arr [ i ] [ j ] , arr [ i + 1 ] ) ; ans = Math . min ( ans , Math . abs ( arr [ i + 1 ] [ p ] - arr [ i ] [ j ] ) ) ; if ( p - 1 >= 0 ) ans = Math . min ( ans , Math . abs ( arr [ i + 1 ] [ p - 1 ] - arr [ i ] [ j ] ) ) ; } } return ans ; } let m = [ [ 8 , 5 ] , [ 6 , 8 ] ] ; document . write ( mindiff ( m , R , C ) ) ;

Index/key variables: i, j, mid, p
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binarySearch ( arr , left , right ) { if ( left <= right ) { var mid = parseInt ( ( left + right ) / 2 ) ; if ( arr [ mid - 1 ] < arr [ mid ] && arr [ mid ] > arr [ mid + 1 ] ) return mid ; if ( arr [ mid ] < arr [ mid + 1 ] ) return binarySearch ( arr , mid + 1 , right ) ; else return binarySearch ( arr , left , mid - 1 ) ; } return - 1 ; } var arr = [ 6 , 7 , 8 , 11 , 9 , 5 , 2 , 1 ] ; var n = arr . length ; var index = binarySearch ( arr , 1 , n - 2 ) ; if ( index != - 1 ) document . write ( arr [ index ] ) ;

Index/key variables: index, mid
Javascript program:
function findRepeatingElement ( arr , low , high ) { if ( low > high ) return - 1 ; var mid = parseInt ( ( low + high ) / 2 ) ; if ( arr [ mid ] != mid + 1 ) { if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ; return findRepeatingElement ( arr , low , mid - 1 ) ; } return findRepeatingElement ( arr , mid + 1 , high ) ; } var arr = [ 1 , 2 , 3 , 3 , 4 , 5 ] ; var n = arr . length ; var index = findRepeatingElement ( arr , 0 , n - 1 ) ; if ( index != - 1 ) document . write ( arr [ index ] ) ;

Index/key variables: index, mid
Javascript program:
function findFrequencyUtil ( arr , low , high , freq ) { if ( arr [ low ] == arr [ high ] ) { freq [ arr [ low ] ] += high - low + 1 ; } else { let mid = Math . floor ( ( low + high ) / 2 ) ; findFrequencyUtil ( arr , low , mid , freq ) ; findFrequencyUtil ( arr , mid + 1 , high , freq ) ; } } function findFrequency ( arr , n ) { let freq = new Array ( arr [ n - 1 ] + 1 ) ; for ( let i = 0 ; i < arr [ n - 1 ] + 1 ; i ++ ) { freq [ i ] = 0 ; } findFrequencyUtil ( arr , 0 , n - 1 , freq ) ; for ( let i = 0 ; i <= arr [ n - 1 ] ; i ++ ) if ( freq [ i ] != 0 ) document . write ( " " + i + " " + freq [ i ] + " " ) ; } let arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ] ; let n = arr . length ; findFrequency ( arr , n ) ;

Index/key variables: high, i, low
Accumulator variables: i
Iterator variables: i
Javascript program:
function floorSqrt ( x ) { if ( x == 0 x == 1 ) return x ; let i = 1 ; let result = 1 ; while ( result <= x ) { i ++ ; result = i * i ; } return i - 1 ; } let x = 11 ; document . write ( floorSqrt ( x ) ) ;

Accumulator variables: i
Javascript program:
function maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) { let max_rectangles = 0 ; let X = [ ] , Y = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { X . push ( x1 [ i ] ) ; X . push ( x2 [ i ] - 1 ) ; Y . push ( y1 [ i ] ) ; Y . push ( y2 [ i ] - 1 ) ; } for ( let i = 0 ; i < X . length ; i ++ ) { for ( let j = 0 ; j < Y . length ; j ++ ) { let cnt = 0 ; for ( let k = 0 ; k < N ; k ++ ) { if ( X [ i ] >= x1 [ k ] && X [ i ] + 1 <= x2 [ k ] && Y [ j ] >= y1 [ k ] && Y [ j ] + 1 <= y2 [ k ] ) { cnt ++ ; } } max_rectangles = Math . max ( max_rectangles , cnt ) ; } } document . write ( max_rectangles ) ; } let x1 = [ 0 , 50 ] ; let y1 = [ 0 , 50 ] ; let x2 = [ 100 , 60 ] ; let y2 = [ 100 , 60 ] ; let N = x1 . length ; maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) ;

Index/key variables: i, j, k
Accumulator variables: cnt, i, j, k
Iterator variables: i, j, k