dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function xnor ( a , b ) { if ( a < b ) { let t = a ; a = b ; b = t ; } if ( a == 0 && b == 0 ) return 1 ; let a_rem = 0 ; let b_rem = 0 ; let count = 0 ; let xnornum = 0 ; while ( true ) { a_rem = a & 1 ; b_rem = b & 1 ; if ( a_rem == b_rem ) xnornum |= ( 1 << count ) ; count ++ ; a = a >> 1 ; b = b >> 1 ; if ( a < 1 ) break ; } return xnornum ; } let a = 10 , b = 50 ; document . write ( xnor ( a , b ) ) ;

Accumulator variables: count, xnornum
Javascript program:
function togglebit ( n ) { if ( n == 0 ) return 1 ; let i = n ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return i ^ n ; } function XNOR ( num1 , num2 ) { if ( num1 < num2 ) { let temp = num1 ; num1 = num2 ; num2 = temp ; } num1 = togglebit ( num1 ) ; return num1 ^ num2 ; } let num1 = 10 , num2 = 20 ; document . write ( XNOR ( num1 , num2 ) ) ;

Accumulator variables: n
Javascript program:
function MaximumSum ( a , b , n ) { let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum1 |= a [ i ] ; sum2 |= b [ i ] ; } document . write ( sum1 + sum2 ) ; } let A = [ 1 , 2 , 4 , 3 , 2 ] ; let B = [ 2 , 3 , 3 , 12 , 1 ] ; let n = A . length ; MaximumSum ( A , B , n ) ;

Index/key variables: i
Accumulator variables: i, sum1, sum2
Iterator variables: i
Javascript program:
function evenbittogglenumber ( n ) { let res = 0 , count = 0 ; for ( let temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return n ^ res ; } let n = 11 ; document . write ( evenbittogglenumber ( n ) ) ;

Accumulator variables: count, res
Iterator variables: temp
Javascript program:
function maxAND ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) res = Math . max ( res , arr [ i ] & arr [ j ] ) ; return res ; } var arr = [ 4 , 8 , 6 , 2 ] ; var n = arr . length ; document . write ( " " + maxAND ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function index ( i ) { return 1 + ( i >> 31 ) - ( - i >> 31 ) ; } function check ( n ) { let s = [ " " , " " , " " ] ; let val = index ( n ) ; document . write ( n + " " + s [ val ] + " " ) ; } check ( 30 ) ; check ( - 20 ) ; check ( 0 ) ;

Index/key variables: val
Javascript program:
function checking ( s ) { let c = 0 ; let n = s . length ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' ) c ++ ; if ( c >= 6 && s [ i ] == ' ' ) return true ; } return false ; } let s = " " ; if ( checking ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function countSetBitsInGivenRange ( n , l , r ) { let num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; return countSetBits ( n & num ) ; } let n = 42 ; let l = 2 , r = 5 ; document . write ( countSetBitsInGivenRange ( n , l , r ) ) ;

Accumulator variables: count, n
Javascript program:
function findUnique ( a , n , k ) { let sizeof_let = 4 ; let LET_SIZE = 8 * sizeof_let ; let count = Array . from ( { length : LET_SIZE } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < LET_SIZE ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) if ( ( a [ j ] & ( 1 << i ) ) != 0 ) count [ i ] += 1 ; let res = 0 ; for ( let i = 0 ; i < LET_SIZE ; i ++ ) res += ( count [ i ] % k ) * ( 1 << i ) ; return res ; } let a = [ 6 , 2 , 5 , 2 , 2 , 6 , 6 ] ; let n = a . length ; let k = 3 ; document . write ( findUnique ( a , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function setBit ( xorValue ) { var count = 0 ; while ( xorValue ) { if ( xorValue % 2 ) count ++ ; xorValue = parseInt ( xorValue / 2 ) ; } return count ; } function minFlip ( n , k ) { var size = Math . log2 ( n ) + 1 ; var max = Math . pow ( 2 , k ) - 1 ; max = ( max << ( size - k ) ) ; var xorValue = ( n ^ max ) ; return ( setBit ( xorValue ) ) ; } var n = 27 , k = 3 ; document . write ( " " + minFlip ( n , k ) ) ;

Accumulator variables: count
Javascript program:
function setAllBitsAfterMSB ( n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return n ; } function toggle ( n ) { n = n ^ setAllBitsAfterMSB ( n ) ; return n ; } let n = 10 ; document . write ( toggle ( n ) ) ;

Accumulator variables: n
Javascript program:
function posOfRightMostSameBit ( m , n ) { let loopCounter = 1 ; while ( m > 0 n > 0 ) { let a = m % 2 == 1 ; let b = n % 2 == 1 ; if ( ! ( a ^ b ) ) { return loopCounter ; } m = m >> 1 ; n = n >> 1 ; loopCounter ++ ; } return - 1 ; } let m = 16 , n = 7 ; document . write ( " " + posOfRightMostSameBit ( m , n ) ) ;

Accumulator variables: loopCounter
Javascript program:
function printNonConsecutive ( n ) { let p = ( 1 << n ) ; for ( let i = 1 ; i < p ; i ++ ) if ( ( i & ( i << 1 ) ) == 0 ) document . write ( i + " " ) ; } let n = 3 ; printNonConsecutive ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var INT_SIZE = 32 ; function constructNthNumber ( group_no , aux_num , op ) { var a = Array . from ( { length : INT_SIZE } , ( _ , i ) => 0 ) ; var num = 0 , len_f = 0 ; var i = 0 ; if ( op == 2 ) { len_f = 2 * group_no ; a [ len_f - 1 ] = a [ 0 ] = 1 ; while ( aux_num > 0 ) { a [ group_no + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } else if ( op == 0 ) { len_f = 2 * group_no + 1 ; a [ len_f - 1 ] = a [ 0 ] = 1 ; a [ group_no ] = 0 ; while ( aux_num > 0 ) { a [ group_no + 1 + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } else { len_f = 2 * group_no + 1 ; a [ len_f - 1 ] = a [ 0 ] = 1 ; a [ group_no ] = 1 ; while ( aux_num > 0 ) { a [ group_no + 1 + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } for ( i = 0 ; i < len_f ; i ++ ) num += ( 1 << i ) * a [ i ] ; return num ; } function getNthNumber ( n ) { var group_no = 0 , group_offset ; var count_upto_group = 0 , count_temp = 1 ; var op , aux_num ; while ( count_temp < n ) { group_no ++ ; count_upto_group = count_temp ; count_temp += 3 * ( 1 << ( group_no - 1 ) ) ; } group_offset = n - count_upto_group - 1 ; if ( ( group_offset + 1 ) <= ( 1 << ( group_no - 1 ) ) ) { op = 2 ; aux_num = group_offset ; } else { if ( ( ( group_offset + 1 ) - ( 1 << ( group_no - 1 ) ) ) % 2 == 1 ) op = 0 ; else op = 1 ; aux_num = ( ( group_offset ) - ( 1 << ( group_no - 1 ) ) ) / 2 ; } return constructNthNumber ( group_no , aux_num , op ) ; } var n = 9 ; document . write ( getNthNumber ( n ) ) ;

Index/key variables: group_no, i
Accumulator variables: count_temp, group_no, i, num
Iterator variables: i
Javascript program:
function shuffle ( N , key ) { let NO_OF_BITS = N ; let reverse_num = 0 , temp ; for ( let i = 0 ; i < NO_OF_BITS ; i ++ ) { temp = ( key & ( 1 << i ) ) ; if ( temp > 0 ) reverse_num |= ( 1 << ( ( NO_OF_BITS - 1 ) - i ) ) ; } document . write ( reverse_num ) ; } let N = 3 ; let key = 3 ; shuffle ( N , key ) ;

Accumulator variables: i, reverse_num
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function findSum ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) if ( countSetBits ( i ) == 2 ) sum += i ; return sum ; } let n = 10 ; document . write ( findSum ( n ) ) ;

Accumulator variables: count, i, n, sum
Iterator variables: i
Javascript program:
function CountZeroBit ( x ) { let count = 0 ; while ( x > 0 ) { if ( ( x & 1 ) == 0 ) count ++ ; x >>= 1 ; } return count ; } function CountXORandSumEqual ( x ) { let count = CountZeroBit ( x ) ; return ( 1 << count ) ; } let x = 10 ; document . write ( CountXORandSumEqual ( x ) ) ;

Accumulator variables: count
Javascript program:
function missingNumber ( arr1 , arr2 , n ) { let mnum = 0 ; for ( let i = 0 ; i < n ; i ++ ) mnum = mnum ^ arr1 [ i ] ; for ( let i = 0 ; i < n - 1 ; i ++ ) mnum = mnum ^ arr2 [ i ] ; return mnum ; } let arr1 = [ 4 , 8 , 1 , 3 , 7 ] ; let arr2 = [ 7 , 4 , 3 , 1 ] ; let n = arr1 . length ; document . write ( " " + missingNumber ( arr1 , arr2 , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countValues ( x ) { var count = 0 , n = 1 ; while ( x != 0 ) { if ( x % 2 == 0 ) count += n ; n *= 2 ; x = parseInt ( x / 2 ) ; } return count ; } var x = 10 ; document . write ( countValues ( x ) ) ;

Accumulator variables: count, n
Javascript program:
function constructXOR ( A , n ) { let XOR = 0 ; for ( let i = 0 ; i < n ; i ++ ) XOR ^= A [ i ] ; for ( let i = 0 ; i < n ; i ++ ) A [ i ] = XOR ^ A [ i ] ; } let A = [ 2 , 4 , 1 , 3 , 5 ] ; let n = A . length ; constructXOR ( A , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( A [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: XOR, i
Iterator variables: i
Javascript program:
function bitCount ( n ) { let count = 0 ; while ( n > 0 ) { if ( ( n & 1 ) > 0 ) ++ count ; n >>= 1 ; } return count ; } function countPairsWithKDiff ( arr , n , k ) { for ( let i = 0 ; i < n - 1 ; ++ i ) { for ( let j = i + 1 ; j < n ; ++ j ) { let xoredNum = arr [ i ] ^ arr [ j ] ; if ( k == bitCount ( xoredNum ) ) ++ ans ; } } return ans ; } let k = 2 ; let arr = [ 2 , 4 , 1 , 3 , 1 ] ; let n = arr . length ; document . write ( " " + k + " " + countPairsWithKDiff ( arr , n , k ) + " " ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
function kBitDifferencePairs ( arr , n , k ) { let MAX = Math . max ( ... arr ) ; let count = new Array ( MAX + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; ++ i ) ++ count [ arr [ i ] ] ; let ans = 0 ; if ( k == 0 ) { for ( let i = 0 ; i <= MAX ; ++ i ) ans += parseInt ( ( count [ i ] * ( count [ i ] - 1 ) ) / 2 ) ; return ans ; } for ( let i = 0 ; i <= MAX ; ++ i ) { if ( ! count [ i ] ) continue ; for ( let j = i + 1 ; j <= MAX ; ++ j ) { if ( BitCount ( i ^ j ) == k ) ans += count [ i ] * count [ j ] ; } } return ans ; } function BitCount ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } let k = 2 ; let arr = [ 2 , 4 , 1 , 3 , 1 ] ; let n = arr . length ; document . write ( " " + k + " " + kBitDifferencePairs ( arr , n , k ) + " " ) ; k = 3 ; document . write ( " " + k + " " + kBitDifferencePairs ( arr , n , k ) + " " ) ;

Index/key variables: i, j
Accumulator variables: ans, count
Iterator variables: i, j
Javascript program:
function multiply ( n , m ) { let ans = 0 , count = 0 ; while ( m ) { if ( m % 2 == 1 ) ans += n << count ; count ++ ; m = Math . floor ( m / 2 ) ; } return ans ; } let n = 20 , m = 13 ; document . write ( multiply ( n , m ) ) ;

Accumulator variables: ans, count
Javascript program:
function dec2bin ( dec ) { return ( dec >>> 0 ) . toString ( 2 ) ; } function findContinuous1 ( n ) { let bp = dec2bin ( n ) let bits = bp . length let prev_count = 0 let curr_count = 0 let i = 0 while ( i < bits ) { if ( bp [ i ] == ' ' ) { curr_count += 1 ; i += 1 ; } else if ( bp [ i - 1 ] == ' ' ) { i += 1 curr_count = 0 continue } else { if ( curr_count < prev_count ) return 0 i += 1 prev_count = curr_count curr_count = 0 } } if ( prev_count > curr_count && ( curr_count != 0 ) ) return 0 return 1 } n = 179 if ( findContinuous1 ( n ) ) document . write ( " " ) else document . write ( " " )

Index/key variables: i
Accumulator variables: curr_count, i
Javascript program:
function areSetBitsIncreasing ( n ) { var prev_count = Number . MAX_VALUE ; while ( n > 0 ) { while ( n > 0 && n % 2 == 0 ) n = parseInt ( n / 2 ) ; var curr_count = 1 ; while ( n > 0 && n % 2 == 1 ) { n = n / 2 ; curr_count ++ ; } if ( curr_count >= prev_count ) return false ; prev_count = curr_count ; } return true ; } var n = 10 ; if ( areSetBitsIncreasing ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: curr_count
Javascript program:
function countXOR ( n ) { let count0 = 0 , count1 = 0 ; while ( n != 0 ) { if ( n % 2 == 0 ) count0 ++ ; else count1 ++ ; n = Math . floor ( n / 2 ) ; } return ( count0 ^ count1 ) ; } let n = 31 ; document . write ( countXOR ( n ) ) ;

Accumulator variables: count0, count1
Javascript program:
function xorPairCount ( arr , n , x ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let curr_xor = x ^ arr [ i ] ; if ( m . has ( curr_xor ) ) result += m . get ( curr_xor ) ; if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . set ( arr [ i ] , 1 ) ; } } return result ; } let arr = [ 2 , 5 , 2 ] ; let n = arr . length ; let x = 0 ; document . write ( " " + xorPairCount ( arr , n , x ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function msbPos ( n ) { let msb_p = - 1 ; while ( n > 0 ) { n = n >> 1 ; msb_p ++ ; } return msb_p ; } function andOperator ( x , y ) { while ( x > 0 && y > 0 ) { let msb_p1 = msbPos ( x ) ; let msb_p2 = msbPos ( y ) ; if ( msb_p1 != msb_p2 ) break ; let msb_val = ( 1 << msb_p1 ) ; res = res + msb_val ; x = x - msb_val ; y = y - msb_val ; } return res ; } let x = 10 , y = 15 ; document . write ( andOperator ( x , y ) ) ;

Accumulator variables: msb_p
Javascript program:
function countValues ( n ) { let countV = 0 ; for ( let i = 0 ; i <= n ; i ++ ) if ( ( n + i ) == ( n ^ i ) ) countV ++ ; return countV ; } let n = 12 ; document . write ( countValues ( n ) ) ;

Accumulator variables: countV, i
Iterator variables: i
Javascript program:
function countValues ( n ) { let unset_bits = 0 ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) unset_bits ++ ; n = n >> 1 ; } return 1 << unset_bits ; } let n = 12 ; document . write ( countValues ( n ) ) ;

Accumulator variables: unset_bits
Javascript program:
function printTwoSetBitNums ( n ) { let x = 1 ; while ( n > 0 ) { let y = 0 ; while ( y < x ) { document . write ( ( 1 << x ) + ( 1 << y ) + " " ) ; n -- ; if ( n == 0 ) return ; y ++ ; } x ++ ; } } printTwoSetBitNums ( 4 ) ;

Accumulator variables: n, x, y
Javascript program:
function rand50 ( ) { return Math . floor ( Math . random ( ) * 10 ) & 1 ; } function rand75 ( ) { return rand50 ( ) | rand50 ( ) ; } for ( let i = 0 ; i < 50 ; i ++ ) document . write ( rand75 ( ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printRepeatingEven ( arr , n ) { let _xor = 0 ; let pos ; for ( let i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; _xor ^= pos ; } for ( let i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; if ( ! ( ( pos & _xor ) != 0 ) ) { document . write ( arr [ i ] + " " ) ; _xor ^= pos ; } } } let arr = [ 9 , 12 , 23 , 10 , 12 , 12 , 15 , 23 , 14 , 12 , 15 ] ; let n = arr . length ; printRepeatingEven ( arr , n ) ;

Index/key variables: i
Accumulator variables: _xor
Iterator variables: i
Javascript program:
function countSetBits ( x ) { let count = 0 ; while ( x != 0 ) { x &= ( x - 1 ) ; count ++ ; } return count ; } function isBleak ( n ) { for ( let x = 1 ; x < n ; x ++ ) if ( x + countSetBits ( x ) == n ) return false ; return true ; } if ( isBleak ( 3 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isBleak ( 4 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: count, x
Iterator variables: x
Javascript program:
let INT_BITS = 32 ; function maxSubarrayXOR ( set , n ) { let index = 0 ; for ( let i = INT_BITS - 1 ; i >= 0 ; i -- ) { let maxInd = index ; let maxEle = Number . MIN_VALUE ; for ( let j = index ; j < n ; j ++ ) { if ( ( set [ j ] & ( 1 << i ) ) != 0 && set [ j ] > maxEle ) { maxEle = set [ j ] ; maxInd = j ; } } if ( maxEle == Number . MIN_VALUE ) continue ; let temp = set [ index ] ; set [ index ] = set [ maxInd ] ; set [ maxInd ] = temp ; maxInd = index ; for ( let j = 0 ; j < n ; j ++ ) { if ( j != maxInd && ( set [ j ] & ( 1 << i ) ) != 0 ) set [ j ] = set [ j ] ^ set [ maxInd ] ; } index ++ ; } let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) res ^= set [ i ] ; return res ; } let set = [ 9 , 8 , 5 ] ; let n = set . length ; document . write ( " " ) ; document . write ( maxSubarrayXOR ( set , n ) ) ;

Index/key variables: i, index, j, maxInd
Accumulator variables: i, index, j, res
Iterator variables: i, j
Javascript program:
function myXOR ( x , y ) { for ( let i = 31 ; i >= 0 ; i -- ) { let b1 = ( ( x & ( 1 << i ) ) == 0 ) ? 0 : 1 ; let b2 = ( ( y & ( 1 << i ) ) == 0 ) ? 0 : 1 ; let xoredBit = ( b1 & b2 ) ? 0 : ( b1 b2 ) ; res <<= 1 ; res |= xoredBit ; } return res ; } let x = 3 , y = 5 ; document . write ( " " + myXOR ( x , y ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
let N = 2 ; function freivald ( a , b , c ) { let r = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) r [ i ] = Math . random ( ) % 2 ; let br = new Array ( N ) ; br . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) br [ i ] = br [ i ] + b [ i ] [ j ] * r [ j ] ; let cr = new Array ( N ) ; cr . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) cr [ i ] = cr [ i ] + c [ i ] [ j ] * r [ j ] ; let axbr = new Array ( N ) ; axbr . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) axbr [ i ] = axbr [ i ] + a [ i ] [ j ] * br [ j ] ; for ( let i = 0 ; i < N ; i ++ ) if ( axbr [ i ] - cr [ i ] != 0 ) false ; return true ; } function isProduct ( a , b , c , k ) { for ( let i = 0 ; i < k ; i ++ ) if ( freivald ( a , b , c ) == false ) return false ; return true ; } let a = [ [ 1 , 1 ] , [ 1 , 1 ] ] ; let b = [ [ 1 , 1 ] , [ 1 , 1 ] ] ; let c = [ [ 2 , 2 ] , [ 2 , 2 ] ] ; let k = 2 ; if ( isProduct ( a , b , c , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function calc_Expectation ( a , n ) { let prb = ( 1 / n ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += a [ i ] * prb ; return sum ; } let expect , n = 6 ; let a = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; expect = calc_Expectation ( a , n ) ; document . write ( " " + expect ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function LongestSubarray ( a , n , k ) { var pre = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] > k ) pre [ i ] = 1 ; else pre [ i ] = - 1 ; } for ( i = 1 ; i < n ; i ++ ) pre [ i ] = pre [ i - 1 ] + pre [ i ] ; var len = 0 ; var lo = 1 , hi = n ; while ( lo <= hi ) { var mid = parseInt ( ( lo + hi ) / 2 ) ; var ok = false ; for ( i = mid - 1 ; i < n ; i ++ ) { var x = pre [ i ] ; if ( i - mid >= 0 ) x -= pre [ i - mid ] ; if ( x > 0 ) { ok = true ; break ; } } if ( ok == true ) { len = mid ; lo = mid + 1 ; } else hi = mid - 1 ; } return len ; } var a = [ 2 , 3 , 4 , 5 , 3 , 7 ] ; var k = 3 ; var n = a . length ; document . write ( LongestSubarray ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, x
Iterator variables: i
Boolean variables: ok
Javascript program:
function binarySeach ( P , N ) { var i = 0 ; var j = P . length - 1 ; var index = - 1 ; while ( i <= j ) { var mid = i + parseInt ( ( j - i ) / 2 ) ; if ( P [ mid ] >= N ) { index = mid ; j = mid - 1 ; } else { i = mid + 1 ; } } return index ; } function minDays ( P , arr ) { for ( var i = 1 ; i < P . length ; i ++ ) { P [ i ] += P [ i ] + P [ i - 1 ] ; } for ( var i = 0 ; i < arr . length ; i ++ ) { var index = binarySeach ( P , arr [ i ] ) ; if ( index != - 1 ) { document . write ( ( index + 1 ) + " " ) ; } else { document . write ( - 1 + " " ) ; } } } var arr = [ 400 , 200 , 700 , 900 , 1400 ] ; var P = [ 100 , 300 , 400 , 500 , 600 ] ; minDays ( P , arr ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumProfit ( arr , N ) { let ans = Number . MIN_VALUE ; let price = 0 ; arr . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < N ; i ++ ) { let count = ( N - i ) ; if ( ans < count * arr [ i ] ) { price = arr [ i ] ; ans = count * arr [ i ] ; } } return price ; } let arr = [ 22 , 87 , 9 , 50 , 56 , 43 ] ; document . write ( maximumProfit ( arr , 6 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPalindrome ( S , i , j ) { while ( i < j ) { if ( S [ i ] !== S [ j ] ) return false ; i ++ ; j -- ; } return true ; } function printLongestPalindrome ( S , N ) { var palLength = new Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) { var maxlength = 1 ; for ( var j = 0 ; j < i ; j ++ ) { if ( S [ j ] === S [ i ] ) { if ( isPalindrome ( S , j , i ) !== false ) { maxlength = i - j + 1 ; break ; } } } for ( var j = N - 1 ; j > i ; j -- ) { if ( S [ j ] === S [ i ] ) { if ( isPalindrome ( S , i , j ) ) { maxlength = Math . max ( j - i + 1 , maxlength ) ; break ; } } } palLength [ i ] = maxlength ; } for ( var i = 0 ; i < N ; i ++ ) { document . write ( palLength [ i ] + " " ) ; } } var S = " " ; var N = S . length ; printLongestPalindrome ( S , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function mulsum ( arr , n , N ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % N == 0 ) { sum = sum + arr [ i ] ; } } document . write ( sum ) ; } var arr = [ 1 , 2 , 3 , 5 , 6 ] ; var n = arr . length ; var N = 3 ; mulsum ( arr , n , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function farthestHill ( arr , X , Y , N , K ) { var i , diff ; var pq = [ ] ; for ( i = K ; i < N - 1 ; i ++ ) { if ( arr [ i ] >= arr [ i + 1 ] ) continue ; diff = arr [ i + 1 ] - arr [ i ] ; pq . push ( diff ) ; pq . sort ( ) ; pq = pq . reverse ( ) ; if ( pq . length > Y ) { X -= pq [ 0 ] ; pq = pq . slice ( 1 ) ; } if ( X < 0 ) { document . write ( i ) ; return ; } } document . write ( N - 1 ) ; } var arr = [ 4 , 2 , 7 , 6 , 9 , 14 , 12 ] ; var X = 5 , Y = 1 ; var K = 0 ; var N = arr . length ; farthestHill ( arr , X , Y , N , K ) ;

Index/key variables: i
Accumulator variables: X, i
Iterator variables: i
Javascript program:
function newString ( originalLabel , limit ) { let n = originalLabel . length ; let charset = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { charset [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { charset [ originalLabel [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let newString = [ ] ; for ( let i = 25 ; i >= 0 ; i -- ) { let count = 0 ; while ( charset [ i ] > 0 ) { newString . push ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) ; charset [ i ] -- ; count ++ ; if ( charset [ i ] > 0 && count == limit ) { let next = nextAvailableChar ( charset , i ) ; if ( next == null ) return newString . join ( " " ) ; newString . push ( next ) ; count = 0 ; } } } return newString . join ( " " ) ; } function nextAvailableChar ( charset , start ) { for ( let i = start - 1 ; i >= 0 ; i -- ) { if ( charset [ i ] > 0 ) { charset [ i ] -- ; return String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; } } return null ; } let S = " " ; let K = 2 ; document . write ( newString ( S , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function swapEvenOdd ( arr , n ) { let o = - 1 , e = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) continue ; let r = - 1 ; if ( arr [ i ] % 2 == 0 ) { o ++ ; while ( arr [ o ] % 2 == 0 arr [ o ] < 0 ) o ++ ; r = o ; } else { e ++ ; while ( arr [ e ] % 2 == 1 arr [ e ] < 0 ) e ++ ; r = e ; } arr [ i ] *= - 1 ; arr [ r ] *= - 1 ; let tmp = arr [ i ] ; arr [ i ] = arr [ r ] ; arr [ r ] = tmp ; } for ( let i = 0 ; i < n ; i ++ ) { document . write ( ( - 1 * arr [ i ] ) + " " ) ; } } let arr = [ 1 , 3 , 2 , 4 ] ; let n = arr . length ; swapEvenOdd ( arr , n ) ;

Index/key variables: e, i, o, r
Accumulator variables: e, i, o
Iterator variables: i