dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countSequences ( arr , n ) { let count = 1 ; arr . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ; return count ; } let arr = [ 1 , 7 , 3 , 5 , 10 ] ; let n = arr . length ; document . write ( countSequences ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minimumMoves ( a , n ) { let operations = 0 ; a . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) operations += Math . abs ( a [ i ] - ( i + 1 ) ) ; return operations ; } let arr = [ 5 , 3 , 2 ] ; let n = arr . length ; document . write ( minimumMoves ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, operations
Iterator variables: i
Javascript program:
function printCase ( n ) { if ( n <= 2 ) { document . write ( - 1 ) ; return ; } for ( let i = n ; i >= 1 ; i -- ) document . write ( i + " " ) ; } let n = 3 ; printCase ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( n , k , a , b ) { a . sort ( ) ; b . sort ( ) ; let fl = false ; let ind = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { if ( fl == true ) { return false ; } fl = true ; ind = i ; } } if ( ind == - 1 | Math . abs ( a [ ind ] - b [ ind ] ) <= k ) { return true ; } return false ; } let n = 2 , k = 4 ; let a = [ 1 , 5 ] ; let b = [ 1 , 1 ] ; if ( check ( n , k , a , b ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, ind
Accumulator variables: i
Iterator variables: i
Boolean variables: fl
Javascript program:
var MOD = 1000000007 function SubseqWidths ( A , n ) { A . sort ( ( a , b ) => a - b ) var pow2 = Array ( n ) . fill ( 0 ) ; pow2 [ 0 ] = 1 ; for ( var i = 1 ; i < n ; ++ i ) pow2 [ i ] = ( pow2 [ i - 1 ] * 2 ) % MOD ; var ans = 0 ; for ( var i = 0 ; i < n ; ++ i ) ans = ( ans + ( pow2 [ i ] - pow2 [ n - 1 - i ] ) * A [ i ] ) % MOD ; return ans ; } var A = [ 5 , 6 , 4 , 3 , 8 ] ; var n = A . length ; document . write ( SubseqWidths ( A , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function maxArrayCover ( a , n , x ) { a . sort ( ) ; let cc = 0 ; let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { s += a [ i ] ; if ( s > x ) { break ; } cc += 1 ; } var sum = a . reduce ( function ( a , b ) { return a + b ; } , 0 ) ; if ( sum == x ) { return n ; } else { if ( cc == n ) { return n - 1 ; } else { return cc ; } } } let n = 3 ; let x = 70 ; let a = [ 10 , 20 , 30 ] ; document . write ( maxArrayCover ( a , n , x ) ) ;

Index/key variables: i
Accumulator variables: cc, i, s
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } var start = null ; function isPairWiseSorted ( head ) { var flag = true ; var temp = head ; while ( temp != null && temp . next != null ) { if ( temp . data > temp . next . data ) { flag = false ; break ; } temp = temp . next . next ; } return flag ; } 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 ; start = head_ref ; } start = null ; push ( start , 5 ) ; push ( start , 1 ) ; push ( start , 9 ) ; push ( start , 9 ) ; push ( start , 15 ) ; push ( start , 10 ) ; if ( isPairWiseSorted ( start ) ) document . write ( " " ) ; else document . write ( " " ) ;

Boolean variables: flag
Class/struct names: Node
Javascript program:
function maximumSOP ( a , b ) { let sop = 0 ; let n = a . length ; a . sort ( ) ; b . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { sop += ( a [ i ] * b [ i ] ) ; } return sop ; } let A = [ 1 , 2 , 3 ] ; let B = [ 4 , 5 , 1 ] ; document . write ( maximumSOP ( A , B ) ) ;

Index/key variables: i
Accumulator variables: i, sop
Iterator variables: i
Javascript program:
function countTriplets ( arr , n , m ) { let count = 0 ; arr . sort ( function ( a , b ) { return a - b } ) ; let end , start , mid ; for ( end = n - 1 ; end >= 2 ; end -- ) { start = 0 ; mid = end - 1 ; while ( start < mid ) { let prod = arr [ end ] * arr [ start ] * arr [ mid ] ; if ( prod > m ) mid -- ; else if ( prod < m ) start ++ ; else if ( prod == m ) { count ++ ; mid -- ; start ++ ; } } } return count ; } let arr = [ 1 , 1 , 1 , 1 , 1 , 1 ] ; let n = arr . length ; let m = 1 ; document . write ( countTriplets ( arr , n , m ) ) ;

Index/key variables: end, mid, start
Accumulator variables: count, end, mid, start
Iterator variables: end
Javascript program:
function distribution ( arr , n ) { let resources = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) resources . add ( arr [ i ] ) ; return Math . min ( resources . size , parseInt ( n / 2 , 10 ) ) ; } let arr = [ 1 , 1 , 2 , 1 , 3 , 4 ] ; let n = arr . length ; document . write ( distribution ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sort3 ( arr , temp ) { if ( arr [ 1 ] < arr [ 0 ] ) { temp [ 0 ] = arr [ 0 ] ; arr [ 0 ] = arr [ 1 ] ; arr [ 1 ] = temp [ 0 ] ; } if ( arr [ 2 ] < arr [ 1 ] ) { temp [ 0 ] = arr [ 1 ] ; arr [ 1 ] = arr [ 2 ] ; arr [ 2 ] = temp [ 0 ] ; if ( arr [ 1 ] < arr [ 0 ] ) { temp [ 0 ] = arr [ 0 ] ; arr [ 0 ] = arr [ 1 ] ; arr [ 1 ] = temp [ 0 ] ; } } } let a = [ 10 , 12 , 5 ] ; let temp1 = [ 10 ] ; sort3 ( a , temp1 ) ; for ( let i = 0 ; i < 3 ; i ++ ) document . write ( a [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function merge ( arr , beg , mid , end , maxele ) { let i = beg ; let j = mid + 1 ; let k = beg ; while ( i <= mid && j <= end ) { if ( arr [ i ] % maxele <= arr [ j ] % maxele ) { arr [ k ] = arr [ k ] + ( arr [ i ] % maxele ) * maxele ; k ++ ; i ++ ; } else { arr [ k ] = arr [ k ] + ( arr [ j ] % maxele ) * maxele ; k ++ ; j ++ ; } } while ( i <= mid ) { arr [ k ] = arr [ k ] + ( arr [ i ] % maxele ) * maxele ; k ++ ; i ++ ; } while ( j <= end ) { arr [ k ] = arr [ k ] + ( arr [ j ] % maxele ) * maxele ; k ++ ; j ++ ; } for ( i = beg ; i <= end ; i ++ ) { arr [ i ] = Math . floor ( arr [ i ] / maxele ) ; } } function mergeSortRec ( arr , beg , end , maxele ) { if ( beg < end ) { let mid = Math . floor ( ( beg + end ) / 2 ) ; mergeSortRec ( arr , beg , mid , maxele ) ; mergeSortRec ( arr , mid + 1 , end , maxele ) ; merge ( arr , beg , mid , end , maxele ) ; } } function mergeSort ( arr , n ) { let maxele = Math . max ( ... arr ) + 1 ; mergeSortRec ( arr , 0 , n - 1 , maxele ) ; } let arr = [ 999 , 612 , 589 , 856 , 56 , 945 , 243 ] ; let n = arr . length ; mergeSort ( arr , n ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function printTriplets ( arr , n , sum ) { arr . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < n - 2 ; i ++ ) { let j = i + 1 , k = n - 1 ; while ( j < k ) { if ( arr [ i ] + arr [ j ] + arr [ k ] >= sum ) k -- ; else { for ( let x = j + 1 ; x <= k ; x ++ ) document . write ( arr [ i ] + " " + arr [ j ] + " " + arr [ x ] + " " ) ; j ++ ; } } } } let arr = [ 5 , 1 , 3 , 4 , 7 ] ; let n = arr . length ; let sum = 12 ; printTriplets ( arr , n , sum ) ;

Index/key variables: i, j, k, x
Accumulator variables: i, j, k, x
Iterator variables: i, x
Javascript program:
function printSorted ( s , l ) { var Stack = [ ] ; var tempstack = [ ] ; Stack . push ( s [ 0 ] . charCodeAt ( 0 ) ) ; for ( var i = 1 ; i < l ; i ++ ) { var a = s [ i ] . charCodeAt ( 0 ) ; var b = Stack [ Stack . length - 1 ] ; if ( ( a - b ) >= 1 || ( a == b ) ) Stack . push ( s [ i ] . charCodeAt ( 0 ) ) ; else if ( ( b - a ) >= 1 ) { while ( ( b - a ) >= 1 ) { tempstack . push ( Stack [ Stack . length - 1 ] ) ; Stack . pop ( ) ; if ( Stack . length > 0 ) b = Stack [ Stack . length - 1 ] ; else break ; } Stack . push ( s [ i ] . charCodeAt ( 0 ) ) ; while ( tempstack . length > 0 ) { Stack . push ( tempstack [ tempstack . length - 1 ] ) ; tempstack . pop ( ) ; } } } var answer = " " ; while ( Stack . length > 0 ) { answer = String . fromCharCode ( Stack [ Stack . length - 1 ] ) + answer ; Stack . pop ( ) ; } document . write ( answer ) } var s = " " ; var l = s . length ; printSorted ( s , l ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkFittingArrays ( A , B , N ) { A . sort ( function ( a , b ) { return a - b ; } ) ; B . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < N ; i ++ ) if ( A [ i ] > B [ i ] ) return false ; return true ; } let A = [ 7 , 5 , 3 , 2 ] ; let B = [ 5 , 4 , 8 , 7 ] ; let N = A . length ; if ( checkFittingArrays ( A , B , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximum_toys ( cost , N , K ) { let count = 0 , sum = 0 ; cost . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( sum + cost [ i ] <= K ) { sum = sum + cost [ i ] ; count ++ ; } } return count ; } let K = 50 ; let cost = [ 1 , 12 , 5 , 111 , 200 , 1000 , 10 , 9 , 12 , 15 ] ; let N = cost . length ; document . write ( maximum_toys ( cost , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function areBookingsPossible ( A , B , K , N ) { A . sort ( ) ; B . sort ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( i + K < N && A [ i + K ] < B [ i ] ) { return " " ; } } return " " ; } let arrival = [ 1 , 2 , 3 ] ; let departure = [ 2 , 3 , 4 ] ; let N = arrival . length ; let K = 1 ; document . write ( areBookingsPossible ( arrival , departure , K , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printVector ( V ) { for ( let e of V ) { document . write ( e + " " ) ; } document . write ( " " ) ; } function insertionSortRecursive ( V , N ) { if ( N <= 1 ) return ; insertionSortRecursive ( V , N - 1 ) ; let j = N - 1 ; while ( j > 0 && V [ j ] < V [ j - 1 ] ) { let temp = V [ j ] ; V [ j ] = V [ j - 1 ] ; V [ j - 1 ] = temp ; j -= 1 ; } } let A = [ 9 , 8 , 7 , 5 , 2 , 1 , 2 , 3 ] ; document . write ( " " ) ; printVector ( A ) ; document . write ( " " ) ; insertionSortRecursive ( A , A . length ) ; printVector ( A ) ;

Index/key variables: j
Accumulator variables: j
Iterator variables: e
Javascript program:
function findWord ( arr ) { var hs = { } ; for ( var i = 0 ; i < arr . length ; i ++ ) { if ( hs . hasOwnProperty ( arr [ i ] ) ) { hs [ arr [ i ] ] = hs [ arr [ i ] ] + 1 ; } else { hs [ arr [ i ] ] = 1 ; } } var Key = " " ; var Value = 0 ; for ( const [ key , value ] of Object . entries ( hs ) ) { if ( value > Value ) { Value = value ; Key = key ; } } return Key ; } var arr = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var sol = findWord ( arr ) ; document . write ( sol ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function almostSort ( A , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { let temp = A [ i ] ; A [ i ] = A [ i + 1 ] ; A [ i + 1 ] = temp ; i ++ ; } } for ( let i = 0 ; i < n - 1 ; i ++ ) if ( A [ i ] > A [ i + 1 ] ) return false ; return true ; } let A = [ 1 , 3 , 2 , 4 , 6 , 5 ] ; let n = A . length ; if ( almostSort ( A , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nextGap ( gap ) { if ( gap <= 1 ) return 0 ; return parseInt ( gap / 2 , 10 ) + ( gap % 2 ) ; } function merge ( arr1 , arr2 , n , m ) { let i , j , gap = n + m ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) { for ( i = 0 ; i + gap < n ; i ++ ) if ( arr1 [ i ] > arr1 [ i + gap ] ) { let temp = arr1 [ i ] ; arr1 [ i ] = arr1 [ i + gap ] ; arr1 [ i + gap ] = temp ; } for ( j = gap > n ? gap - n : 0 ; i < n && j < m ; i ++ , j ++ ) if ( arr1 [ i ] > arr2 [ j ] ) { let temp = arr1 [ i ] ; arr1 [ i ] = arr2 [ j ] ; arr2 [ j ] = temp ; } if ( j < m ) { for ( j = 0 ; j + gap < m ; j ++ ) if ( arr2 [ j ] > arr2 [ j + gap ] ) { let temp = arr2 [ j ] ; arr2 [ j ] = arr2 [ j + gap ] ; arr2 [ j + gap ] = temp ; } } } } let a1 = [ 10 , 27 , 38 , 43 , 82 ] ; let a2 = [ 3 , 9 ] ; merge ( a1 , a2 , a1 . length , a2 . length ) ; document . write ( " " ) ; for ( let i = 0 ; i < a1 . length ; i ++ ) { document . write ( a1 [ i ] + " " ) ; } document . write ( " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < a2 . length ; i ++ ) { document . write ( a2 [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: gap, i, j
Javascript program:
function sortSquares ( arr ) { let n = arr . length ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = arr [ i ] * arr [ i ] ; arr . sort ( ) ; } let arr = [ - 6 , - 3 , - 1 , 2 , 4 , 5 ] ; let n = arr . length ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; sortSquares ( arr ) ; document . write ( " " + " " ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mergeTwoHalf ( A , n ) { let temp = new Array ( n ) ; temp . fill ( 0 ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { half_i = i + 1 ; break ; } } if ( half_i == 0 ) return ; let i = 0 , j = half_i , k = 0 ; while ( i < half_i && j < n ) { if ( A [ i ] < A [ j ] ) temp [ k ++ ] = A [ i ++ ] ; else temp [ k ++ ] = A [ j ++ ] ; } while ( i < half_i ) temp [ k ++ ] = A [ i ++ ] ; while ( j < n ) temp [ k ++ ] = A [ j ++ ] ; for ( let i = 0 ; i < n ; i ++ ) A [ i ] = temp [ i ] ; } let A = [ 2 , 3 , 8 , - 1 , 7 , 10 ] ; let n = A . length ; mergeTwoHalf ( A , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( A [ i ] + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function findMinDiff ( arr , n , m ) { if ( m == 0 n == 0 ) return 0 ; arr . sort ( function ( a , b ) { return a - b } ) ; if ( n < m ) return - 1 ; let min_diff = Number . MAX_VALUE ; for ( let i = 0 ; i + m - 1 < n ; i ++ ) { let diff = arr [ i + m - 1 ] - arr [ i ] ; if ( diff < min_diff ) min_diff = diff ; } return min_diff ; } let arr = [ 12 , 4 , 7 , 9 , 2 , 23 , 25 , 41 , 30 , 40 , 28 , 42 , 30 , 44 , 48 , 43 , 50 ] ; let m = 7 ; let n = arr . length ; document . write ( " " + findMinDiff ( arr , n , m ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function distinctCount ( arr , n ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) s . add ( Math . abs ( arr [ i ] ) ) ; return s . size ; } let arr = [ - 2 , - 1 , 0 , 1 , 1 ] ; let n = arr . length ; document . write ( " " + distinctCount ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function distinctCount ( arr , n ) { let count = n ; let i = 0 , j = n - 1 , sum = 0 ; while ( i < j ) { while ( i != j && arr [ i ] == arr [ i + 1 ] ) count -- , i ++ ; while ( i != j && arr [ j ] == arr [ j - 1 ] ) count -- , j -- ; if ( i == j ) break ; sum = arr [ i ] + arr [ j ] ; if ( sum == 0 ) { count -- ; i ++ , j -- ; } else if ( sum < 0 ) i ++ ; else j -- ; } return count ; } let arr = [ - 2 , - 1 , 0 , 1 , 1 ] ; let n = arr . length ; document . write ( " " + distinctCount ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Javascript program:
function sortByOneSwap ( arr , n ) { for ( let i = n - 1 ; i > 0 ; i -- ) { if ( arr [ i ] < arr [ i - 1 ] ) { let j = i - 1 ; while ( j >= 0 && arr [ i ] < arr [ j ] ) j -- ; let temp = arr [ i ] ; arr [ i ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; break ; } } } function printArray ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 10 , 30 , 20 , 40 , 50 , 60 , 70 ] ; let n = arr . length ; document . write ( " " + " " ) ; printArray ( arr , n ) ; sortByOneSwap ( arr , n ) ; document . write ( " " + " " ) ; printArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function flip ( arr , i ) { let temp , start = 0 ; while ( start < i ) { temp = arr [ start ] ; arr [ start ] = arr [ i ] ; arr [ i ] = temp ; start ++ ; i -- ; } } function findMax ( arr , n ) { let mi , i ; for ( mi = 0 , i = 0 ; i < n ; ++ i ) if ( arr [ i ] > arr [ mi ] ) mi = i ; return mi ; } function pancakeSort ( arr , n ) { for ( let curr_size = n ; curr_size > 1 ; -- curr_size ) { let mi = findMax ( arr , curr_size ) ; if ( mi != curr_size - 1 ) { flip ( arr , mi ) ; flip ( arr , curr_size - 1 ) ; } } return 0 ; } function printArray ( arr , arr_size ) { for ( let i = 0 ; i < arr_size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 23 , 10 , 20 , 11 , 12 , 6 , 7 ] ; let n = arr . length ; pancakeSort ( arr , n ) ; document . write ( " " + " " ) ; printArray ( arr , n ) ;

Index/key variables: i, mi, start
Accumulator variables: i, start
Iterator variables: curr_size, i, mi
Javascript program:
function performOperation ( S , N ) { for ( var i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( S . charAt ( i ) == ' ' ) { S [ i ] = ' ' ; } else { S [ i ] = ' ' ; } } else { if ( S . charAt ( i ) == ' ' ) { S . charAt ( i ) = ' ' ; } else { S [ i ] = ' ' ; } } } return S ; } var S = " " ; var N = S . length ; document . write ( performOperation ( S , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( x , N ) { while ( true ) { N -= x ; if ( x < 10 ) break ; let temp2 = 0 ; while ( x > 0 ) { temp2 += ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } x = temp2 ; } if ( ( x < 10 ) && ( N == 0 ) ) { return true ; } return false ; } function countNoOfsuchX ( N ) { let k = Math . floor ( Math . log10 ( N ) ) + 1 ; let count = 1 ; for ( let x = ( N - ( k * ( k + 1 ) * 5 ) ) ; x <= N ; x ++ ) { if ( check ( x , N ) ) { count += 1 ; } } return count ; } let N = 9399 ; document . write ( countNoOfsuchX ( N ) ) ;

Accumulator variables: N, count, temp2, x
Iterator variables: x
Javascript program:
function proc ( v ) { let n = v . length ; let low = v [ n - 1 ] , high = v [ n - 1 ] ; let p1 = n , p2 = n ; let ans = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let x = v [ i ] ; if ( x < low ) { low = x ; ans = 0 ; } else if ( x > high ) { high = x ; ans = 0 ; } if ( x == low ) p1 = i ; if ( x == high ) p2 = i ; ans += n - Math . max ( p1 , p2 ) ; } return ans ; } function subarray ( v ) { let n = v . length ; if ( n <= 1 ) { return n ; } let ans = proc ( v ) ; let low = v [ 0 ] , pos_low = 0 , high = v [ 0 ] , pos_high = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let x = v [ i ] ; if ( x < low ) { low = x ; pos_low = i ; } else if ( x > high ) { high = x ; pos_high = i ; } } let u = [ ... v ] ; u . splice ( pos_low , 1 ) ; ans = Math . max ( ans , proc ( u ) ) ; let w = [ ... v ] ; w . splice ( pos_high , 1 ) ; return Math . max ( ans , proc ( w ) ) ; } let v = [ ] ; v . push ( 7 ) ; v . push ( 2 ) ; v . push ( 5 ) ; v . push ( 4 ) ; v . push ( 3 ) ; v . push ( 1 ) ; document . write ( subarray ( v ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function find ( arr , N ) { let Sum = 0 ; let i = 0 ; let ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { Sum += arr [ i ] ; } if ( Sum % N ) { return - 1 ; } else { k = Math . floor ( Sum / N ) ; ans = 0 ; i = 0 ; while ( i < N ) { ans = ans + Math . abs ( k - arr [ i ] ) ; i += 1 ; } } return Math . floor ( ans / 2 ) ; } let arr = [ 5 , 4 , 1 , 10 ] let N = arr . length ; document . write ( find ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: Sum, i
Iterator variables: i
Javascript program:
function shortestDistance ( s , n ) { var visited = Array ( 128 ) . fill ( - 1 ) ; var ans = Number . MAX_VALUE ; for ( var right = 0 ; right < n ; right ++ ) { var left = visited [ s . charCodeAt ( right ) ] ; if ( left != - 1 ) ans = Math . min ( ans , right - left - 1 ) ; visited [ s . charCodeAt ( right ) ] = right ; } return ans == Number . MAX_VALUE ? - 1 : ans ; } var s = " " ; var n = 13 ; document . write ( shortestDistance ( s , n ) ) ;

Accumulator variables: right
Iterator variables: right
Javascript program:
function possibleNumbers ( N , M , A , B ) { var i ; if ( A > B ) { var temp = A ; A = B ; B = temp ; } var number = N + M * A ; document . write ( number + " " ) ; if ( A != B ) { for ( i = 0 ; i < M ; i ++ ) { number = number - A + B ; document . write ( number + " " ) ; } } } var N = 5 , M = 3 , A = 4 , B = 6 ; possibleNumbers ( N , M , A , B ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var Pi = 3.141592 ; function MaxBuildingsCovered ( arr , N , L ) { var curr_sum = 0 ; var start = 0 , curr_count = 0 , max_count = 0 ; for ( var i = 0 ; i < N ; i ++ ) { curr_sum = curr_sum + parseFloat ( arr [ i ] ) * Pi ; if ( i != 0 ) curr_sum += 1 ; if ( curr_sum <= L ) { curr_count ++ ; } else if ( curr_sum > L ) { curr_sum = curr_sum - parseFloat ( arr [ start ] ) * Pi ; curr_sum -= 1 ; start ++ ; curr_count -- ; } max_count = Math . max ( curr_count , max_count ) ; } return max_count ; } var arr = [ 4 , 1 , 6 , 2 ] ; var L = 24 ; var N = arr . length ; document . write ( MaxBuildingsCovered ( arr , N , L ) ) ;

Index/key variables: i, start
Accumulator variables: curr_count, curr_sum, i, start
Iterator variables: i
Javascript program:
function countUnsetBits ( N ) { let c = 0 ; while ( N != 0 ) { if ( N % 2 == 0 ) { c += 1 ; } N = N >> 1 ; } return c ; } function countBitwiseZero ( N ) { let unsetBits = countUnsetBits ( N ) ; document . write ( 1 << unsetBits ) ; } let N = 9 ; countBitwiseZero ( N ) ;

Accumulator variables: c
Javascript program:
function isPossible ( s ) { let n = s . length ; let count_0 = 0 , count_1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) ++ count_0 ; else ++ count_1 ; if ( count_1 > count_0 ) return false ; } if ( count_0 != ( 2 * count_1 ) ) return false ; count_0 = 0 ; count_1 = 0 ; for ( let i = n - 1 ; i >= 0 ; -- i ) { if ( s [ i ] == ' ' ) ++ count_0 ; else ++ count_1 ; if ( count_1 > count_0 ) return false ; } return true ; } let s = " " ; if ( isPossible ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function leastBricks ( wall ) { let map = new Map ( ) ; let res = 0 ; for ( let list of wall ) { let width = 0 ; for ( let i = 0 ; i < list . length - 1 ; i ++ ) { width += list [ i ] ; if ( map . has ( width ) ) { map . set ( width , map . get ( width ) + 1 ) ; } else { map . set ( width , 1 ) } res = Math . max ( res , map . get ( width ) ) ; } } document . write ( wall . length - res ) ; } let arr = [ [ 1 , 2 , 2 , 1 ] , [ 3 , 1 , 2 ] , [ 1 , 3 , 2 ] , [ 2 , 4 ] , [ 3 , 1 , 2 ] , [ 1 , 3 , 1 , 1 ] ] ; leastBricks ( arr ) ;

Index/key variables: i
Accumulator variables: i, width
Iterator variables: i, list
Javascript program:
function findPermutation ( N ) { for ( var i = 1 ; i <= N ; i ++ ) document . write ( i + " " ) ; document . write ( " " ) ; } var N = 5 ; findPermutation ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function MinimumOperations ( A , N , K ) { let Count = 0 ; let i = 0 ; while ( i < N - 1 ) { i = i + K - 1 ; Count ++ ; } return Count ; } let A = [ 5 , 4 , 3 , 1 , 2 ] ; let K = 3 ; let N = A . length ; document . write ( MinimumOperations ( A , N , K ) ) ;

Accumulator variables: Count