dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let N = 100002 ; let tree = new Array ( 4 * N ) ; function build ( arr , node , start , end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } let mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } function query ( node , start , end , l , r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } let mid = ( start + end ) >> 1 ; let q1 = query ( 2 * node , start , mid , l , r ) ; let q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } function countSubArrays ( arr , n , K ) { build ( arr , 1 , 0 , n - 1 ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let bitwise_or = query ( 1 , 0 , n - 1 , i , j ) ; if ( bitwise_or >= K ) count ++ ; } } return count ; } let arr = [ 3 , 4 , 5 ] ; let n = arr . length ; let k = 6 ; document . write ( countSubArrays ( arr , n , k ) ) ;

Index/key variables: node, start
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let N = 100002 ; let tree = new Array ( 4 * N ) ; function build ( arr , node , start , end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } let mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } function query ( node , start , end , l , r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } let mid = ( start + end ) >> 1 ; let q1 = query ( 2 * node , start , mid , l , r ) ; let q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } function countSubArrays ( arr , n , K ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let low = i , high = n - 1 , index = Number . MAX_VALUE ; while ( low <= high ) { let mid = ( low + high ) >> 1 ; if ( query ( 1 , 0 , n - 1 , i , mid ) >= K ) { index = Math . min ( index , mid ) ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( index != Number . MAX_VALUE ) { count += n - index ; } } return count ; } let arr = [ 3 , 4 , 5 ] ; let n = arr . length ; build ( arr , 1 , 0 , n - 1 ) ; let k = 6 ; document . write ( countSubArrays ( arr , n , k ) ) ;

Index/key variables: node, start
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countPattern ( n , pat ) { let pattern_int = 0 ; let power_two = 1 ; let all_ones = 0 ; for ( let i = pat . length - 1 ; i >= 0 ; i -- ) { let current_bit = pat . charAt ( i ) - ' ' ; pattern_int += ( power_two * current_bit ) ; all_ones = all_ones + power_two ; power_two = power_two * 2 ; } let count = 0 ; while ( n != 0 && n >= pattern_int ) { if ( ( n & all_ones ) == pattern_int ) { count ++ ; } n = n >> 1 ; } return count ; } let n = 500 ; let pat = " " ; document . write ( countPattern ( n , pat ) ) ;

Accumulator variables: count, i, pattern_int
Iterator variables: i
Javascript program:
var MAX = 1000001 ; var primeUpto = Array ( MAX ) . fill ( 0 ) ; function SieveOfEratosthenes ( ) { var isPrime = Array ( MAX ) . fill ( 1 ) ; isPrime [ 0 ] = isPrime [ 1 ] = 0 ; for ( var i = 2 ; i * i < MAX ; i ++ ) { if ( isPrime [ i ] ) { for ( var j = i * 2 ; j < MAX ; j += i ) isPrime [ j ] = 0 ; } } for ( var i = 1 ; i < MAX ; i ++ ) { primeUpto [ i ] = primeUpto [ i - 1 ] ; if ( isPrime [ i ] ) primeUpto [ i ] ++ ; } } function countOfNumbers ( N , K ) { SieveOfEratosthenes ( ) ; var low = 1 , high = N , ans = 0 ; while ( low <= high ) { var mid = ( low + high ) >> 1 ; if ( mid - primeUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ( ans ? N - ans + 1 : 0 ) ; } var N = 10 , K = 3 ; document . write ( countOfNumbers ( N , K ) ) ;

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

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function diagonalsMinMax ( mat ) { let n = mat . length ; if ( n == 0 ) return ; let principalMin = mat [ 0 ] [ 0 ] , principalMax = mat [ 0 ] [ 0 ] ; let secondaryMin = mat [ n - 1 ] [ 0 ] , secondaryMax = mat [ n - 1 ] [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( mat [ i ] [ i ] < principalMin ) { principalMin = mat [ i ] [ i ] ; } if ( mat [ i ] [ i ] > principalMax ) { principalMax = mat [ i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] < secondaryMin ) { secondaryMin = mat [ n - 1 - i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] > secondaryMax ) { secondaryMax = mat [ n - 1 - i ] [ i ] ; } } document . write ( " " + principalMin + " " ) ; document . write ( " " + principalMax + " " ) ; document . write ( " " + secondaryMin + " " ) ; document . write ( " " + secondaryMax + " " ) ; } let matrix = [ [ 1 , 2 , 3 , 4 , - 10 ] , [ 5 , 6 , 7 , 8 , 6 ] , [ 1 , 2 , 11 , 3 , 4 ] , [ 5 , 6 , 70 , 5 , 8 ] , [ 4 , 9 , 7 , 1 , - 5 ] ] ; diagonalsMinMax ( matrix ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkSorted ( n , arr ) { var first = 0 , second = 0 ; var count = 0 ; for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { count ++ ; if ( first == 0 ) first = i ; else second = i ; } } if ( count > 2 ) return false ; if ( count == 0 ) return true ; if ( count == 2 ) [ arr [ first - 1 ] , arr [ second ] ] = [ arr [ second ] , arr [ first - 1 ] ] ; else if ( count == 1 ) [ arr [ first - 1 ] , arr [ first ] ] = [ arr [ first ] , arr [ first - 1 ] ] ; for ( var i = 1 ; i < n ; i ++ ) if ( arr [ i ] < arr [ i - 1 ] ) return false ; return true ; } var arr = [ 1 , 4 , 3 , 2 ] ; var n = arr . length ; if ( checkSorted ( n , arr ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: first, i, second
Accumulator variables: count, i
Iterator variables: i
Javascript program:
var N = 4 var M = 4 function printIntersection ( A , B ) { for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { if ( A [ i ] [ j ] == B [ i ] [ j ] ) document . write ( A [ i ] [ j ] + " " ) ; else document . write ( " " ) ; } document . write ( " " ) ; } } var A = [ [ 2 , 4 , 6 , 8 ] , [ 1 , 3 , 5 , 7 ] , [ 8 , 6 , 4 , 2 ] , [ 7 , 5 , 3 , 1 ] ] ; var B = [ [ 2 , 3 , 6 , 8 ] , [ 1 , 3 , 5 , 2 ] , [ 8 , 1 , 4 , 2 ] , [ 3 , 5 , 4 , 1 ] ] ; printIntersection ( A , B ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countWays ( arr , n ) { let max_val = 0 ; for ( let i = 0 ; i < n ; i ++ ) max_val = Math . max ( max_val , arr [ i ] ) ; let freq = new Array ( max_val + 1 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; ans += freq [ 0 ] * ( freq [ 0 ] - 1 ) * ( freq [ 0 ] - 2 ) / 6 ; for ( let i = 1 ; i <= max_val ; i ++ ) ans += freq [ 0 ] * freq [ i ] * ( freq [ i ] - 1 ) / 2 ; for ( let i = 1 ; 2 * i <= max_val ; i ++ ) ans += freq [ i ] * ( freq [ i ] - 1 ) / 2 * freq [ 2 * i ] ; for ( let i = 1 ; i <= max_val ; i ++ ) { for ( let j = i + 1 ; i + j <= max_val ; j ++ ) ans += freq [ i ] * freq [ j ] * freq [ i + j ] ; } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( countWays ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function LongestSubarray ( arr , n , k ) { let count = 1 ; let max_length = 1 ; let prev_mod = arr [ 0 ] % k ; for ( let i = 1 ; i < n ; i ++ ) { let curr_mod = arr [ i ] % k ; if ( curr_mod == prev_mod ) { count ++ ; } else { max_length = Math . max ( max_length , count ) ; count = 1 ; prev_mod = curr_mod ; } } return Math . max ( max_length , count ) ; } let arr = [ 4 , 9 , 7 , 18 , 29 , 11 ] ; let n = arr . length ; let k = 11 ; document . write ( LongestSubarray ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
var M = 3 ; var N = 4 ; function binarySearch1D ( arr , K ) { var low = 0 ; var high = N - 1 ; while ( low <= high ) { var mid = low + parseInt ( ( high - low ) / 2 ) ; if ( arr [ mid ] == K ) return true ; if ( arr [ mid ] < K ) low = mid + 1 ; else high = mid - 1 ; } return false ; } function searchMatrix ( matrix , K ) { var low = 0 ; var high = M - 1 ; while ( low <= high ) { var mid = low + parseInt ( ( high - low ) / 2 ) ; if ( K >= matrix [ mid ] [ 0 ] && K <= matrix [ mid ] [ N - 1 ] ) return binarySearch1D ( matrix [ mid ] , K ) ; if ( K < matrix [ mid ] [ 0 ] ) high = mid - 1 ; else low = mid + 1 ; } return false ; } var matrix = [ [ 1 , 3 , 5 , 7 ] , [ 10 , 11 , 16 , 20 ] , [ 23 , 30 , 34 , 50 ] ] ; var K = 3 ; if ( searchMatrix ( matrix , K ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: mid
Javascript program:
function replacePi ( input ) { var output = " " ; var size = input . length ; for ( var i = 0 ; i < size ; ++ i ) { if ( i + 1 < size && input [ i ] === " " && input [ i + 1 ] === " " ) { output += " " ; i ++ ; } else { output += input [ i ] ; } } return output ; } var input = " " ; document . write ( replacePi ( input ) ) ;

Index/key variables: i
Accumulator variables: i, output
Iterator variables: i
Javascript program:
function numberOfElements ( height , n ) { var max_so_far = 0 ; var coun = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] > max_so_far ) { max_so_far = height [ i ] ; coun ++ ; } } return coun ; } var n = 6 ; var height = [ 4 , 8 , 2 , 0 , 0 , 5 ] ; document . write ( numberOfElements ( height , n ) ) ;

Index/key variables: i
Accumulator variables: coun, i
Iterator variables: i
Javascript program:
var MAX = 100000 ; class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function check_pair_product ( head , prod ) { var s = [ ] ; var p = head ; while ( p != null ) { var curr = p . data ; if ( prod % curr == 0 && s . includes ( prod / curr ) ) { document . write ( curr + " " + prod / curr ) ; return true ; } s . push ( p . data ) ; p = p . next ; } return false ; } var head = null ; head = push ( head , 1 ) ; head = push ( head , 2 ) ; head = push ( head , 1 ) ; head = push ( head , 12 ) ; head = push ( head , 1 ) ; head = push ( head , 18 ) ; head = push ( head , 47 ) ; head = push ( head , 16 ) ; head = push ( head , 12 ) ; head = push ( head , 14 ) ; var res = check_pair_product ( head , 24 ) ; if ( res == false ) document . write ( " " ) ;

Class/struct names: Node
Javascript program:
function solve ( arr , n , k ) { arr . sort ( ( a , b ) => a - b ) if ( k == 1 && arr [ n - 2 ] != arr [ n - 1 ] ) { cout << arr [ n - 1 ] << endl ; return ; } var count = 1 ; for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == arr [ i + 1 ] ) count ++ ; else count = 1 ; if ( count == k && ( i == 0 || ( arr [ i - 1 ] != arr [ i ] ) ) ) { document . write ( arr [ i ] + " " ) ; return ; } } document . write ( " " ) ; } var arr = [ 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 ] ; var k = 2 ; var n = arr . length ; solve ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function solve ( arr , n , k ) { var m = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } var max = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { if ( m . get ( arr [ i ] ) == k && max == - 1000000000 ) { max = arr [ i ] ; } else if ( m . get ( arr [ i ] ) == k && max < arr [ i ] ) { max = arr [ i ] ; } } if ( max == - 1000000000 ) document . write ( " " ) ; else document . write ( max ) ; } var arr = [ 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 ] ; var k = 4 ; var n = arr . length ; solve ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getMin ( arr , n ) { let res = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) res = Math . min ( res , arr [ i ] ) ; return res ; } function getMax ( arr , n ) { let res = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) res = Math . max ( res , arr [ i ] ) ; return res ; } function findSum ( arr , n ) { let min = getMin ( arr , n ) ; let max = getMax ( arr , n ) ; return min + max ; } function findProduct ( arr , n ) { let min = getMin ( arr , n ) ; let max = getMax ( arr , n ) ; return min * max ; } let arr = [ 12 , 1234 , 45 , 67 , 1 ] ; let n = arr . length ; document . write ( " " + findSum ( arr , n ) + " " ) ; document . write ( " " + findProduct ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countEle ( s , a , N ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; ++ i ) { var num = a [ i ] ; if ( mp . has ( num ) ) document . write ( " " ) ; else { var cnt = 0 ; while ( s [ s . length - 1 ] != num ) { mp . set ( s [ s . length - 1 ] , true ) ; s . pop ( ) ; cnt ++ ; } s . pop ( ) ; cnt ++ ; document . write ( cnt + " " ) ; } } } var N = 5 ; var s = [ ] ; s . push ( 1 ) ; s . push ( 2 ) ; s . push ( 3 ) ; s . push ( 4 ) ; s . push ( 6 ) ; var a = [ 6 , 3 , 4 , 1 , 2 ] ; countEle ( s , a , N ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Javascript program:
function countChar ( str ) { var n = str . length ; if ( n <= 2 ) return n ; var count = 2 ; for ( var i = 1 ; i < n - 1 ; i ++ ) if ( str [ i - 1 ] == str [ i + 1 ] ) count ++ ; return count ; } var str = " " ; document . write ( countChar ( str ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
let prime = new Array ( 1000000 + 5 ) ; function findPrime ( ) { prime . fill ( true ) prime [ 1 ] = false ; for ( let p = 2 ; p * p <= 1000000 ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= 1000000 ; i += p ) prime [ i ] = false ; } } } function lenOfLongSubarr ( arr , n ) { let um = new Map ( ) ; let sum = 0 , maxLen = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += prime [ arr [ i ] ] == 0 ? - 1 : 1 ; if ( sum == 1 ) maxLen = i + 1 ; else if ( ! um . has ( sum ) ) um . set ( sum , i ) ; if ( um . has ( sum - 1 ) ) { if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ; } } return maxLen ; } findPrime ( ) ; let arr = [ 1 , 9 , 3 , 4 , 5 , 6 , 7 , 8 ] ; let n = arr . length ; document . write ( lenOfLongSubarr ( arr , n ) + " " )

Index/key variables: i, p
Accumulator variables: i, p, sum
Iterator variables: i, p
Javascript program:
function next ( arr , target ) { let start = 0 , end = arr . length - 1 ; let ans = - 1 ; while ( start <= end ) { let mid = parseInt ( ( start + end ) / 2 , 10 ) ; if ( arr [ mid ] <= target ) { start = mid + 1 ; } else { ans = mid ; end = mid - 1 ; } } return ans ; } let arr = [ 1 , 2 , 3 , 5 , 8 , 12 ] ; document . write ( next ( arr , 8 ) ) ;

Index/key variables: mid
Javascript program:
function search ( arr , n , x ) { let res = - 1 ; for ( let i = 0 ; i < n ; i ++ ) if ( x == arr [ i ] ) res = i ; if ( res == - 1 ) return false ; let temp = arr [ res ] ; for ( let i = res ; i > 0 ; i -- ) arr [ i ] = arr [ i - 1 ] ; arr [ 0 ] = temp ; return true ; } let arr = [ 12 , 25 , 36 , 85 , 98 , 75 , 89 , 15 , 63 , 66 , 64 , 74 , 27 , 83 , 97 ] ; let q = [ 63 , 63 , 86 , 63 , 78 ] ; let n = arr . length ; let m = q . length ; for ( let i = 0 ; i < m ; i ++ ) search ( arr , n , q [ i ] ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, res
Accumulator variables: i
Iterator variables: i
Javascript program:
function kPresentProbability ( a , n , k ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] == k ) count += 1 ; return count / n ; } let A = [ 4 , 7 , 2 , 0 , 8 , 7 , 5 ] ; let K = 3 ; let N = A . length ; document . write ( kPresentProbability ( A , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function slopeOfNum ( num , n ) { let slope = 0 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( num [ i ] > num [ i - 1 ] && num [ i ] > num [ i + 1 ] ) slope ++ ; else if ( num [ i ] < num [ i - 1 ] && num [ i ] < num [ i + 1 ] ) slope ++ ; } return slope ; } let num = " " ; let n = num . length ; document . write ( " " + slopeOfNum ( num , n ) ) ;

Index/key variables: i
Accumulator variables: i, slope
Iterator variables: i
Javascript program:
function pairExists ( arr1 , m , arr2 , n ) { let s = new Set ( ) ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( s . has ( arr2 [ j ] - arr1 [ i ] ) ) return true ; } s . add ( arr1 [ i ] ) ; } return false ; } let arr1 = [ 1 , 5 , 10 , 8 ] ; let arr2 = [ 2 , 20 , 13 ] ; if ( pairExists ( arr1 , 4 , arr2 , 3 ) ) document . write ( 1 + " " ) ; else document . write ( 0 + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let cumulativeValue = 0 ; function canBeOptimalValue ( K , arr , N , B ) { let tmp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) tmp [ i ] = ( arr [ i ] + K * ( i + 1 ) ) ; tmp . sort ( ( a , b ) => a - b ) ; cumulativeValue = 0 ; for ( let i = 0 ; i < K ; i ++ ) cumulativeValue += tmp [ i ] ; return cumulativeValue <= B ; } function findNoOfElementsandValue ( arr , N , B ) { let ans = 0 ; while ( start <= end ) { let mid = Math . floor ( ( start + end ) / 2 ) ; if ( canBeOptimalValue ( mid , arr , N , B ) ) { ans = mid ; start = mid + 1 ; } else end = mid - 1 ; } canBeOptimalValue ( ans , arr , N , B , cumulativeValue ) ; document . write ( ans + " " + cumulativeValue + " " ) ; } let arr = [ 1 , 2 , 5 , 6 , 3 ] ; let N = arr . length ; let B = 90 ; findNoOfElementsandValue ( arr , N , B ) ;

Index/key variables: i
Accumulator variables: cumulativeValue, i
Iterator variables: i
Javascript program:
function prevGreater ( arr , n ) { document . write ( " " ) ; for ( let i = 1 ; i < n ; i ++ ) { let j ; for ( j = i - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] < arr [ j ] ) { document . write ( arr [ j ] + " " ) ; break ; } } if ( j == - 1 ) document . write ( " " ) ; } } let arr = [ 10 , 4 , 2 , 20 , 40 , 12 , 30 ] ; let n = arr . length ; prevGreater ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function prevGreater ( arr , n ) { let s = [ ] ; s . push ( arr [ 0 ] ) ; document . write ( " " ) ; for ( let i = 1 ; i < n ; i ++ ) { while ( s . length != 0 && s [ s . length - 1 ] < arr [ i ] ) s . pop ( ) ; if ( s . length == 0 ) document . write ( " " ) ; else document . write ( s [ s . length - 1 ] + " " ) ; s . push ( arr [ i ] ) ; } } let arr = [ 10 , 4 , 2 , 20 , 40 , 12 , 30 ] ; let n = arr . length ; prevGreater ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printDuplicates ( arr , n ) { let i ; let fl = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ arr [ i ] % n ] >= n ) { if ( arr [ arr [ i ] % n ] < 2 * n ) { document . write ( arr [ i ] % n + " " ) ; fl = 1 ; } } arr [ arr [ i ] % n ] += n ; } if ( ! fl ) document . write ( " " ) ; } let arr = [ 1 , 6 , 3 , 1 , 3 , 6 , 6 ] ; let arr_size = arr . length ; printDuplicates ( arr , arr_size ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMissingNo ( arr , n ) { var val ; var nextval ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] <= 0 arr [ i ] > n ) continue ; val = arr [ i ] ; while ( arr [ val - 1 ] != val ) { nextval = arr [ val - 1 ] ; arr [ val - 1 ] = val ; val = nextval ; if ( val <= 0 val > n ) break ; } } for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != i + 1 ) { return i + 1 ; } } return n + 1 ; } var arr = [ 2 , 3 , 7 , 6 , 8 , - 1 , - 10 , 15 ] ; var arr_size = arr . length ; var missing = findMissingNo ( arr , arr_size ) ; document . write ( " " + missing ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findTriplets ( arr , n , sum ) { for ( let i = 0 ; i < n - 2 ; i ++ ) { for ( let j = i + 1 ; j < n - 1 ; j ++ ) { for ( let k = j + 1 ; k < n ; k ++ ) { if ( arr [ i ] + arr [ j ] + arr [ k ] == sum ) { document . write ( arr [ i ] + " " + arr [ j ] + " " + arr [ k ] + " " ) ; } } } } } let arr = [ 0 , - 1 , 2 , - 3 , 1 ] ; let n = arr . length ; findTriplets ( arr , n , - 2 ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findTriplets ( arr , n , sum ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { let s = new Set ( ) ; for ( let j = i + 1 ; j < n ; j ++ ) { let x = sum - ( arr [ i ] + arr [ j ] ) ; if ( s . has ( x ) ) document . write ( x + " " + arr [ i ] + " " + arr [ j ] + " " ) ; else s . add ( arr [ j ] ) ; } } } let arr = [ 0 , - 1 , 2 , - 3 , 1 ] ; let sum = - 2 ; let n = arr . length ; findTriplets ( arr , n , sum ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxProduct ( arr , n ) { if ( n < 4 ) return - 1 ; let max_product = Number . MIN_VALUE ; for ( let i = 0 ; i < n - 3 ; i ++ ) for ( let j = i + 1 ; j < n - 2 ; j ++ ) for ( let k = j + 1 ; k < n - 1 ; k ++ ) for ( let l = k + 1 ; l < n ; l ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] * arr [ l ] ) ; return max_product ; } let arr = [ 10 , 3 , 5 , 6 , 20 ] ; let n = arr . length ; let max = maxProduct ( arr , n ) ; if ( max == - 1 ) document . write ( " " ) ; else document . write ( " " + max ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function maxSum ( arr , n ) { if ( n < 2 ) return - 1 ; let ans = arr [ 0 ] + arr [ 1 ] ; for ( let i = 1 ; i + 1 < n ; i ++ ) ans = Math . min ( ans , ( arr [ i ] + arr [ i + 1 ] ) ) ; return ans ; } let arr = [ 1 , 12 , 2 , 2 ] ; let n = arr . length ; document . write ( maxSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortString ( str , n ) { var new_str = " " ; for ( var i = ' ' . charCodeAt ( 0 ) ; i <= ' ' . charCodeAt ( 0 ) ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) if ( str [ j ] . charCodeAt ( 0 ) == i ) new_str += str [ j ] ; return new_str ; } var str = " " ; var n = str . length ; document . write ( sortString ( str , n ) ) ;

Index/key variables: j
Accumulator variables: i, j, new_str
Iterator variables: i, j
Javascript program:
function sortString ( str , n ) { var i ; var arr = Array ( 26 ) . fill ( 0 ) ; var new_str = " " ; for ( i = 0 ; i < n ; i ++ ) ++ arr [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; for ( i = 0 ; i < 26 ; i ++ ) while ( arr [ i ] -- ) new_str += String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; return new_str ; } var str = " " ; var n = str . length ; document . write ( sortString ( str , n ) ) ;

Index/key variables: i
Accumulator variables: i, new_str
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } var head = null ; function maxChar ( head ) { var p = head ; var hash = new Array ( 256 ) . fill ( 0 ) ; while ( p != null ) { hash [ p . data . charCodeAt ( 0 ) ] ++ ; p = p . next ; } p = head ; var max = - 1 ; var res = " " ; while ( p != null ) { if ( max < hash [ p . data . charCodeAt ( 0 ) ] ) { res = p . data ; max = hash [ p . data . charCodeAt ( 0 ) ] ; } p = p . next ; } return res ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; head = head_ref ; } head = null ; var str = " " . split ( " " ) ; for ( var i = 0 ; i < str . length ; i ++ ) { push ( head , str [ i ] ) ; } document . write ( maxChar ( head ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node