dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function power ( a , b , c ) { var result = 1 ; while ( b > 0 ) { if ( ( b & 1 ) == 1 ) { result = ( result * a ) % c ; } b /= 2 ; a = ( a * a ) % c ; } return result ; } function calculate ( X , N ) { var a = [ ... Array ( 10 ) ] ; var cyclicity = [ ... Array ( 11 ) ] ; cyclicity [ 1 ] = 1 ; cyclicity [ 2 ] = 4 ; cyclicity [ 3 ] = 4 ; cyclicity [ 4 ] = 2 ; cyclicity [ 5 ] = 1 ; cyclicity [ 6 ] = 1 ; cyclicity [ 7 ] = 4 ; cyclicity [ 8 ] = 4 ; cyclicity [ 9 ] = 2 ; cyclicity [ 10 ] = 1 ; if ( N == 0 N == 1 ) { return X % 10 ; } else if ( N == 2 N == 3 N == 4 ) { var temp = 1e18 ; a [ 2 ] = 2 ; a [ 3 ] = 6 ; a [ 4 ] = 4 ; var v = X % 10 ; if ( v != 0 ) { var u = cyclicity [ parseInt ( v ) ] ; var r = a [ parseInt ( N ) ] % u ; if ( r == 0 ) { if ( v == 2 v == 4 v == 6 v == 8 ) { return 6 ; } else if ( v == 5 ) { return 5 ; } else if ( v == 1 v == 3 v == 7 v == 9 ) { return 1 ; } } else { return power ( v , r , temp ) % 10 ; } } else { return 0 ; } } return 1 ; } var X = 18 ; var N = 4 ; var result = calculate ( X , N ) ; document . write ( result ) ;

Accumulator variables: b
Javascript program:
function formQuadruplets ( arr , n ) { var ans = 0 , pairs = 0 ; pairs = parseInt ( n / 4 ) ; arr . sort ( ) . reverse ( ) ; for ( var i = 0 ; i < n - pairs ; i += 3 ) { ans += arr [ i + 2 ] ; } return ans ; } var arr = [ 2 , 1 , 7 , 5 , 5 , 4 , 1 , 1 , 3 , 3 , 2 , 2 ] ; var n = arr . length ; document . write ( formQuadruplets ( arr , n ) + " " ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let mod = 1000000007 ; function waysToColor ( arr , n , k ) { let powOf2 = new Array ( 500 ) ; let c = new Array ( 500 ) ; for ( let i = 0 ; i < 500 ; i ++ ) { c [ i ] = new Array ( 500 ) ; for ( let j = 0 ; j < 500 ; j ++ ) { c [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= n ; i ++ ) { c [ i ] [ 0 ] = 1 ; for ( let j = 1 ; j <= i ; j ++ ) { c [ i ] [ j ] = ( c [ i - 1 ] [ j ] + c [ i - 1 ] [ j - 1 ] ) % mod ; } } powOf2 [ 0 ] = powOf2 [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { powOf2 [ i ] = powOf2 [ i - 1 ] * 2 % mod ; } let rem = n - k ; arr [ k ++ ] = n + 1 ; arr . sort ( function ( a , b ) { return a - b ; } ) ; let answer = 1 ; for ( let i = 0 ; i < k ; i ++ ) { let x = arr [ i ] - ( i - 1 >= 0 ? arr [ i - 1 ] : 0 ) - 1 ; answer *= c [ rem ] [ x ] % mod * ( i != 0 && i != k - 1 ? powOf2 [ x ] : 1 ) % mod ; rem -= x ; } return answer ; } let N = 6 ; let K = 3 ; let arr = [ 1 , 2 , 6 , 0 ] ; document . write ( waysToColor ( arr , N , K ) ) ;

Index/key variables: i, j, rem, x
Accumulator variables: answer, i, j, k, rem
Iterator variables: i, j
Javascript program:
function printArray ( a , n ) { a . sort ( function ( a , b ) { return a - b ; } ) ; var i = 0 ; var j = n - 1 ; while ( i <= j ) { if ( i == j ) { document . write ( a [ i ] + " " ) ; } else { document . write ( a [ j ] + " " ) ; document . write ( a [ i ] + " " ) ; } i = i + 1 ; j = j - 1 ; } document . write ( " " ) ; } var arr1 = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; var n1 = arr1 . length ; printArray ( arr1 , n1 ) ;

Index/key variables: i, j
Javascript program:
function SmallestDiv ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return i ; } } return n ; } let X = 385 ; let ans = SmallestDiv ( X ) ; document . write ( ans + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function findArray ( n , k , s ) { var vis = Array ( n ) . fill ( 0 ) ; var cnt = 0 ; var arr = Array ( n ) . fill ( 0 ) ; for ( i = 0 ; i < n && cnt < k ; i += 2 ) { arr [ i ] = s ; vis [ i ] = 1 ; cnt ++ ; } var val = s ; if ( s % 2 == 0 ) val ++ ; else val = val + 2 ; for ( i = 0 ; i < n ; i ++ ) { if ( vis [ i ] == 0 ) { arr [ i ] = val ; } } printArr ( arr , n ) ; } var n = 8 , k = 3 , s = 12 ; findArray ( n , k , s ) ;

Index/key variables: i
Accumulator variables: cnt, i, val
Iterator variables: i
Javascript program:
var N = 100000 ; var prime = Array . from ( { length : N } , ( _ , i ) => 0 ) ; var divi = Array . from ( { length : N } , ( _ , i ) => 0 ) ; var sum = Array . from ( { length : N } , ( _ , i ) => 0 ) ; function SieveOfEratosthenes ( ) { for ( i = 0 ; i < N ; i ++ ) prime [ i ] = 1 ; prime [ 0 ] = prime [ 1 ] = 0 ; for ( p = 2 ; p * p < N ; p ++ ) { if ( prime [ p ] == 1 ) { for ( i = p * p ; i < N ; i += p ) prime [ i ] = 0 ; } } } function DivisorCount ( ) { for ( i = 1 ; i < N ; i ++ ) { for ( j = i ; j < N ; j += i ) { divi [ j ] ++ ; } } } function pre ( ) { for ( i = 1 ; i < N ; i ++ ) { if ( prime [ divi [ i ] ] == 1 ) { sum [ i ] = i ; } } for ( i = 1 ; i < N ; i ++ ) sum [ i ] += sum [ i - 1 ] ; } var l = 5 , r = 8 ; SieveOfEratosthenes ( ) ; DivisorCount ( ) ; pre ( ) ; document . write ( sum [ r ] - sum [ l - 1 ] ) ;

Index/key variables: i, j, p, r
Accumulator variables: i, j, p
Iterator variables: i, j, p
Javascript program:
let M = 1000000007 ; function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function modInverse ( n , p ) { return power ( n , p - 2 , p ) ; } function nCrModPFermat ( n , r , p ) { if ( r == 0 ) return 1 ; let fac = new Array ( n + 1 ) ; fac [ 0 ] = 1 ; let i ; for ( i = 1 ; i <= n ; i ++ ) fac [ i ] = fac [ i - 1 ] * i % p ; return ( fac [ n ] * modInverse ( fac [ r ] , p ) % p * modInverse ( fac [ n - r ] , p ) % p ) % p ; } function countOdd ( n ) { let x = parseInt ( n / 2 , 10 ) ; if ( n % 2 == 1 ) x ++ ; return x ; } function counteEven ( n ) { let x = parseInt ( n / 2 , 10 ) ; return x ; } function CountEvenSumSequences ( n ) { let count = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { let even = i , odd = n - i ; if ( odd % 2 == 1 ) continue ; let tot = ( power ( countOdd ( n ) , odd , M ) * nCrModPFermat ( n , odd , M ) ) % M ; tot = ( tot * power ( counteEven ( n ) , i , M ) ) % M ; count += tot * 0 + 521 ; count %= M ; } return ( count - 1 ) ; } let n = 5 ; document . write ( CountEvenSumSequences ( n ) ) ;

Index/key variables: i, n, r
Accumulator variables: count, i, x
Iterator variables: i
Javascript program:
const MAX = 1000000 ; let prime = new Array ( MAX ) ; function SieveOfEratosthenes ( ) { for ( let i = 0 ; i < MAX ; i ++ ) prime [ i ] = true ; for ( let p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * p ; i < MAX ; i += p ) prime [ i ] = false ; } } } function sumPrime ( k ) { SieveOfEratosthenes ( ) ; let v = [ ] ; for ( let i = 2 ; i < MAX ; i ++ ) { if ( prime [ i ] ) v . push ( i ) ; } let sum = 0 ; let skip = parseInt ( ( k * ( k - 1 ) ) / 2 ) ; while ( k > 0 ) { sum += v [ skip ] ; skip ++ ; k -- ; } return sum ; } let k = 3 ; document . write ( sumPrime ( k ) ) ;

Index/key variables: i, p, skip
Accumulator variables: i, k, p, skip, sum
Iterator variables: i, p
Javascript program:
function nextOccurrence ( str , n , start , ch ) { for ( var i = start ; i < n ; i ++ ) { if ( str [ i ] === ch ) return i ; } return - 1 ; } function countSubStr ( str , n , ch ) { var cnt = 0 ; var j = nextOccurrence ( str , n , 0 , ch ) ; for ( var i = 0 ; i < n ; i ++ ) { while ( j !== - 1 && j < i ) { j = nextOccurrence ( str , n , j + 1 , ch ) ; } if ( j === - 1 ) break ; cnt += n - j ; } return cnt ; } var str = " " ; var n = str . length ; var ch = " " ; document . write ( countSubStr ( str , n , ch ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function checkEvenOdd ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let arr = [ 2 , 12 , 20 , 36 , 38 ] ; let n = arr . length ; checkEvenOdd ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAXN = 30 ; function countMaxLength ( N ) { var res ; var pre = Array ( MAXN ) , p = 1 ; pre [ 0 ] = 0 ; for ( var i = 1 ; i < MAXN ; i ++ ) { p *= 2 ; pre [ i ] = pre [ i - 1 ] + i * p ; } var ind ; for ( var i = 1 ; i < MAXN ; i ++ ) { if ( pre [ i ] >= N ) { ind = i ; break ; } } var x = N - pre [ ind - 1 ] ; var y = 2 * ind - 1 ; if ( x >= y ) res = Math . min ( x , y ) ; else res = Math . max ( x , 2 * ( ind - 2 ) + 1 ) ; return res ; } var N = 25 ; document . write ( countMaxLength ( N ) ) ;

Index/key variables: i
Accumulator variables: i, p
Iterator variables: i
Javascript program:
function factorialUsingRecursion ( n ) { if ( n == 0 ) return 1 ; return n * factorialUsingRecursion ( n - 1 ) ; } function factorialUsingIteration ( n ) { var res = 1 , i ; for ( i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } var num = 5 ; document . write ( " " + num + " " + factorialUsingRecursion ( 5 ) + " " ) ; document . write ( " " + num + " " + factorialUsingIteration ( 5 ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function revereseArray ( arr , n ) { let rev = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) rev [ n - i - 1 ] = arr [ i ] ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = rev [ i ] ; } function printArray ( arr , size ) { for ( let i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; printArray ( arr , n ) ; revereseArray ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function __ ( x , y ) { return x ; } function revereseArray ( arr , n ) { for ( let i = 0 ; i < n / 2 ; i ++ ) arr [ i ] = __ ( arr [ n - i - 1 ] , arr [ n - i - 1 ] = arr [ i ] ) ; } function printArray ( arr , size ) { for ( let i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; printArray ( arr , n ) ; revereseArray ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findlet ( str , M ) { let N = str . length ; M = Math . min ( M , N ) ; let s1 = " " ; while ( M != 0 ) { s1 = " " ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { if ( ( str [ i - 1 ] == ' ' && str [ i + 1 ] != ' ' ) || ( str [ i - 1 ] != ' ' && str [ i + 1 ] == ' ' ) ) s1 += ' ' ; else s1 += ' ' ; } else s1 += ' ' ; } if ( str == s1 ) break ; str = s1 ; M -- ; } document . write ( s1 ) ; } let str = " " ; let M = 3 ; findlet ( str , M ) ;

Index/key variables: i
Accumulator variables: M, i, s1
Iterator variables: i
Javascript program:
function numberofSubsequences ( a , L , R , X , n ) { let ans = 0 ; for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { let cnt = 0 , sum = 0 ; let minVal = Number . MAX_SAFE_INTEGER , maxVal = Number . MIN_SAFE_INTEGER ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) ) { cnt += 1 ; sum += a [ j ] ; maxVal = Math . max ( maxVal , a [ j ] ) ; minVal = Math . min ( minVal , a [ j ] ) ; } } if ( cnt >= 2 && sum >= L && sum <= R && ( maxVal - minVal >= X ) ) { ans += 1 ; } } return ans ; } let a = [ 10 , 20 , 30 , 25 ] ; let L = 40 , R = 50 , X = 10 ; let N = a . length ; document . write ( numberofSubsequences ( a , L , R , X , N ) + " " ) ;

Index/key variables: j
Accumulator variables: ans, cnt, i, j, sum
Iterator variables: i, j
Javascript program:
function Minimum ( N , K ) { let sum = N * ( N + 1 ) / 2 ; if ( K > sum ) return - 1 ; if ( K <= N ) return 1 ; sum = 0 ; let count = 0 ; while ( N >= 1 && sum < K ) { count += 1 ; sum += N ; N -= 1 ; } return count ; } let N = 5 , K = 10 ; document . write ( Minimum ( N , K ) ) ;

Accumulator variables: N, count, sum
Javascript program:
function largestNum ( arr ) { let set = new Set ( ) ; let res = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { set . add ( arr [ i ] ) ; if ( set . has ( - 1 * arr [ i ] ) ) { res = Math . max ( res , Math . abs ( arr [ i ] ) ) ; } } return res ; } let arr = [ 3 , 2 , - 2 , 5 , - 3 ] ; document . write ( largestNum ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findElement ( A , N , X ) { var i = 0 ; var Comparisons = 0 ; var T = 1 ; var Found = " " ; Comparisons += 1 ; if ( N % 2 == 1 ) { i = 1 ; T *= ( A [ 0 ] - X ) ; } for ( ; i < N ; i += 2 ) { Comparisons += 1 ; T *= ( A [ i ] - X ) ; T *= ( A [ i + 1 ] - X ) ; } Comparisons += 1 ; if ( T == 0 ) { document . write ( " " + Comparisons ) ; } else { document . write ( " " ) ; } } var A = [ - 3 , 5 , 11 , 3 , 100 , 2 , 88 , 22 , 7 , 900 , 23 , 4 , 1 ] ; var N = A . length ; var X = 1 ; findElement ( A , N , X ) ;

Index/key variables: i
Accumulator variables: Comparisons, T, i
Javascript program:
function find ( arr , N , key ) { let l = 0 ; let h = N - 1 ; while ( l <= h ) { let mid = Math . floor ( ( l + h ) / 2 ) ; if ( arr [ mid ] == key ) return mid ; if ( arr [ l ] >= arr [ mid ] ) { if ( arr [ l ] >= key && key >= arr [ mid ] ) h = mid - 1 ; else l = mid + 1 ; } else { if ( arr [ mid ] >= key && key >= arr [ h ] ) l = mid + 1 ; else h = mid - 1 ; } } return - 1 ; } let arr = [ 10 , 8 , 6 , 5 , 2 , 1 , 13 , 12 ] ; let N = arr . length ; let key = 8 ; let ans = find ( arr , N , key ) ; document . write ( ans ) ;

Index/key variables: h, l, mid
Javascript program:
function maxItems ( n , m , a , b , K ) { var count = 0 ; var A = new Array ( n + 1 ) ; var B = new Array ( m + 1 ) ; A [ 0 ] = 0 ; B [ 0 ] = 0 ; var i ; for ( i = 1 ; i <= n ; i ++ ) { A [ i ] = a [ i - 1 ] + A [ i - 1 ] ; } for ( i = 1 ; i <= m ; i ++ ) { B [ i ] = b [ i - 1 ] + B [ i - 1 ] ; } for ( i = 0 ; i <= n ; i ++ ) { if ( A [ i ] > K ) break ; var rem = K - A [ i ] ; var j = 0 ; var lo = 0 , hi = m ; while ( lo <= hi ) { var mid = parseInt ( ( lo + hi ) / 2 ) ; if ( B [ mid ] <= rem ) { j = mid ; lo = mid + 1 ; } else { hi = mid - 1 ; } } count = Math . max ( j + i , count ) ; } document . write ( count ) ; } var n = 4 , m = 5 , K = 7 ; var A = [ 2 , 4 , 7 , 3 ] ; var B = [ 1 , 9 , 3 , 4 , 5 ] ; maxItems ( n , m , A , B , K ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function getCountPairs ( arr , N , S ) { let mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , 0 ) ; mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } let twice_count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( mp . get ( S - arr [ i ] ) != null ) { twice_count += mp . get ( S - arr [ i ] ) ; } if ( S - arr [ i ] == arr [ i ] ) twice_count -- ; } return Math . floor ( twice_count / 2 ) ; } function countPairs ( arr , N ) { let count = 0 ; let S = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) S . add ( arr [ i ] ) ; for ( let ele of S . values ( ) ) { let sum = 2 * ele ; count += getCountPairs ( arr , N , sum ) ; } return count ; } let N = 6 ; let arr = [ 4 , 2 , 5 , 1 , 3 , 5 ] ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i, twice_count
Iterator variables: ele, i
Javascript program:
function isPrime ( N ) { if ( N == 1 ) return false ; for ( var i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } function findCoPrime ( L , R ) { var coPrime ; for ( var i = R + 1 ; ; i ++ ) { if ( isPrime ( i ) ) { coPrime = i ; break ; } } return coPrime ; } var L = 16 , R = 17 ; document . write ( findCoPrime ( L , R ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var arr = [ 1 , 9 , 3 , 6 , 5 ] ; function maximumValue ( arr , n ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { ans = Math . max ( ans , arr [ i ] + arr [ j ] + i - j ) ; } } document . write ( ans ) ; } n = arr . length maximumValue ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumValue ( arr , n ) { var maxvalue = arr [ 0 ] ; var result = 0 ; for ( i = 1 ; i < n ; i ++ ) { result = Math . max ( result , maxvalue + arr [ i ] - i ) ; maxvalue = Math . max ( maxvalue , arr [ i ] + i ) ; } document . write ( result ) ; } var arr = [ 1 , 9 , 3 , 6 , 5 ] ; var N = arr . length ; maximumValue ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lower_bound ( arr , key ) { let low = 0 ; let high = arr . length - 1 ; while ( low < high ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; if ( arr [ mid ] >= key ) { high = mid ; } else { low = mid + 1 ; } } return low ; } function closestValue ( A , k ) { let close = A [ A . length - 1 ] ; let it = lower_bound ( A , k ) ; if ( it != A . length ) { close = A [ it ] ; if ( it != 0 ) { if ( ( k - A [ it - 1 ] ) < ( close - k ) ) { close = A [ it - 1 ] ; } } } return close ; } function minPossible ( arr , brr , crr ) { arr . sort ( ) ; crr . sort ( ) ; let minimum = Number . MAX_VALUE ; for ( let val in brr ) { let arr_close = closestValue ( arr , val ) ; let crr_close = closestValue ( crr , val ) ; if ( Math . abs ( val - arr_close ) + Math . abs ( val - crr_close ) < minimum ) minimum = Math . abs ( val - arr_close ) + Math . abs ( val - crr_close ) ; } document . write ( minimum ) ; } let a = [ 1 , 8 , 5 ] ; let b = [ 2 , 9 ] ; let c = [ 5 , 4 ] ; minPossible ( a , b , c ) ;

Index/key variables: it, mid
Iterator variables: val
Javascript program:
function minimum_swaps ( arr , n ) { var count = 0 ; var max_el = Math . max ( ... arr ) ; var min_el = Math . min ( ... arr ) ; if ( min_el === max_el ) return 0 ; var index_max = - 1 ; var index_min = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] === max_el && index_max === - 1 ) { index_max = i ; } if ( arr [ i ] === min_el ) { index_min = i ; } } count += index_max ; count += n - 1 - index_min ; if ( index_min < index_max ) count -= 1 ; return count ; } var arr = [ 2 , 4 , 1 , 6 , 5 ] ; var N = arr . length ; document . write ( minimum_swaps ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
var ans = 0 ; function DFS ( src , Adj , arr , currentMin , currentMax ) { ans = Math . max ( ans , Math . max ( Math . abs ( currentMax - arr [ src - 1 ] ) , Math . abs ( currentMin - arr [ src - 1 ] ) ) ) ; currentMin = Math . min ( currentMin , arr [ src - 1 ] ) ; currentMax = Math . min ( currentMax , arr [ src - 1 ] ) ; Adj [ src ] . forEach ( child => { DFS ( child , Adj , arr , currentMin , currentMax ) ; } ) ; } function getMaximumDifference ( Edges , arr , N , M ) { var Adj = Array . from ( Array ( N + 1 ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < M ; i ++ ) { var u = Edges [ i ] [ 0 ] ; var v = Edges [ i ] [ 1 ] ; Adj [ u ] . push ( v ) ; } DFS ( 1 , Adj , arr , arr [ 0 ] , arr [ 0 ] ) ; document . write ( ans ) ; } var N = 5 , M = 4 ; var Edges = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 4 , 5 ] , [ 1 , 3 ] ] ; var arr = [ 13 , 8 , 3 , 15 , 18 ] ; getMaximumDifference ( Edges , arr , N , M ) ;

Index/key variables: i, src, u
Accumulator variables: i
Iterator variables: i
Javascript program:
function leastWeightedSumPath ( n , edges , src , dst , K ) { var graph = new Map ( ) ; for ( var edge of edges ) { if ( ! graph . has ( edge [ 0 ] ) ) graph . set ( edge [ 0 ] , new Array ( ) ) var tmp = graph . get ( edge [ 0 ] ) ; tmp . push ( [ edge [ 1 ] , edge [ 2 ] ] ) ; graph . set ( edge [ 0 ] , tmp ) ; } var pq = [ ] ; var costs = Array . from ( Array ( n + 1 ) , ( ) => Array ( K + 2 ) . fill ( 1000000000 ) ) ; costs [ src ] [ K + 1 ] = 0 ; pq . push ( [ 0 , src , K + 1 ] ) ; while ( pq . length != 0 ) { var top = pq [ pq . length - 1 ] ; pq . pop ( ) ; if ( top [ 1 ] == dst ) return top [ 0 ] ; if ( top [ 2 ] == 0 ) continue ; if ( graph . has ( top [ 1 ] ) ) { for ( var neighbor of graph . get ( top [ 1 ] ) ) { if ( costs [ neighbor [ 0 ] ] [ top [ 2 ] - 1 ] < neighbor [ 1 ] + top [ 0 ] ) { continue ; } costs [ neighbor [ 0 ] ] [ top [ 2 ] - 1 ] = neighbor [ 1 ] + top [ 0 ] ; pq . push ( [ neighbor [ 1 ] + top [ 0 ] , neighbor [ 0 ] , top [ 2 ] - 1 ] ) ; } } pq . sort ( ( a , b ) => { if ( a [ 0 ] == b [ 0 ] ) return b [ 1 ] - a [ 1 ] return b [ 0 ] - a [ 0 ] ; } ) ; } return - 1 ; } var n = 3 , src = 0 , dst = 2 , k = 1 ; var edges = [ [ 0 , 1 , 100 ] , [ 1 , 2 , 100 ] , [ 0 , 2 , 500 ] ] ; document . write ( leastWeightedSumPath ( n , edges , src , dst , k ) ) ;

Index/key variables: src
Iterator variables: edge, neighbor
Javascript program:
function indivisibleDigits ( arr , N ) { for ( i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; for ( j = 2 ; j < 10 ; j ++ ) { var temp = arr [ i ] ; var flag = true ; while ( temp > 0 ) { if ( ( temp % 10 ) != 0 && ( temp % 10 ) % j == 0 ) { flag = false ; break ; } temp = parseInt ( temp / 10 ) ; } if ( flag ) { document . write ( j + " " ) ; } } document . write ( " " ) ; } } var arr = [ 4162 , 1152 , 99842 ] ; var N = arr . length ; indivisibleDigits ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function longestSequence ( arr , N ) { if ( N == 0 ) { document . write ( 0 ) ; return ; } arr . sort ( ) ; var maxLen = 1 ; var len = 1 ; var i ; for ( i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i - 1 ] + 1 ) { len ++ ; maxLen = Math . max ( maxLen , len ) ; } else { len = 1 ; } } document . write ( maxLen ) ; } var arr = [ 8 , 5 , 4 , 8 , 4 ] ; var N = arr . length ; longestSequence ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Javascript program:
function minSum ( arr , N , Q , M ) { for ( var i = 0 ; i < M ; i ++ ) { var val = Q [ i ] ; var front = 0 , rear = 0 ; for ( var j = 0 ; j < N ; j ++ ) { front += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } for ( var j = N - 1 ; j >= 0 ; j -- ) { rear += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } document . write ( Math . min ( front , rear ) + " " ) ; } } var arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 1 ] ; var N = arr . length ; var Q = [ 7 , 6 ] ; var M = Q . length ; minSum ( arr , N , Q , M ) ;

Index/key variables: i, j
Accumulator variables: front, i, j, rear
Iterator variables: i, j
Javascript program:
function KthCharacter ( S , N , K ) { var strarray = S . split ( ' ' ) ; strarray . sort ( ) ; var ch = strarray [ K - 1 ] ; var count = 0 ; strarray . forEach ( c => { if ( c == ch ) count ++ ; } ) ; document . write ( count ) ; } var S = " " ; var N = S . length ; var K = 3 ; KthCharacter ( S , N , K ) ;

Accumulator variables: count
Javascript program:
function findSubstring ( S ) { var T = " " ; var ans = " " ; var l = 0 ; T += S [ 0 ] ; for ( var i = 1 ; i < S . length ; i ++ ) { if ( Math . abs ( S [ i ] . charCodeAt ( 0 ) - S [ i - 1 ] . charCodeAt ( 0 ) ) === 1 ) { l = T . length ; if ( l > ans . length ) { ans = T ; } T = " " ; T += S [ i ] ; } else { T += S [ i ] ; } } l = T . length ; if ( l > ans . length ) { ans = T ; } document . write ( ans ) ; } var S = " " ; findSubstring ( S ) ;

Index/key variables: i
Accumulator variables: T, i
Iterator variables: i
Javascript program:
function findMinLength ( arr , N ) { let front = 0 , back = N - 1 ; while ( front < back ) { let x = arr [ front ] ; if ( arr [ front ] != arr [ back ] ) break ; while ( arr [ front ] == x && front <= back ) front ++ ; while ( arr [ back ] == x && front <= back ) back -- ; } document . write ( back - front + 1 ) ; document . write ( " " ) ; } let arr = [ 1 , 1 , 2 , 3 , 3 , 1 , 2 , 2 , 1 ] ; let N = arr . length ; findMinLength ( arr , N ) ;

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