dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let N = 200000 ; let prime = new Array ( 20000 ) . fill ( 0 ) ; let index = 0 ; function Sieve ( ) { index = 0 ; let p = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i <= N ; i ++ ) { p [ i ] = 1 ; } p [ 0 ] = p [ 1 ] = 0 ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( p [ i ] == 1 ) { for ( let j = i * i ; j <= N ; j += i ) { p [ j ] = 0 ; } } } for ( let i = 1 ; i < N ; i ++ ) { if ( p [ i ] == 1 ) { prime [ index ++ ] = ( Math . pow ( i , 4 ) ) ; } } } function countNumbers ( L , R ) { let Count = 0 ; for ( let i = 0 ; i < index ; i ++ ) { let p = prime [ i ] ; if ( p >= L && p <= R ) { Count ++ ; } } document . write ( Count ) ; } let L = 16 , R = 85000 ; Sieve ( ) ; countNumbers ( L , R ) ;

Index/key variables: i, j
Accumulator variables: Count, i, index, j
Iterator variables: i, j
Javascript program:
function countRemainingElements ( L1 , L2 , n ) { let one = 0 ; let zero = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( L1 [ i ] == 1 ) one ++ ; else zero ++ ; } let ans = n ; for ( let i = 0 ; i < n ; i ++ ) { if ( L2 [ i ] == 1 ) { one -- ; if ( one < 0 ) { ans = i ; break ; } } else { zero -- ; if ( zero < 0 ) { ans = i ; break ; } } } document . write ( n - ans ) ; } let L1 = [ 1 , 1 , 0 , 0 ] ; let L2 = [ 0 , 0 , 0 , 1 ] ; let N = L1 . length ; countRemainingElements ( L1 , L2 , N ) ;

Index/key variables: i
Accumulator variables: i, one, zero
Iterator variables: i
Javascript program:
function getCount ( rows , columns , A ) { var res = 0 ; for ( var i = 0 ; i < rows ; i ++ ) { for ( var j = i + 1 ; j < rows ; j ++ ) { if ( A [ i ] [ 0 ] * A [ j ] [ 1 ] == A [ i ] [ 1 ] * A [ j ] [ 0 ] ) { res ++ ; } } } return res ; } var A = [ [ 4 , 8 ] , [ 10 , 20 ] , [ 15 , 30 ] , [ 3 , 6 ] ] ; var columns = 2 ; var rows = 4 ; document . write ( getCount ( rows , columns , A ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function Min_Score_Index ( N , A ) { var Score = Array ( N ) . fill ( 0 ) ; for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] + i < N ) Score [ i ] = A [ i ] * Score [ A [ i ] + i ] ; else Score [ i ] = A [ i ] ; } var min_value = 1000000000 ; Score . forEach ( i => { min_value = Math . min ( i , min_value ) ; } ) ; var ind = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( Score [ i ] == min_value ) ind = i ; } document . write ( ind ) ; } var N = 5 ; var A = [ 1 , 2 , 3 , 4 , 5 ] ; Min_Score_Index ( N , A ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minLength ( S , T , N , M ) { let temp = " " ; let subtract = 0 ; for ( let i = 0 ; i < N ; ++ i ) { temp += S [ i ] ; if ( temp . length >= M ) { if ( T == temp . substr ( temp . length - M , temp . length ) ) { subtract += M ; let cnt = 0 ; while ( cnt != M ) { temp = temp . substr ( 0 , temp . length - 1 ) ; ++ cnt ; } } } } document . write ( ( N - subtract ) ) ; } let S = " " , T = " " ; let N = S . length ; let M = T . length ; minLength ( S , T , N , M ) ;

Index/key variables: i
Accumulator variables: subtract, temp
Iterator variables: i
Javascript program:
function maximumCount ( arr1 , arr2 , s1 , s2 ) { let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < s1 ; i ++ ) { sum1 += arr1 [ i ] ; } for ( let j = 0 ; j < s2 ; j ++ ) { sum2 += arr2 [ j ] ; } let len = 0 ; if ( s1 >= s2 ) { len = s2 ; } else { len = s1 ; } arr1 . sort ( ) ; arr2 . sort ( ) ; let j = 0 , k = s2 - 1 , count = 0 ; for ( let i = 0 ; i < len ; i ++ ) { if ( sum1 <= sum2 ) { if ( arr2 [ k ] >= arr1 [ i ] ) { let dif1 = arr1 [ j ] , dif2 = arr2 [ k ] ; sum1 -= dif1 ; sum1 += dif2 ; sum2 -= dif2 ; sum2 += dif1 ; j ++ ; k -- ; count ++ ; } else { break ; } } else { break ; } } return count ; } let arr1 = [ 1 , 3 , 2 , 4 ] ; let arr2 = [ 6 , 7 , 8 ] ; let N = arr1 . length ; let M = arr2 . length ; document . write ( maximumCount ( arr1 , arr2 , N , M ) ) ;

Index/key variables: i, j, k
Accumulator variables: count, i, j, k, sum1, sum2
Iterator variables: i, j
Javascript program:
function isValidDigit ( digit , K ) { while ( K != 0 ) { if ( K % 10 == digit ) { return true ; } K = parseInt ( K / 10 ) ; } return false ; } function noOfValidNumbers ( K , arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let no = arr [ i ] ; let flag = true ; while ( no != 0 ) { let digit = no % 10 ; if ( ! isValidDigit ( digit , K ) ) { flag = false ; break ; } no = parseInt ( no / 10 ) ; } if ( flag == true ) { count ++ ; } } return count ; } let K = 12 ; let arr = [ 1 , 12 , 1222 , 13 , 2 ] ; let n = arr . length ; document . write ( noOfValidNumbers ( K , arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
class pair { constructor ( element , index ) { this . element = element ; this . index = index ; } } function minimumIndex ( arr , Q ) { let N = arr . length ; let M = Q . length ; let storeArrIdx = [ ] ; let minIdx = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { minIdx [ i ] = 0 ; } for ( let i = 0 ; i < N ; ++ i ) { storeArrIdx . push ( [ arr [ i ] , i ] ) ; } ( arr ) . sort ( function ( a , b ) { return a - b ; } ) ; storeArrIdx . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] } ) ; minIdx [ N - 1 ] = storeArrIdx [ N - 1 ] [ 1 ] ; for ( let i = N - 2 ; i >= 0 ; i -- ) { minIdx [ i ] = Math . min ( minIdx [ i + 1 ] , storeArrIdx [ i ] [ 1 ] ) ; } for ( let i = 0 ; i < M ; i ++ ) { let pos = lower_bound ( arr , Q [ i ] ) ; if ( pos == N ) { document . write ( " " + " " ) ; continue ; } document . write ( minIdx [ pos ] + " " ) ; } } function lower_bound ( arr , element ) { for ( let i = 0 ; i < arr . length ; i ++ ) if ( element <= arr [ i ] ) return i ; return arr . length ; } let arr = [ 1 , 9 ] ; let Q = [ 7 , 10 , 0 ] ; minimumIndex ( arr , Q ) ;

Index/key variables: i, pos
Accumulator variables: i
Iterator variables: i
Class/struct names: pair
Javascript program:
function isSubarrayExistUtil ( arr , K , N ) { var totalXOR = 0 ; var SubarrayXOR = 0 ; for ( i = 0 ; i < N ; i ++ ) totalXOR ^= arr [ i ] ; for ( i = 0 ; i < K ; i ++ ) SubarrayXOR ^= arr [ i ] ; if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) return true ; for ( i = K ; i < N ; i ++ ) { SubarrayXOR ^= arr [ i ] ; SubarrayXOR ^= arr [ i - 1 ] ; if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) return true ; } return false ; } function isSubarrayExist ( arr , K , N ) { if ( isSubarrayExistUtil ( arr , K , N ) ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 2 , 3 , 3 , 5 , 7 , 7 , 3 , 4 ] ; var N = arr . length ; var K = 5 ; isSubarrayExist ( arr , K , N ) ;

Index/key variables: i
Accumulator variables: SubarrayXOR, i, totalXOR
Iterator variables: i
Javascript program:
function countPairs ( L , R ) { let count_even ; if ( L % 2 == 0 ) { count_even = ( R / 2 ) - ( L / 2 ) + 1 ; } else { count_even = ( R / 2 ) - ( L / 2 ) ; } let count_odd ; if ( L % 2 == 0 ) { count_odd = ( ( R + 1 ) / 2 ) - ( ( L + 1 ) / 2 ) ; } else { count_odd = ( ( R + 1 ) / 2 ) - ( ( L + 1 ) / 2 ) + 1 ; } count_even *= count_even ; count_odd *= count_odd ; document . write ( count_even + count_odd ) ; } let L = 1 , R = 3 ; countPairs ( L , R ) ;

Accumulator variables: count_even, count_odd
Javascript program:
function getDefiniteFinds ( arr ) { let n = arr . length ; let smallestRight = new Array ( n + 1 ) . fill ( 0 ) ; smallestRight [ n ] = Number . MAX_VALUE ; for ( let i = n - 1 ; i >= 0 ; i -- ) { smallestRight [ i ] = Math . min ( smallestRight [ i + 1 ] , arr [ i ] ) ; } let mn = Number . MIN_VALUE ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( mn < arr [ i ] && arr [ i ] < smallestRight [ i + 1 ] ) { ans ++ ; } mn = Math . max ( arr [ i ] , mn ) ; } return ans ; } let arr = [ 5 , 4 , 9 ] ; document . write ( getDefiniteFinds ( arr ) ) ;

Index/key variables: i, n
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function Count_numbers ( L , R ) { var count = ( R - L ) / 2 ; if ( R % 2 != 0 L % 2 != 0 ) count += 1 ; document . write ( count ) ; } var L = 6 , R = 30 ; Count_numbers ( L , R ) ;

Accumulator variables: count
Javascript program:
function checkReverse ( leftSum , rightSum ) { var rev = 0 ; var temp = rightSum ; while ( temp != 0 ) { rev = ( rev * 10 ) + ( temp % 10 ) ; temp = parseInt ( temp / 10 ) ; } if ( rev == leftSum ) { return true ; } return false ; } function findIndex ( arr , N ) { var rightSum = 0 ; var leftSum = 0 ; for ( i = 0 ; i < N ; i ++ ) { rightSum += arr [ i ] ; } for ( i = 0 ; i < N ; i ++ ) { rightSum -= arr [ i ] ; if ( checkReverse ( leftSum , rightSum ) ) { return i ; } leftSum += arr [ i ] ; } return - 1 ; } var arr = [ 5 , 7 , 3 , 6 , 4 , 9 , 2 ] ; var N = arr . length ; document . write ( findIndex ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, leftSum, rightSum
Iterator variables: i
Javascript program:
function LCS ( firstArr , secondArr ) { let mp = new Map ( ) for ( let i = 0 ; i < firstArr . length ; i ++ ) { mp . set ( firstArr [ i ] , i + 1 ) ; } let tempArr = [ ] ; for ( let i = 0 ; i < secondArr . length ; i ++ ) { if ( mp . has ( secondArr [ i ] ) ) { tempArr . push ( mp . get ( secondArr [ i ] ) ) ; } } let tail = [ ] ; tail . push ( tempArr [ 0 ] ) ; for ( let i = 1 ; i < tempArr . length ; i ++ ) { if ( tempArr [ i ] > tail [ tail . length - 1 ] ) tail . push ( tempArr [ i ] ) ; else if ( tempArr [ i ] < tail [ 0 ] ) tail . unshift ( 0 , tempArr [ i ] ) ; } return tail . length ; } let firstArr = [ 3 , 5 , 1 , 8 ] ; let secondArr = [ 3 , 3 , 5 , 3 , 8 ] ; document . write ( LCS ( firstArr , secondArr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function totalWays ( n , str ) { var IdxOf0s = [ ] ; var cntWays = 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { IdxOf0s . push ( i ) ; } } var M = IdxOf0s . length ; if ( M == 0 M % 2 ) { return 0 ; } for ( var i = 2 ; i < M ; i += 2 ) { cntWays = cntWays * ( IdxOf0s [ i ] - IdxOf0s [ i - 1 ] ) ; } return cntWays ; } var str = " " ; var n = str . length ; document . write ( totalWays ( n , str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countTriplets ( arr , N ) { var zero_i = [ ] ; var one_i = [ ] ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zero_i . push ( i + 1 ) ; else if ( arr [ i ] == 1 ) one_i . push ( i + 1 ) ; else mp . set ( i + 1 , 1 ) ; } var total = zero_i . length * one_i . length * mp . size ; for ( var i = 0 ; i < zero_i . length ; i ++ ) { for ( var j = 0 ; j < one_i . length ; j ++ ) { var p = zero_i [ i ] ; var q = one_i [ j ] ; var r = 2 * p - q ; if ( mp . has ( r ) ) total -- ; r = 2 * q - p ; if ( mp . has ( r ) ) total -- ; r = ( p + q ) / 2 ; if ( mp . has ( r ) && Math . abs ( r - p ) == Math . abs ( r - q ) ) total -- ; } } document . write ( total ) ; } var arr = [ 0 , 1 , 2 , 1 ] ; var N = arr . length ; countTriplets ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, total
Iterator variables: i, j
Javascript program:
function PrimeFactors ( N ) { let st = [ ] ; let i = 2 ; while ( N != 1 ) { if ( N % i == 0 ) { st . push ( i ) ; while ( N % i == 0 ) { N = Math . floor ( N / i ) ; } } i ++ ; } while ( st . length != 0 ) { document . write ( st . pop ( ) ) ; } } let N = 8 ; PrimeFactors ( N ) ;

Accumulator variables: i
Javascript program:
function CountSubarray ( arr , n , k ) { var temp = k , count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == temp ) { if ( temp == 1 ) { count ++ ; temp = k ; } else temp -- ; } else { temp = k ; if ( arr [ i ] == k ) i -- ; } } return count ; } var arr = [ 1 , 2 , 3 , 7 , 9 , 3 , 2 , 1 , 8 , 3 , 2 , 1 ] ; var N = arr . length ; var K = 3 ; document . write ( CountSubarray ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i, temp
Iterator variables: i
Javascript program:
function countFreq ( N , K ) { let count = 0 ; while ( N > 0 ) { if ( N % 10 == K ) { count ++ ; } N = Math . floor ( N / 10 ) ; } return count ; } function findElementUtil ( arr , N , K ) { let c ; let max ; let ele = 0 ; max = 0 ; for ( let i = 0 ; i < N ; i ++ ) { c = countFreq ( arr [ i ] , K ) ; if ( c > max ) { max = c ; ele = arr [ i ] ; } } if ( max == 0 ) return - 1 ; else return ele ; } function findElement ( arr , N , K ) { let ele = findElementUtil ( arr , N , K ) ; if ( ele == - 1 ) document . write ( " " ) ; else document . write ( ele ) ; } let K = 3 ; let arr = [ 3 , 77 , 343 , 456 ] ; let N = arr . length ; findElement ( arr , K , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findMinDeletions ( v , n ) { let minDel = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let L = v [ i ] [ 0 ] ; let R = v [ i ] [ 1 ] ; let Count = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( v [ j ] [ 0 ] >= L && v [ j ] [ 1 ] <= R ) { Count += 1 ; } } minDel = Math . min ( minDel , n - Count ) ; } return minDel ; } let v = [ [ 1 , 3 ] , [ 4 , 12 ] , [ 5 , 8 ] , [ 13 , 20 ] ] ; let N = v . length ; document . write ( findMinDeletions ( v , N ) ) ;

Index/key variables: i, j
Accumulator variables: Count, i, j
Iterator variables: i, j
Javascript program:
function maxEvenLetegers ( arr , N , M ) { let curr = 0 ; for ( let i = 0 ; i < M ; i ++ ) { if ( arr [ i ] % 2 == 0 ) curr ++ ; } let ans = curr ; for ( let i = M ; i < N ; i ++ ) { if ( arr [ i - M ] % 2 == 0 ) { curr -- ; } if ( arr [ i ] % 2 == 0 ) curr ++ ; ans = Math . max ( ans , curr ) ; } return ans ; } let arr = [ 2 , 3 , 5 , 4 , 7 , 6 ] ; let M = 3 ; let N = arr . length ; document . write ( maxEvenLetegers ( arr , N , M ) + " " ) ;

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: i
Javascript program:
function countNumbers ( n , d ) { let total = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { let x = i ; while ( x > 0 ) { if ( x % 8 == d ) { total ++ ; break ; } x = x / 8 ; } } document . write ( total ) ; } let n = 20 , d = 7 ; countNumbers ( n , d ) ;

Accumulator variables: i, total
Iterator variables: i
Javascript program:
function findCntTriplet ( N ) { let cntTriplet = 0 ; for ( let i = 1 ; i < N ; i ++ ) { if ( N % i != 0 ) { cntTriplet += Math . floor ( N / i ) ; } else { cntTriplet += Math . floor ( N / i ) - 1 ; } } return cntTriplet ; } let N = 3 ; document . write ( findCntTriplet ( N ) ) ;

Accumulator variables: cntTriplet, i
Iterator variables: i
Javascript program:
function countDivisors ( n ) { var count = 0 ; var j = 0 ; var divisor = Array ( n ) . fill ( 0 ) ; for ( var i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( parseInt ( n / i ) == i ) { divisor [ j ] = i ; j += 1 ; } else { divisor [ j ] = i ; divisor [ j + 1 ] = parseInt ( n / i ) ; j += 2 ; } } } divisor [ j ] = n ; for ( var i = 0 ; i <= j ; i ++ ) { var x = divisor [ i ] ; x -= 1 ; if ( parseInt ( n / x ) == parseInt ( n % x ) ) count ++ ; } document . write ( count ) ; } var N = 10000000 ; countDivisors ( N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, x
Iterator variables: i
Javascript program:
function smallestIndexArrayElementsFlip ( arr , N ) { var pos = - 1 ; var i , j ; for ( i = 0 ; i < N ; i ++ ) { arr [ i ] *= - 1 ; var sum = 0 ; for ( j = 0 ; j < N ; j ++ ) { sum += arr [ j ] ; } if ( sum == 0 ) { pos = i ; break ; } else { arr [ i ] *= - 1 ; } } return pos ; } var arr = [ 1 , 3 , - 5 , 3 , 4 ] ; var N = arr . length ; document . write ( smallestIndexArrayElementsFlip ( arr , N ) ) ;

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

Index/key variables: i
Accumulator variables: ArrSum, i
Iterator variables: i
Javascript program:
function make_String_S_to_T ( S , T ) { var possible = false ; var M = T . length ; var N = S . length ; for ( i = 0 ; i <= M ; i ++ ) { var prefix_length = i ; var suffix_length = M - i ; var prefix = S . substring ( 0 , prefix_length ) ; var suffix = S . substring ( N - suffix_length , N ) ; if ( ( prefix + suffix ) == ( T ) ) { possible = true ; break ; } } if ( possible ) return " " ; else return " " ; } var S = " " ; var T = " " ; document . write ( make_String_S_to_T ( S , T ) ) ;

Accumulator variables: i
Iterator variables: i
Boolean variables: possible
Javascript program:
function findSum ( a ) { var ans = 0 ; for ( var low = 0 ; low < a . length ; low ++ ) { for ( var high = low ; high < a . length ; high ++ ) { var count = 0 ; var maxNumber = 0 ; for ( var i = low ; i <= high ; i ++ ) { if ( a [ i ] === maxNumber ) count ++ ; else if ( a [ i ] > maxNumber ) { maxNumber = a [ i ] ; count = 1 ; } } ans += maxNumber * ( count % 2 === 0 ? 2 : 1 ) ; } } document . write ( ans ) ; } var arr = [ 2 , 1 , 4 , 4 , 2 ] ; findSum ( arr ) ;

Index/key variables: i
Accumulator variables: ans, count, high, i, low
Iterator variables: high, i, low
Javascript program:
function countPairs ( arr , n ) { let mp1 = new Map ( ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( mp1 . has ( sum ) ) { mp1 . set ( sum , mp1 . get ( sum ) + 1 ) ; } else { mp1 . set ( sum , 1 ) } } sum = 0 ; let ans = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; if ( mp1 . has ( sum ) ) { ans += mp1 . get ( sum ) ; } } document . write ( ans ) ; } let arr = [ 1 , 2 , 1 , 1 ] ; let n = arr . length countPairs ( arr , n ) ;

Index/key variables: i
Accumulator variables: ans, i, sum
Iterator variables: i
Javascript program:
function isMagic ( num ) { return ( num % 9 == 1 ) ; } function isComposite ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } function find ( L , R , q ) { let dp = [ ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; for ( let i = 1 ; i < 1000005 ; i ++ ) { if ( isComposite ( i ) && isMagic ( i ) == true ) { dp [ i ] = dp [ i - 1 ] + 1 ; } else dp [ i ] = dp [ i - 1 ] ; } for ( let i = 0 ; i < q ; i ++ ) document . write ( dp [ R [ i ] ] - dp [ L [ i ] - 1 ] + " " ) ; } let L = [ 10 , 3 ] ; let R = [ 100 , 2279 ] ; let Q = 2 ; find ( L , R , Q ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSmallestInteger ( arr , N , K ) { var left = 1 ; var right = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; while ( left < right ) { var mid = ( left + right ) / 2 ; var sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { sum += parseInt ( ( arr [ i ] + mid - 1 ) / mid ) ; } if ( sum > K ) { left = mid + 1 ; } else { right = mid ; } } return left ; } var arr = [ 1 , 2 , 5 , 9 ] ; var N = arr . length ; var K = 6 ; document . write ( findSmallestInteger ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minimum_deci_binary_number ( s ) { let m = Number . MIN_VALUE ; for ( let i = 0 ; i < s . length ; i ++ ) { let temp = s [ i ] - ' ' ; if ( temp > m ) { m = temp ; } } return m ; } let S = " " ; document . write ( minimum_deci_binary_number ( S ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( arr , n ) { let flips = 0 ; for ( let i = 0 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } for ( let i = 1 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } document . write ( flips ) ; } let arr = [ 2 , 3 , 4 , 3 , 5 , 3 , 2 ] ; let N = arr . length ; minOperations ( arr , N ) ;

Index/key variables: i
Accumulator variables: flips, i
Iterator variables: i
Javascript program:
function minimumReverse ( s , n ) { let k = 0 , l = 0 ; let sum1 = 0 , sum0 = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) sum1 ++ ; else sum0 ++ ; if ( s [ i ] == s [ i - 1 ] && s [ i ] == ' ' ) k ++ ; else if ( s [ i ] == s [ i - 1 ] && s [ i ] == ' ' ) l ++ ; } if ( s [ 0 ] == ' ' ) sum1 ++ ; sum0 ++ ; if ( Math . abs ( sum1 - sum0 ) > 1 ) return - 1 ; return Math . max ( k , l ) ; } let S = " " ; let N = S . length ; document . write ( minimumReverse ( S , N ) ) ;

Index/key variables: i
Accumulator variables: i, k, l, sum0, sum1
Iterator variables: i
Javascript program:
function cntPairsletwoArray ( arr , brr , N , M ) { let cntOddArr = 0 ; let cntOddBrr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { cntOddArr += 1 ; } } for ( let i = 0 ; i < M ; i ++ ) { if ( brr [ i ] % 2 == 1 ) { cntOddBrr += 1 ; } } return ( N * M ) - ( cntOddArr * cntOddBrr ) ; } let arr = [ 1 , 2 , 3 ] ; let N = arr . length ; let brr = [ 1 , 2 ] ; let M = brr . length ; document . write ( cntPairsletwoArray ( arr , brr , N , M ) ) ;

Index/key variables: i
Accumulator variables: cntOddArr, cntOddBrr, i
Iterator variables: i
Javascript program:
function max_freq ( arr , N ) { arr . sort ( ) ; let Max = arr [ N - 1 ] ; let Min = arr [ 0 ] ; let freq = [ ] ; for ( let i = 0 ; i < Max - Min + 1 ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < N ; i ++ ) { freq [ arr [ i ] - Min ] ++ ; } let maxSum = 0 ; for ( let i = 0 ; i < ( Max - Min - 1 ) ; i ++ ) { let val = freq [ i ] + freq [ i + 1 ] + freq [ i + 2 ] ; maxSum = Math . max ( maxSum , val ) ; } document . write ( maxSum ) ; } let arr = [ 3 , 1 , 4 , 1 , 5 , 9 , 2 ] ; let N = arr . length ; max_freq ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaxLength ( N , arr ) { var dp = Array ( N + 1 ) . fill ( 1 ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 2 * i ; j <= N ; j += i ) { if ( arr [ i - 1 ] < arr [ j - 1 ] ) { dp [ j ] = Math . max ( dp [ j ] , dp [ i ] + 1 ) ; } } } return Math . max . apply ( Math , dp ) ; } var arr = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; var N = arr . length ; document . write ( findMaxLength ( N , arr ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binary_search ( vec , a , n ) { let low , high , mid ; low = 0 ; high = n - 1 ; while ( low < high ) { mid = low + Math . floor ( ( high - low + 1 ) / 2 ) ; if ( vec [ mid ] [ 0 ] > a ) { high = mid - 1 ; } else if ( vec [ mid ] [ 1 ] <= a ) { low = mid ; } } return low ; } function modify_vec ( v , n ) { for ( let i = 1 ; i < n ; i ++ ) { v [ i ] [ 1 ] = Math . min ( v [ i ] [ 1 ] , v [ i - 1 ] [ 1 ] ) ; } } function evaluate_query ( v , n , m1 , m2 ) { let temp = binary_search ( v , n , m1 ) ; if ( ( v [ temp ] [ 0 ] <= m1 ) && ( v [ temp ] [ 1 ] <= m2 ) ) { return 1 ; } return 0 ; } function checkPairs ( v , queries ) { let n = v . length ; v . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] } ) ; modify_vec ( v , n ) ; let k = queries . length ; for ( let i = 0 ; i < k ; i ++ ) { let m1 = queries [ i ] [ 0 ] ; let m2 = queries [ i ] [ 1 ] ; let result = evaluate_query ( v , n , m1 , m2 ) ; if ( result > 0 ) document . write ( " " ) ; else document . write ( " " ) ; } } let arr = [ [ 3 , 5 ] , [ 2 , 7 ] , [ 2 , 3 ] , [ 4 , 9 ] ] ; let queries = [ [ 3 , 4 ] , [ 3 , 2 ] , [ 4 , 1 ] , [ 3 , 7 ] ] ; checkPairs ( arr , queries ) ;

Index/key variables: i, mid, temp
Accumulator variables: i
Iterator variables: i