dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Maxlen ( arr , n ) { let ans = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) count = 0 ; else count ++ ; ans = Math . max ( ans , count ) ; } return ans ; } let arr = [ 1 , 7 , 2 ] ; let n = arr . length ; document . write ( Maxlen ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function get_submaxarr ( arr , n , y ) { var j = 0 ; var stk = [ ] ; var maxarr = Array ( n ) ; stk . push ( 0 ) ; for ( var i = 1 ; i < n ; i ++ ) { while ( stk . length != 0 && arr [ i ] > arr [ stk [ stk . length - 1 ] ] ) { maxarr [ stk [ stk . length - 1 ] ] = i - 1 ; stk . pop ( ) ; } stk . push ( i ) ; } while ( stk . length != 0 ) { maxarr [ stk [ stk . length - 1 ] ] = n - 1 ; stk . pop ( ) ; } var submax = [ ] ; for ( var i = 0 ; i <= n - y ; i ++ ) { while ( maxarr [ j ] < i + y - 1 j < i ) { j ++ ; } submax . push ( arr [ j ] ) ; } return submax ; } function get_subminarr ( arr , n , y ) { var j = 0 ; var stk = [ ] ; var minarr = Array ( n ) ; stk . push ( 0 ) ; for ( var i = 1 ; i < n ; i ++ ) { while ( stk . length != 0 && arr [ i ] < arr [ stk [ stk . length - 1 ] ] ) { minarr [ stk [ stk . length - 1 ] ] = i ; stk . pop ( ) ; } stk . push ( i ) ; } while ( stk . length != 0 ) { minarr [ stk [ stk . length - 1 ] ] = n ; stk . pop ( ) ; } var submin = [ ] ; for ( var i = 0 ; i <= n - y ; i ++ ) { while ( minarr [ j ] <= i + y - 1 j < i ) { j ++ ; } submin . push ( arr [ j ] ) ; } return submin ; } function getMinDifference ( Arr , N , Y ) { var submin = get_subminarr ( Arr , N , Y ) ; var submax = get_submaxarr ( Arr , N , Y ) ; var minn = submax [ 0 ] - submin [ 0 ] ; var b = submax . length ; for ( var i = 1 ; i < b ; i ++ ) { var dif = submax [ i ] - submin [ i ] ; minn = Math . min ( minn , dif ) ; } document . write ( minn + " " ) ; } var arr = [ 1 , 2 , 3 , 3 , 2 , 2 ] ; var N = arr . length var arr = [ 1 , 2 , 3 , 3 , 2 , 2 ] ; var N = arr . length var Y = 4 ; getMinDifference ( arr , N , Y ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
let tree ; let path ; let maxHeight , maxHeightNode ; function getDiameterPath ( vertex , targetVertex , parent , path ) { if ( vertex == targetVertex ) { path . push ( vertex ) ; return true ; } for ( let i = 0 ; i < tree . get ( vertex ) . length ; i ++ ) { if ( tree . get ( vertex ) [ i ] == parent ) continue ; if ( getDiameterPath ( tree . get ( vertex ) [ i ] , targetVertex , vertex , path ) ) { path . push ( vertex ) ; return true ; } } return false ; } function farthestNode ( vertex , parent , height ) { if ( height > maxHeight ) { maxHeight = height ; maxHeightNode = vertex ; } if ( tree . get ( vertex ) != null ) for ( let i = 0 ; i < tree . get ( vertex ) . length ; i ++ ) { if ( tree . get ( vertex ) [ i ] == parent ) continue ; farthestNode ( tree . get ( vertex ) [ i ] , vertex , height + 1 ) ; } } function addedge ( a , b ) { if ( tree . get ( a ) == null ) tree . set ( a , [ ] ) ; tree . get ( a ) . push ( b ) ; if ( tree . get ( b ) == null ) tree . set ( b , [ ] ) ; tree . get ( b ) . push ( a ) ; } function FindCenter ( n ) { maxHeight = - 1 ; maxHeightNode = - 1 ; farthestNode ( 0 , - 1 , 0 ) ; let leaf1 = maxHeightNode ; maxHeight = - 1 ; farthestNode ( maxHeightNode , - 1 , 0 ) ; let leaf2 = maxHeightNode ; path = [ ] ; getDiameterPath ( leaf1 , leaf2 , - 1 , path ) ; let pathSize = path . length ; if ( pathSize % 2 == 1 ) { document . write ( path [ parseInt ( pathSize / 2 , 10 ) ] ) ; } else { document . write ( path [ parseInt ( pathSize / 2 , 10 ) ] + " " + path [ parseInt ( ( pathSize - 1 ) / 2 , 10 ) ] ) ; } } let N = 4 ; tree = new Map ( ) ; addedge ( 1 , 0 ) ; addedge ( 1 , 2 ) ; addedge ( 1 , 3 ) ; FindCenter ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxm = 1000000000 ; function count ( v , n ) { let i , odd = 0 , even = 0 ; let j , d , count ; let t = 1 << v . length ; let size = v . length ; for ( i = 1 ; i < t ; i ++ ) { d = 1 ; count = 0 ; for ( j = 0 ; j < size ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { d *= v [ j ] ; count ++ ; } } if ( count % 2 == 1 ) odd += n / d ; else even += n / d ; } return ( odd - even ) ; } function BinarySearch ( l , r , v , key ) { let mid ; while ( r - l > 1 ) { mid = Math . floor ( ( l + r ) / 2 ) ; if ( key <= count ( v , mid ) ) { r = mid ; } else { l = mid ; } } if ( key == count ( v , l ) ) return l ; else return r ; } let N = 2 , K = 10 ; let v = [ 2 , 3 ] ; document . write ( BinarySearch ( 1 , maxm , v , K ) + " " ) ;

Index/key variables: j
Accumulator variables: count, d, even, i, j, odd
Iterator variables: i, j
Javascript program:
function minDistancePoints ( A , K , n ) { let m = new Map ( ) ; let q = [ ] ; for ( let i = 0 ; i < n ; ++ i ) { m . set ( A [ i ] , true ) ; q . push ( A [ i ] ) ; } let ans = [ ] ; while ( K > 0 ) { let x = q . shift ( ) ; if ( ! m . has ( x - 1 ) && K > 0 ) { m . set ( x - 1 , true ) ; q . push ( x - 1 ) ; ans . push ( x - 1 ) ; K -- ; } if ( ! m . has ( x + 1 ) && K > 0 ) { m . set ( x + 1 , true ) ; q . push ( x + 1 ) ; ans . push ( x + 1 ) ; K -- ; } } for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ; } let A = [ - 1 , 4 , 6 ] ; let K = 3 ; let n = A . length ; minDistancePoints ( A , K , n ) ;

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
Javascript program:
var N = 3 ; function search ( mat , n , m ) { var i , a = 1000000000 ; for ( i = 0 ; i < n ; i ++ ) { var low = 0 ; var high = m - 1 ; var mid ; var ans = 1000000000 ; while ( low <= high ) { mid = parseInt ( ( low + high ) / 2 ) ; if ( mat [ i ] [ mid ] == 1 ) { if ( mid == 0 ) { ans = 0 ; break ; } else if ( mat [ i ] [ mid - 1 ] == 0 ) { ans = mid ; break ; } } if ( mat [ i ] [ mid ] == 1 ) high = mid - 1 ; else low = mid + 1 ; } if ( ans < a ) a = ans ; } if ( a == 1000000000 ) return - 1 ; return a + 1 ; } var mat = [ [ 0 , 0 , 0 ] , [ 0 , 0 , 1 ] , [ 0 , 1 , 1 ] ] ; document . write ( search ( mat , 3 , 3 ) ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubString ( S , K , N ) { function maxSubString ( S , K , N ) { var freq = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; ++ i ) { freq [ S [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = 1 ; } var answer = [ ] ; for ( var i = 0 ; i < 26 ; ++ i ) { if ( freq [ i ] === 0 ) continue ; var ch = String . fromCharCode ( i + 97 ) ; var count = 0 ; var index = - 1 ; for ( var j = 0 ; j < N ; ++ j ) { if ( S [ j ] === ch ) count ++ ; if ( count === K ) index = j ; } answer . push ( [ ch , index ] ) ; } var flag = 0 ; for ( var i = 0 ; i < answer . length ; ++ i ) { if ( answer [ i ] [ 1 ] > - 1 ) { flag = 1 ; document . write ( answer [ i ] [ 0 ] + " " + answer [ i ] [ 1 ] + " " ) ; } } if ( flag === 0 ) document . write ( " " + " " ) ; } var S = " " ; var K = 2 ; var N = S . length ; maxSubString ( S . split ( " " ) , K , N ) ;

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Javascript program:
function greaterK ( n , k ) { let p = new Array ( String ( n ) . length + 2 ) . fill ( 0 ) ; let index = 0 ; let x = n ; while ( x > 0 ) { p [ index ] = ( x % k ) ; x = Math . floor ( x / k ) ; index ++ ; } let idx = 0 ; for ( let i = 0 ; i < p . length - 1 ; ++ i ) { if ( p [ i ] >= 2 ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; for ( let j = idx ; j < i ; ++ j ) { p [ j ] = 0 ; } idx = i + 1 ; } if ( p [ i ] == k ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; } } let j = p . length - 1 ; if ( p [ j ] >= 2 ) { p [ index ] = 1 ; index ++ ; } let ans = 0 ; for ( let i = p . length - 1 ; i >= 0 ; -- i ) { ans = ans * k + p [ i ] ; } document . write ( ans + " " ) ; } let n = 29 , k = 7 ; greaterK ( n , k ) ;

Index/key variables: i, index, j
Accumulator variables: index
Iterator variables: i, j
Javascript program:
function canBeBalanced ( s , n ) { var count = 0 , count_1 = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) count ++ ; else count -- ; count_1 = Math . min ( count_1 , count ) ; } if ( count_1 >= - 1 && count == 0 ) return true ; return false ; } var s = " " ; var n = s . length ; if ( canBeBalanced ( s , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function calculateDifference ( arr , n ) { let max_val = Math . max ( ... arr ) ; let prime = new Array ( max_val + 1 ) . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } let X1 = 1 , X2 = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { X1 ^= arr [ i ] ; } else if ( arr [ i ] != 1 ) { X2 ^= arr [ i ] ; } } return Math . abs ( X1 - X2 ) ; } let arr = [ 1 , 3 , 5 , 10 , 15 , 7 ] ; let n = arr . length ; document . write ( calculateDifference ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: X1, X2, i, p
Iterator variables: i, p
Javascript program:
class Node { constructor ( ) { var data ; var next ; } } function insert ( head , item ) { var temp = new Node ( ) ; temp . data = item ; temp . next = head ; head = temp ; return head ; } function countNode ( head ) { let count = 0 ; while ( head . next != null ) { let ptr = head . next ; while ( ptr != null ) { if ( head . data == ptr . data ) { count ++ ; break ; } ptr = ptr . next ; } head = head . next ; } return count ; } var head = null ; head = insert ( head , 5 ) ; head = insert ( head , 7 ) ; head = insert ( head , 5 ) ; head = insert ( head , 1 ) ; head = insert ( head , 7 ) ; document . write ( countNode ( head ) ) ;

Accumulator variables: count
Class/struct names: Node
Javascript program:
function maxSumArray ( arr , n ) { var sum = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) } var minimum = 1000000000 ; mp . forEach ( ( value , key ) => { minimum = Math . min ( minimum , value * key ) ; } ) ; return ( sum - minimum ) ; } var arr = [ 1 , 1 , 3 , 3 , 2 , 2 , 1 , 1 , 1 ] ; var n = arr . length ; document . write ( maxSumArray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let MAX = 101 ; let prefix = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { prefix [ i ] = new Array ( MAX ) . fill ( 0 ) } let ar = new Array ( MAX ) . fill ( 0 ) ; function cal_prefix ( n , arr ) { for ( let i = 0 ; i < n ; i ++ ) ar [ i + 1 ] = arr [ i ] ; for ( let i = 1 ; i < MAX ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) prefix [ i ] [ j ] = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { prefix [ i ] [ j ] = prefix [ i ] [ j - 1 ] + ( ar [ j ] <= i ? 1 : 0 ) ; } } } function ksub ( l , r , n , k ) { let lo = 1 ; let hi = MAX - 1 ; while ( lo + 1 < hi ) { let mid = Math . floor ( ( lo + hi ) / 2 ) ; if ( prefix [ mid ] [ r ] - prefix [ mid ] [ l - 1 ] >= k ) hi = mid ; else lo = mid + 1 ; } if ( prefix [ lo ] [ r ] - prefix [ lo ] [ l - 1 ] >= k ) hi = lo ; return hi ; } let arr = new Array ( 1 , 4 , 2 , 3 , 5 , 7 , 6 ) ; let n = arr . length ; let k = 4 ; cal_prefix ( n , arr ) ; let queries = new Array ( new Array ( 1 , n , 1 ) , new Array ( 2 , n - 2 , 2 ) , new Array ( 3 , n - 1 , 3 ) ) ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) document . write ( ksub ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , n , queries [ i ] [ 2 ] ) + " " ) ;

Index/key variables: i, j, lo, mid, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function squareSum ( N ) { let sum = parseInt ( ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ) ; return sum ; } function findMaxN ( X ) { let N = Math . sqrt ( X ) ; for ( let i = 1 ; i <= N ; i ++ ) { if ( squareSum ( i ) > X ) return i - 1 ; } return - 1 ; } let X = 25 ; document . write ( findMaxN ( X ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function max_min ( a , n ) { if ( n <= 1 ) return Number . MAX_VALUE ; let f_min = a [ 0 ] , s_min = Number . MAX_VALUE ; let f_max = a [ 0 ] , s_max = Number . MIN_VALUE ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= f_min ) { s_min = f_min ; f_min = a [ i ] ; } else if ( a [ i ] < s_min ) { s_min = a [ i ] ; } if ( a [ i ] >= f_max ) { s_max = f_max ; f_max = a [ i ] ; } else if ( a [ i ] > s_max ) { s_max = a [ i ] ; } } return Math . min ( ( f_max - s_min ) , ( s_max - f_min ) ) ; } let a = [ 1 , 3 , 3 , 7 ] ; let n = a . length ; document . write ( max_min ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimal ( a , n ) { let lo = 0 , hi = n - 1 ; while ( lo < hi ) { let mid = ( lo + hi ) >> 1 ; if ( a [ mid ] < a [ mid + 1 ] ) { hi = mid ; } else { lo = mid + 1 ; } } return lo ; } let a = [ 8 , 5 , 4 , 3 , 4 , 10 ] ; let n = a . length ; let ind = minimal ( a , n ) ; document . write ( a [ ind ] ) ;

Index/key variables: ind, mid
Javascript program:
function findIndices ( arr , n ) { let leftMin = 0 , rightMin = 0 ; let leftMax = 0 , rightMax = 0 ; let min = arr [ 0 ] , max = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < min ) { leftMin = rightMin = i ; min = arr [ i ] ; } else if ( arr [ i ] == min ) rightMin = i ; if ( arr [ i ] > max ) { leftMax = rightMax = i ; max = arr [ i ] ; } else if ( arr [ i ] == max ) rightMax = i ; } document . write ( " " + leftMin + " " ) ; document . write ( " " + rightMin + " " ) ; document . write ( " " + leftMax + " " ) ; document . write ( " " + rightMax + " " ) ; } let arr = [ 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 ] ; let n = arr . length ; findIndices ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
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 = 1 ; i < n ; i ++ ) { for ( let j = 1 ; j < n ; j ++ ) { if ( i == j ) { if ( mat [ i ] [ j ] < principalMin ) { principalMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > principalMax ) { principalMax = mat [ i ] [ j ] ; } } if ( ( i + j ) == ( n - 1 ) ) { if ( mat [ i ] [ j ] < secondaryMin ) { secondaryMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > secondaryMax ) { secondaryMax = mat [ i ] [ j ] ; } } } } 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, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getCount ( v , n ) { v . sort ( function ( a , b ) { return a - b ; } ) ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let tmp = n - 1 - upperBound ( v , n , v [ i ] - 1 ) ; if ( tmp == v [ i ] ) cnt ++ ; } return cnt ; } function upperBound ( array , length , value ) { let low = 0 ; let high = length ; while ( low < high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( value >= array [ mid ] ) { low = mid + 1 ; } else { high = mid ; } } return low ; } let n = 4 ; let v = [ 1 , 2 , 3 , 4 ] ; document . write ( getCount ( v , n ) ) ;

Index/key variables: i, mid
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function countSegments ( a , n , x ) { let flag = false ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { flag = true ; } else { if ( flag ) count += 1 ; flag = false ; } } if ( flag ) count += 1 ; return count ; } let a = [ 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 ] ; let n = a . length ; let x = 13 ; document . write ( countSegments ( a , n , x ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function findElements ( arr , n , l , r ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { let a = 0 ; if ( mp . get ( arr [ i ] ) == null ) { a = 1 ; } else { a = mp . get ( arr [ i ] ) + 1 ; } mp . set ( arr [ i ] , a ) ; } for ( let i = 0 ; i < n ; ++ i ) { if ( l <= mp . get ( arr [ i ] ) && ( mp . get ( arr [ i ] ) <= r ) ) { document . write ( arr [ i ] + " " ) ; } } } let arr = [ 1 , 2 , 3 , 3 , 2 , 2 , 5 ] ; let n = arr . length ; let l = 2 , r = 3 ; findElements ( arr , n , l , r ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function count_triples ( n , k ) { var i = 0 , j = 0 , l = 0 ; var count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { for ( l = 1 ; l <= n ; l ++ ) { if ( ( i + j ) % k == 0 && ( i + l ) % k == 0 && ( j + l ) % k == 0 ) count ++ ; } } } return count ; } var n = 3 ; var k = 2 ; var ans = count_triples ( n , k ) ; document . write ( ans ) ;

Accumulator variables: count, i, j, l
Iterator variables: i, j, l
Javascript program:
let maxs = 1000001 ; function kthSmallestLargest ( arr , n , k ) { let max_val = Math . max ( ... arr ) ; let hash = new Array ( max_val + 1 ) ; for ( let i = 0 ; i < hash . length ; i ++ ) { hash [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { hash [ arr [ i ] ] ++ ; } let count = 0 ; for ( let i = 0 ; i <= max_val ; i ++ ) { while ( hash [ i ] > 0 ) { count ++ ; if ( count == k ) { return i ; } hash [ i ] -- ; } } return - 1 ; } let arr = [ 11 , 6 , 2 , 9 , 4 , 3 , 16 ] ; let n = arr . length , k = 3 ; document . write ( " " + kthSmallestLargest ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function bsearch ( A , key_to_search ) { let n = A . length ; let lg = parseInt ( Math . log ( n - 1 ) / Math . log ( 2 ) ) + 1 ; let pos = 0 ; for ( let i = lg ; i >= 0 ; i -- ) { if ( A [ pos ] == key_to_search ) return pos ; let new_pos = pos | ( 1 << i ) ; if ( ( new_pos < n ) && ( A [ new_pos ] <= key_to_search ) ) pos = new_pos ; } return ( ( A [ pos ] == key_to_search ) ? pos : - 1 ) ; } let A = [ - 2 , 10 , 100 , 250 , 32315 ] ; document . write ( bsearch ( A , 10 ) ) ;

Index/key variables: new_pos, pos
Accumulator variables: i
Iterator variables: i
Javascript program:
function answerQueries ( a , n , queries , q ) { let v = [ ] ; let mpp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { v . push ( a [ i ] [ 0 ] ) ; mpp . set ( a [ i ] [ 0 ] , 1 ) ; v . push ( a [ i ] [ 1 ] ) ; mpp . set ( a [ i ] [ 1 ] , 2 ) ; } v . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < q ; i ++ ) { let num = queries [ i ] ; let ind = lowerBound ( v , num ) ; if ( ind >= 0 && v [ ind ] == num ) document . write ( " " ) ; else { if ( ind >= 0 && mpp . get ( v [ ind ] ) == 2 ) document . write ( " " ) ; document . write ( " " ) ; } } } function lowerBound ( array , value ) { let low = 0 ; let high = array . length ; while ( low < high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( value <= array [ mid ] ) { high = mid ; } else { low = mid + 1 ; } } return low ; } let a = [ [ 5 , 6 ] , [ 1 , 3 ] , [ 8 , 10 ] ] ; let n = 3 ; let queries = [ 2 , 3 , 4 , 7 ] ; let q = queries . length ; answerQueries ( a , n , queries , q ) ;

Index/key variables: i, ind, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function findmedian ( a , n1 , b , n2 ) { let i = 0 ; let j = 0 ; let k ; let m1 = - 1 , m2 = - 1 ; for ( k = 0 ; k <= ( n1 + n2 ) / 2 ; k ++ ) { if ( i < n1 && j < n2 ) { if ( a [ i ] < b [ j ] ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } else { m2 = m1 ; m1 = b [ j ] ; j ++ ; } } else if ( i == n1 ) { m2 = m1 ; m1 = b [ j ] ; j ++ ; } else if ( j == n2 ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } } if ( ( n1 + n2 ) % 2 == 0 ) { return ( m1 + m2 ) * 1.0 / 2 ; } return m1 ; } let a = [ 1 , 12 , 15 , 26 , 38 ] ; let b = [ 2 , 13 , 24 ] ; let n1 = a . length ; let n2 = b . length ; document . write ( findmedian ( a , n1 , b , n2 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: k
Javascript program:
function printNSE ( arr , n ) { var next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = - 1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { next = arr [ j ] ; break ; } } document . write ( arr [ i ] + " " + next + " " ) ; } } var arr = [ 11 , 13 , 21 , 3 ] ; var n = arr . length ; printNSE ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function longestSubarray ( input ) { let prev = - 1 ; let current , next ; let prevCount = 0 , currentCount = 1 ; let longest = 1 ; current = input [ 0 ] ; for ( let i = 1 ; i < input . length ; i ++ ) { next = input [ i ] ; if ( next == current ) { currentCount ++ ; } else if ( next == prev ) { prevCount += currentCount ; prev = current ; current = next ; currentCount = 1 ; } else { longest = Math . max ( longest , currentCount + prevCount ) ; prev = current ; prevCount = currentCount ; current = next ; currentCount = 1 ; } } return Math . max ( longest , currentCount + prevCount ) ; } let input = [ 5 , 5 , 6 , 7 , 6 ] ; document . write ( longestSubarray ( input ) ) ;

Index/key variables: i
Accumulator variables: currentCount, i, prevCount
Iterator variables: i
Javascript program:
function binarySearch ( searchSpace , s , e , num ) { let ans = 0 ; while ( s <= e ) { let mid = Math . floor ( ( s + e ) / 2 ) ; if ( searchSpace [ mid ] >= num ) { ans = mid ; e = mid - 1 ; } else s = mid + 1 ; } return ans ; } function longestSubArr ( arr , n ) { let searchSpace = new Array ( n ) ; let index = new Array ( n ) ; let j = 0 ; let ans = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( j == 0 searchSpace [ j - 1 ] < arr [ i ] ) { searchSpace [ j ] = arr [ i ] ; index [ j ] = i ; j ++ ; } let idx = binarySearch ( searchSpace , 0 , j - 1 , arr [ i ] ) ; ans = Math . max ( ans , i - index [ idx ] + 1 ) ; } return ans ; } let arr = [ - 5 , - 1 , 7 , 5 , 1 , - 2 ] ; let n = arr . length ; document . write ( longestSubArr ( arr , n ) ) ;

Index/key variables: i, idx, j, mid
Accumulator variables: j
Iterator variables: i
Javascript program:
function pairedElements ( arr , sum , n ) { var low = 0 ; var high = n - 1 ; while ( low < high ) { if ( arr [ low ] + arr [ high ] == sum ) { document . write ( " " + arr [ low ] + " " + arr [ high ] + " " ) ; } if ( arr [ low ] + arr [ high ] > sum ) { high -- ; } else { low ++ ; } } } var arr = [ 2 , 3 , 4 , - 2 , 6 , 8 , 9 , 11 ] var n = arr . length ; arr . sort ( function ( a , b ) { return a - b ; } ) ; pairedElements ( arr , 6 , n ) ;

Index/key variables: high, low
Accumulator variables: high, low
Javascript program:
function isSuffix ( s1 , s2 ) { let n1 = s1 . length , n2 = s2 . length ; if ( n1 > n2 ) return false ; for ( let i = 0 ; i < n1 ; i ++ ) if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) return false ; return true ; } let s1 = " " , s2 = " " ; let result = isSuffix ( s1 , s2 ) ; if ( result ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkIfAllTogether ( s , c ) { function checkIfAllTogether ( s , c ) { let oneSeen = false ; let i = 0 , n = s . length ; while ( i < n ) { if ( s [ i ] == c ) { if ( oneSeen == true ) return false ; while ( i < n && s [ i ] == c ) i ++ ; oneSeen = true ; } else i ++ ; } return true ; } let s = " " ; if ( checkIfAllTogether ( s , ' ' ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Boolean variables: oneSeen
Javascript program:
function search ( arr , n , x ) { let front = 0 , back = n - 1 ; while ( front <= back ) { if ( arr [ front ] == x arr [ back ] == x ) return true ; front ++ ; back -- ; } return false ; } let arr = [ 10 , 20 , 80 , 30 , 60 , 50 , 110 , 100 , 130 , 170 ] ; let x = 130 ; let n = arr . length ; if ( search ( arr , n , x ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: back, front
Accumulator variables: back, front