dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function search ( mat , m , n , x ) { var i = m - 1 , j = 0 ; while ( i >= 0 && j < n ) { if ( mat [ i ] [ j ] == x ) return true ; if ( mat [ i ] [ j ] > x ) i -- ; else j ++ ; } return false ; } var mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] , [ 50 , 60 , 70 , 80 ] ] ; if ( search ( mat , 5 , 4 , 29 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function printGreaterCount ( str ) { let len = str . length ; let right = new Array ( len ) ; right . fill ( 0 ) ; for ( let i = 0 ; i < len ; i ++ ) { for ( let j = i + 1 ; j < len ; j ++ ) { if ( str [ i ] . charCodeAt ( ) < str [ j ] . charCodeAt ( ) ) { right [ i ] ++ ; } } } for ( let i = 0 ; i < len ; i ++ ) { document . write ( right [ i ] + " " ) ; } } let str = " " ; printGreaterCount ( str ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function appearsNBy3 ( arr , n ) { let count1 = 0 , count2 = 0 ; let first = Number . MAX_VALUE ; let second = Number . MAX_VALUE ; for ( let i = 1 ; i < n ; i ++ ) { if ( first == arr [ i ] ) count1 ++ ; else if ( second == arr [ i ] ) count2 ++ ; else if ( count1 == 0 ) { count1 ++ ; first = arr [ i ] ; } else if ( count2 == 0 ) { count2 ++ ; second = arr [ i ] ; } else { count1 -- ; count2 -- ; } } count1 = 0 ; count2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == first ) count1 ++ ; else if ( arr [ i ] == second ) count2 ++ ; } if ( count1 > parseInt ( n / 3 , 10 ) ) return first ; if ( count2 > parseInt ( n / 3 , 10 ) ) return second ; return - 1 ; } let arr = [ 1 , 2 , 3 , 1 , 1 ] ; let n = arr . length ; document . write ( appearsNBy3 ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count1, count2, i
Iterator variables: i
Javascript program:
function countMaxSetBits ( left , right ) { let max_count = - 1 , num = 0 ; for ( let i = left ; i <= right ; ++ i ) { let temp = i , cnt = 0 ; while ( temp > 0 ) { if ( temp % 2 == 1 ) ++ cnt ; temp >>= 1 ; } if ( cnt > max_count ) { max_count = cnt ; num = i ; } } return num ; } let l = 1 , r = 5 ; document . write ( countMaxSetBits ( l , r ) + " " ) ; l = 1 ; r = 10 ; document . write ( countMaxSetBits ( l , r ) ) ;

Iterator variables: i
Javascript program:
function _partition ( arr , low , high ) { let pivot = arr [ high ] , pivotloc = low ; for ( let i = low ; i <= high ; i ++ ) { if ( arr [ i ] < pivot ) { let temp = arr [ i ] ; arr [ i ] = arr [ pivotloc ] ; arr [ pivotloc ] = temp ; pivotloc ++ ; } } let temp = arr [ high ] ; arr [ high ] = arr [ pivotloc ] ; arr [ pivotloc ] = temp ; return pivotloc ; } function kthSmallest ( arr , low , high , k ) { let partition = _partition ( arr , low , high ) ; if ( partition == k - 1 ) return arr [ partition ] ; else if ( partition < k - 1 ) return kthSmallest ( arr , partition + 1 , high , k ) ; else return kthSmallest ( arr , low , partition - 1 , k ) ; } let array = [ 10 , 4 , 5 , 8 , 6 , 11 , 26 ] ; let arraycopy = [ 10 , 4 , 5 , 8 , 6 , 11 , 26 ] ; let kPosition = 3 ; let length = array . length ; if ( kPosition > length ) { document . write ( " " ) ; } else { document . write ( " " + kthSmallest ( arraycopy , 0 , length - 1 , kPosition ) + " " ) ; }

Index/key variables: high, i, partition, pivotloc
Accumulator variables: i, pivotloc
Iterator variables: i
Javascript program:
function recaman ( n ) { let arr = new Array ( n ) ; arr [ 0 ] = 0 ; document . write ( arr [ 0 ] + " " ) ; for ( let i = 1 ; i < n ; i ++ ) { let curr = arr [ i - 1 ] - i ; let j ; for ( j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] == curr ) curr < 0 ) { curr = arr [ i - 1 ] + i ; break ; } } arr [ i ] = curr ; document . write ( arr [ i ] + " " ) ; } } let n = 17 ; recaman ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . left = this . right = null ; } } let ans , lh , rh , f ; let k ; let Root ; function height ( root ) { if ( root == null ) return 0 ; let left_height = height ( root . left ) ; let right_height = height ( root . right ) ; if ( ans < 1 + left_height + right_height ) { ans = 1 + left_height + right_height ; k = root ; lh = left_height ; rh = right_height ; } return 1 + Math . max ( left_height , right_height ) ; } function printArray ( ints , len ) { let i ; if ( f == 0 ) { for ( i = len - 1 ; i >= 0 ; i -- ) { document . write ( ints [ i ] + " " ) ; } } else if ( f == 1 ) { for ( i = 0 ; i < len ; i ++ ) { document . write ( ints [ i ] + " " ) ; } } } function printPathsRecur ( node , path , pathLen , max ) { if ( node == null ) return ; path [ pathLen ] = node . data ; pathLen ++ ; if ( node . left == null && node . right == null ) { if ( pathLen == max && ( f == 0 f == 1 ) ) { printArray ( path , pathLen ) ; f = 2 ; } } else { printPathsRecur ( node . left , path , pathLen , max ) ; printPathsRecur ( node . right , path , pathLen , max ) ; } } function diameter ( root ) { if ( root == null ) return ; ans = Number . MIN_VALUE ; lh = 0 ; rh = 0 ; f = 0 ; let height_of_tree = height ( root ) ; let lPath = new Array ( 100 ) ; let pathlen = 0 ; printPathsRecur ( k . left , lPath , pathlen , lh ) ; document . write ( k . data + " " ) ; let rPath = new Array ( 100 ) ; f = 1 ; printPathsRecur ( k . right , rPath , pathlen , rh ) ; } Root = new Node ( 1 ) ; Root . left = new Node ( 2 ) ; Root . right = new Node ( 3 ) ; Root . left . left = new Node ( 4 ) ; Root . left . right = new Node ( 5 ) ; Root . left . right . left = new Node ( 6 ) ; Root . left . right . right = new Node ( 7 ) ; Root . left . left . right = new Node ( 8 ) ; Root . left . left . right . left = new Node ( 9 ) ; diameter ( Root ) ;

Index/key variables: i, pathLen
Accumulator variables: i, pathLen
Iterator variables: i
Class/struct names: Node
Javascript program:
function recaman ( n ) { if ( n <= 0 ) return ; document . write ( 0 + " " ) ; let s = new Set ( ) ; s . add ( 0 ) ; let prev = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let curr = prev - i ; if ( curr < 0 || s . has ( curr ) ) curr = prev + i ; s . add ( curr ) ; document . write ( curr + " " ) ; prev = curr ; } } let n = 17 ; recaman ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function find_extra_element_index ( arrA , arrB ) { let extra_element = sum ( arrA ) - sum ( arrB ) ; return indexOf ( arrA , extra_element ) ; } function sum ( arr ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; } return sum ; } function indexOf ( arr , element ) { for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == element ) { return i ; } } return - 1 ; } let arrA = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ] ; let arrB = [ 2 , 4 , 6 , 8 , 10 , 12 ] ; document . write ( find_extra_element_index ( arrA , arrB ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function sumOfDiv ( x ) { let sum = 1 ; for ( let i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { sum += i ; if ( x / i != i ) sum += x / i ; } } return sum ; } function isAmicable ( a , b ) { return ( sumOfDiv ( a ) == b && sumOfDiv ( b ) == a ) ; } function countPairs ( arr , n ) { let s = new Set ( ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( s . has ( sumOfDiv ( arr [ i ] ) ) ) { let sum = sumOfDiv ( arr [ i ] ) ; if ( isAmicable ( arr [ i ] , sum ) ) count ++ ; } } return Math . floor ( count / 2 ) ; } let arr1 = [ 220 , 284 , 1184 , 1210 , 2 , 5 ] ; let n1 = arr1 . length ; document . write ( countPairs ( arr1 , n1 ) + " " ) ; let arr2 = [ 2620 , 2924 , 5020 , 5564 , 6232 , 6368 ] ; let n2 = arr2 . length ; document . write ( countPairs ( arr2 , n2 ) + " " ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function minimumDeletion ( s , n ) { var countMap = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( countMap . has ( s [ i ] ) ) { countMap . set ( s [ i ] , countMap . get ( s [ i ] ) + 1 ) ; } else { countMap . set ( s [ i ] , 1 ) ; } } var countMultiset = [ ] ; countMap . forEach ( ( value , key ) => { countMultiset . push ( value ) ; } ) ; countMultiset . sort ( ) ; var ans = 1000000000 ; var i = 0 ; var m = countMultiset . length ; countMultiset . forEach ( j => { ans = Math . min ( ans , n - ( m - i ) * j ) ; i ++ ; } ) ; return ans ; } var S = " " ; var N = S . length ; document . write ( minimumDeletion ( S , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateDistance ( arr , N ) { var v = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { v . push ( [ arr [ i ] , i ] ) ; } v = v . sort ( ) ; var ans = 0 ; var last = 0 ; for ( var i = 0 ; i < N ; i ++ ) { ans += Math . abs ( v [ i ] [ 1 ] - last ) ; last = v [ i ] [ 1 ] ; } return ans ; } var arr = [ 4 , 3 , 2 , 5 , 1 ] ; var N = arr . length ; document . write ( calculateDistance ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function sortArr ( arr , N ) { for ( var i = 0 ; i < N ; i ++ ) { var num = arr [ i ] ; var s = num . toString ( ) ; var temp = s . split ( " " ) ; temp . sort ( ( a , b ) => b - a ) ; s = temp . join ( " " ) ; arr [ i ] = parseInt ( s ) ; var sr = parseInt ( Math . sqrt ( arr [ i ] ) ) ; var a = sr * sr ; var b = ( sr + 1 ) * ( sr + 1 ) ; if ( arr [ i ] - a < b - arr [ i ] ) arr [ i ] = a ; else arr [ i ] = b ; } arr . sort ( ( a , b ) => a - b ) ; for ( var i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } var arr = [ 29 , 43 , 28 , 12 ] ; var N = arr . length ; sortArr ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( arr , N , X ) { arr . sort ( ) ; var sum = 0 ; var cost = 0 ; var INT_MAX = Number . MAX_VALUE ; var min_cost = INT_MAX ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { cost = Math . abs ( arr [ i ] ) * X + ( sum - Math . abs ( arr [ i ] ) * i ) ; sum += Math . abs ( arr [ i ] ) ; min_cost = Math . min ( min_cost , cost ) ; } } document . write ( min_cost ) ; } var arr = [ - 1 , - 3 , - 2 , 4 , - 1 ] ; var N = arr . length ; var X = 2 ; minCost ( arr , N , X ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let ans = 0 ; function countArraysUtil ( arr , X , K , xorVal ) { if ( X == 0 ) { let cnt = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] > xorVal ) cnt ++ ; } if ( cnt >= K ) ans ++ ; return ; } let temp = arr [ 0 ] ; arr . shift ( ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . unshift ( temp ) ; temp = arr [ arr . length - 1 ] ; arr . pop ( ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . push ( temp ) ; arr [ 0 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ 0 ] -- ; arr [ arr . length - 1 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ arr . length - 1 ] -- ; } function countArrays ( arr , X , K ) { let xorVal = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) xorVal = xorVal ^ arr [ i ] ; countArraysUtil ( arr , X , K , xorVal ) ; document . write ( ans ) ; } let arr = [ 10 , 2 , 10 , 5 ] ; let X = 3 , K = 3 ; countArrays ( arr , X , K ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function hashFunction ( N ) { let prime = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 ] ; let value = 1 , r ; while ( N != 0 ) { r = N % 10 ; value = value * prime [ r ] ; N = parseInt ( N / 10 , 10 ) ; } return value ; } function findDiff ( arr , n ) { let m = new Map ( ) ; let h , min , max ; for ( let i = 0 ; i < n ; i ++ ) { h = hashFunction ( arr [ i ] ) ; if ( ! m . has ( h ) ) { m . set ( h , [ ] ) ; } ( m . get ( h ) ) . push ( arr [ i ] ) ; } m . forEach ( ( values , keys ) => { if ( values . length > 1 ) { min = Number . MAX_VALUE ; max = Number . MIN_VALUE ; for ( let j = 0 ; j < values . length ; j ++ ) { if ( ( m . get ( keys ) ) [ j ] < min ) { min = m . get ( keys ) [ j ] ; } if ( m . get ( keys ) [ j ] > max ) { max = m . get ( keys ) [ j ] ; } } document . write ( max - min ) ; } } ) } let arr = [ 121 , 312 , 234 , 211 , 112 , 102 ] ; let N = arr . length ; findDiff ( arr , N ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findArea ( arr , n ) { arr . sort ( ( a , b ) => { return b - a ; } ) var dimension = [ 0 , 0 ] ; for ( var i = 0 , j = 0 ; i < n - 1 && j < 2 ; i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ; return ( dimension [ 0 ] * dimension [ 1 ] ) ; } var arr = [ 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 ] ; var n = arr . length ; document . write ( findArea ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function findSumLength ( arr , n ) { let freq = new Map ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( freq . has ( arr [ i ] ) ) freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; else freq . set ( arr [ i ] , 1 ) ; } let freq_2 = new Map ( ) ; for ( let [ key , value ] of freq . entries ( ) ) { if ( freq . get ( key ) >= 2 ) freq_2 . set ( key , freq . get ( key ) ) ; } let arr1 = [ ] ; for ( let [ key , value ] of freq_2 . entries ( ) ) arr1 . push ( key * Math . floor ( freq_2 . get ( key ) / 2 ) * 2 ) ; arr1 . sort ( function ( a , b ) { return a - b ; } ) ; let summ = 0 ; for ( let i = 0 ; i < arr1 . length ; i ++ ) { summ += arr1 [ i ] ; } document . write ( summ ) ; } let arr = [ 5 , 3 , 2 , 3 , 6 , 4 , 4 , 4 , 5 , 5 , 5 ] ; let n = arr . Count ; findSumLength ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, summ
Iterator variables: i
Javascript program:
function findArea ( arr , n ) { let s = new Set ( ) ; let first = 0 , second = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! s . has ( arr [ i ] ) ) { s . add ( arr [ i ] ) ; continue ; } if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) second = arr [ i ] ; } return ( first * second ) ; } let arr = [ 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 ] ; let n = arr . length ; document . write ( findArea ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function longLenStrictBitonicSub ( arr , n ) { var inc = new Map ( ) , dcr = new Map ( ) ; var len_inc = Array ( n ) , len_dcr = Array ( n ) ; var longLen = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var len = 0 ; if ( inc . has ( arr [ i ] - 1 ) ) len = inc . get ( arr [ i ] - 1 ) ; len_inc [ i ] = len + 1 ; inc . set ( arr [ i ] , len_inc [ i ] ) ; } for ( var i = n - 1 ; i >= 0 ; i -- ) { var len = 0 ; if ( dcr . has ( arr [ i ] - 1 ) ) len = dcr . get ( arr [ i ] - 1 ) ; len_dcr [ i ] = len + 1 ; dcr . set ( arr [ i ] , len_dcr [ i ] ) ; } for ( var i = 0 ; i < n ; i ++ ) if ( longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) ) longLen = len_inc [ i ] + len_dcr [ i ] - 1 ; return longLen ; } var arr = [ 1 , 5 , 2 , 3 , 4 , 5 , 3 , 2 ] ; var n = arr . length ; document . write ( " " + longLenStrictBitonicSub ( arr , n ) ) ;

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

Index/key variables: i, j, min_index
Iterator variables: i, j
Javascript program:
function Bubble_Sort ( arr , n ) { for ( var i = 1 ; i < n ; ++ i ) { for ( var j = 0 ; j <= ( n - i - 1 ) ; ++ j ) { if ( arr [ j ] > arr [ j + 1 ] ) { var temm = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temm ; } } } } var n = 5 ; var arr = [ 2 , 0 , 1 , 4 , 3 ] ; Bubble_Sort ( arr , n ) ; document . write ( " " ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i, j
Javascript program:
function minimum_possible_sum ( arr , n , k ) { if ( n == 0 ) { return 0 ; } if ( n == 1 ) { return arr [ 0 ] ; } var ms = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { ms . push ( arr [ i ] ) ; } ms . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < k ; i ++ ) { var smallest_element = ms [ 0 ] ; var largest_element = ms [ ms . length - 1 ] ; var a = smallest_element * 2 ; var b = largest_element / 2 ; if ( a + b < smallest_element + largest_element ) { ms . shift ( ) ; ms . pop ( ) ; ms . push ( a ) ; ms . push ( b ) ; ms . sort ( ( a , b ) => a - b ) } } var ans = 0 ; ms . forEach ( x => { ans += x ; } ) ; return ans ; } var arr = [ 50 , 1 , 100 , 100 , 1 ] ; var K = 2 ; var n = arr . length ; document . write ( minimum_possible_sum ( arr , n , K ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function firstSubsequence ( s ) { let isMax = - 1 ; for ( let i = 0 ; i < s . length - 1 ; i ++ ) { if ( s [ i ] > s [ i + 1 ] ) { isMax = i ; break ; } } if ( isMax >= 0 ) { s = s . substring ( 0 , isMax ) + s . substring ( isMax + 1 ) ; s . rerase ( isMax , 1 ) ; } else { s . erase ( s . length ( ) - 1 , 1 ) ; s = s . substring ( 0 , s . length - 1 ) ; } document . write ( s ) ; } let S = " " ; firstSubsequence ( S ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX_PATH_SIZE = 1000 ; class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } class PATH { constructor ( Hd , key ) { this . Hd = Hd ; this . key = key ; } } function printPath ( path , size ) { let minimum_Hd = Number . MAX_VALUE ; let p ; for ( let it = 0 ; it < size ; it ++ ) { p = path [ it ] ; minimum_Hd = Math . min ( minimum_Hd , p . Hd ) ; } for ( let it = 0 ; it < size ; it ++ ) { p = path [ it ] ; let noOfUnderScores = Math . abs ( p . Hd - minimum_Hd ) ; for ( let i = 0 ; i < noOfUnderScores ; i ++ ) document . write ( " " ) ; document . write ( p . key + " " ) ; } document . write ( " " ) ; } function printAllPathsUtil ( root , AllPath , HD , order ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { AllPath [ order ] = new PATH ( HD , root . data ) ; printPath ( AllPath , order + 1 ) ; return ; } AllPath [ order ] = new PATH ( HD , root . data ) ; printAllPathsUtil ( root . left , AllPath , HD - 1 , order + 1 ) ; printAllPathsUtil ( root . right , AllPath , HD + 1 , order + 1 ) ; } function printAllPaths ( root ) { if ( root == null ) return ; let Allpaths = [ ] ; for ( let i = 0 ; i < MAX_PATH_SIZE ; i ++ ) { Allpaths . push ( new PATH ( ) ) ; } printAllPathsUtil ( root , Allpaths , 0 , 0 ) ; } let root = new Node ( ' ' ) ; root . left = new Node ( ' ' ) ; root . right = new Node ( ' ' ) ; root . left . left = new Node ( ' ' ) ; root . left . right = new Node ( ' ' ) ; root . right . left = new Node ( ' ' ) ; root . right . right = new Node ( ' ' ) ; printAllPaths ( root ) ;

Index/key variables: it, order
Accumulator variables: i, it
Iterator variables: i, it
Class/struct names: Node, PATH
Javascript program:
function minsteps ( arr , n ) { arr . sort ( ( a , b ) => a - b ) var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { ans += Math . abs ( arr [ i ] - Math . pow ( 2 , i ) ) ; } return ans ; } var arr = [ 1 , 8 , 2 , 10 , 6 ] ; var n = arr . length ; document . write ( minsteps ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let leftRotate = ( arr , d , n ) => { if ( d == 0 d == n ) return ; if ( n - d == d ) { arr = swap ( arr , 0 , n - d , d ) ; return ; } if ( d < n - d ) { arr = swap ( arr , 0 , n - d , d ) ; leftRotate ( arr , d , n - d ) ; } else { arr = swap ( arr , 0 , d , n - d ) ; leftRotate ( arr + n - d , 2 * d - n , d ) ; } } let printArray = ( arr , size ) => { ans = ' ' for ( let i = 0 ; i < size ; i ++ ) ans += arr [ i ] + " " ; document . write ( ans ) } let swap = ( arr , fi , si , d ) => { for ( let i = 0 ; i < d ; i ++ ) { let temp = arr [ fi + i ] ; arr [ fi + i ] = arr [ si + i ] ; arr [ si + i ] = temp ; } return arr } arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; leftRotate ( arr , 2 , 7 ) ; printArray ( arr , 7 ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findCost ( a , n ) { a . sort ( ( x , y ) => y - x ) ; var count = 0 ; for ( var j = 0 ; j < n ; j ++ ) { var p = a [ j ] - j ; a [ j ] = 0 ; if ( p < 0 ) { p = 0 ; continue ; } count += p ; } return count ; } var arr = [ 1 , 6 , 7 , 4 , 2 , 5 , 3 ] ; var N = arr . length ; document . write ( findCost ( arr , N ) ) ;

Index/key variables: j
Accumulator variables: count, j
Iterator variables: j
Javascript program:
function leftRotate ( arr , d , n ) { if ( d == 0 d == n ) return ; let i = d ; let j = n - d ; while ( i != j ) { if ( i < j ) { arr = swap ( arr , d - i , d + j - i , i ) ; j -= i ; } else { arr = swap ( arr , d - i , d , j ) ; i -= j ; } } arr = swap ( arr , d - i , d , i ) ; }

Accumulator variables: i, j
Javascript program:
function countPairs ( arr , n ) { let ans = 0 ; let count = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( count . has ( arr [ i ] ) ) { ans += count . get ( arr [ i ] ) ; count . set ( arr [ i ] , count . get ( arr [ i ] ) + 1 ) ; } else { count . set ( arr [ i ] , 1 ) ; } } return ans ; } let arr = [ 1 , 2 , 1 , 1 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let INF = 1e9 + 7 ; let N , M ; let edges = [ ] ; let dist = new Array ( 2 ) ; for ( let i = 0 ; i < 2 ; i ++ ) { dist [ i ] = new Array ( 200000 ) ; for ( let j = 0 ; j < 200000 ; j ++ ) { dist [ i ] [ j ] = INF ; } } function bfs ( dist , s ) { let q = new Array ( 200000 ) ; let qh = 0 , qt = 0 ; q [ qh ++ ] = s ; dist [ s ] = 0 ; while ( qt < qh ) { let x = q [ qt ++ ] ; for ( let y = 0 ; y < edges [ x ] . length ; y ++ ) { if ( dist [ edges [ x ] [ y ] ] == INF ) { dist [ edges [ x ] [ y ] ] = dist [ x ] + 1 ; q [ qh ++ ] = edges [ x ] [ y ] ; } } } } function shortestPathCost ( selected , K ) { let data = [ ] ; bfs ( dist [ 0 ] , 0 ) ; bfs ( dist [ 1 ] , N - 1 ) ; for ( let i = 0 ; i < K ; i ++ ) { data . push ( [ dist [ 0 ] [ selected [ i ] ] - dist [ 1 ] [ selected [ i ] ] , selected [ i ] ] ) ; } data . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; let best = 0 ; let MAX = - INF ; for ( let it = 0 ; it < data . length ; it ++ ) { let a = data [ it ] [ 1 ] ; best = Math . max ( best , MAX + dist [ 1 ] [ a ] ) ; MAX = Math . max ( MAX , dist [ 0 ] [ a ] ) ; } document . write ( Math . min ( dist [ 0 ] [ N - 1 ] , best + 1 ) ) ; } N = 5 ; M = 4 ; let K = 2 ; let selected = [ 1 , 3 ] ; ( selected ) . sort ( function ( a , b ) { return a - b ; } ) ; edges = [ ] ; for ( let i = 0 ; i < 200005 ; i ++ ) edges . push ( [ ] ) ; edges [ 0 ] . push ( 1 ) ; edges [ 1 ] . push ( 0 ) ; edges [ 1 ] . push ( 2 ) ; edges [ 2 ] . push ( 1 ) ; edges [ 2 ] . push ( 3 ) ; edges [ 3 ] . push ( 2 ) ; edges [ 3 ] . push ( 4 ) ; edges [ 4 ] . push ( 3 ) ; shortestPathCost ( selected , K ) ;

Index/key variables: a, i, it, j, s, x, y
Accumulator variables: i, it, j, qh, qt, y
Iterator variables: i, it, j, y
Javascript program:
function removeElements ( arr , n ) { arr . sort ( ( a , b ) => b - a ) ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { ans += arr [ i ] * Math . pow ( 2 , i ) ; } return ans ; } var n = 4 ; var arr = [ 3 , 1 , 2 , 3 ] ; document . write ( removeElements ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i