dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function minPeaks ( list ) { var n = list . length ; var result = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { var min = 1000000000 ; var index = - 1 ; var size = list . length ; for ( var j = 0 ; j < size ; j ++ ) { if ( j == 0 && j + 1 < size ) { if ( list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( j == size - 1 && j - 1 >= 0 ) { if ( list [ j ] > list [ j - 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( size == 1 ) { min = list [ j ] ; index = j ; } else if ( list [ j ] > list [ j - 1 ] && list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } list . splice ( index , 1 ) ; result . push ( min ) ; } document . write ( " " ) ; for ( var i = 0 ; i < result . length ; i ++ ) { document . write ( result [ i ] + " " ) ; } document . write ( " " ) ; } var arr = [ 1 , 9 , 7 , 8 , 2 , 6 ] ; minPeaks ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binarySearch ( arr , N , X ) { let start = 0 ; let end = N ; while ( start <= end ) { let mid = Math . floor ( start + ( end - start ) / 2 ) ; if ( X == arr [ mid ] ) { return mid ; } else if ( X < arr [ mid ] ) { start = mid + 1 ; } else { end = mid - 1 ; } } return - 1 ; } let arr = [ 5 , 4 , 3 , 2 , 1 ] ; let N = arr . length ; let X = 5 ; document . write ( binarySearch ( arr , N , X ) ) ;

Index/key variables: mid
Javascript program:
function check_both_present ( arr , N , a , b ) { let f1 = false , f2 = false ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == a ) { f1 = true ; } if ( arr [ i ] == b ) { f2 = true ; } } if ( f1 && f2 ) { return true ; } else { return false ; } } function print_array ( ans , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } function build_AP ( N , a , b ) { let arr = Array ( N ) . fill ( 0 ) ; let ans = Array ( N ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) ans [ i ] = Number . MAX_VALUE ; let flag = 0 ; if ( a > b ) { a += ( b - ( b = a ) ) ; } let diff = b - a ; for ( let start = 1 ; start <= a ; start ++ ) { for ( let d = 1 ; d <= diff ; d ++ ) { arr [ 0 ] = start ; for ( let i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + d ; } if ( check_both_present ( arr , N , a , b ) && arr [ N - 1 ] < ans [ N - 1 ] ) { for ( let i = 0 ; i < N ; i ++ ) { ans [ i ] = arr [ i ] ; } } } } print_array ( ans , N ) ; } let N = 5 , A = 20 , B = 50 ; build_AP ( N , A , B ) ;

Index/key variables: i
Accumulator variables: a, d, i, start
Iterator variables: d, i, start
Boolean variables: f1, f2
Javascript program:
function isPrefixOfWord ( sentence , Word ) { var a = sentence . split ( " " ) ; var v = [ ] ; for ( var i = 0 ; i < a . length ; i ++ ) { v . push ( a [ i ] ) ; } for ( var i = 0 ; i < v . length ; i ++ ) { for ( var j = 0 ; j < v [ i ] . length ; j ++ ) { if ( v [ i ] . charAt ( j ) != Word [ j ] ) break ; else if ( j == Word . length - 1 ) return v [ i ] ; } } return " " ; } var s = " " ; var word = " " ; document . write ( isPrefixOfWord ( s , word ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function EvenLIS ( arr ) { let n = arr . length ; let lis = new Array ( n ) . fill ( 1 ) ; for ( let i = 1 ; i < n ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { if ( Math . abs ( arr [ i ] ) > Math . abs ( arr [ j ] ) && Math . abs ( arr [ i ] ) % 2 == 0 && Math . abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } let maxlen = 0 ; for ( let i = 0 ; i < n ; i ++ ) maxlen = Math . max ( maxlen , lis [ i ] ) ; document . write ( maxlen ) ; } let arrr = [ 11 , - 22 , 43 , - 54 , 66 , 5 ] ; let N = arrr . length ; EvenLIS ( arrr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let res = 0 ; class Node { constructor ( val ) { this . left = null ; this . right = null ; this . data = val ; } } function Sum ( root ) { if ( root == null ) { return 0 ; } let leftSubSum = Sum ( root . left ) ; let rightSubSum = Sum ( root . right ) ; if ( root . left != null && root . right != null && leftSubSum == rightSubSum ) res += 1 ; return root . data + leftSubSum + rightSubSum ; } let root = new Node ( 9 ) ; root . left = new Node ( 2 ) ; root . left . left = new Node ( - 1 ) ; root . left . right = new Node ( 3 ) ; root . right = new Node ( 4 ) ; root . right . right = new Node ( 0 ) ; res = 0 ; Sum ( root ) ; document . write ( res ) ;

Accumulator variables: res
Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . left = null ; this . right = null ; this . data = val ; } } function PrintAlternate ( root ) { let Q = [ ] ; Q . push ( root ) ; while ( Q . length > 0 ) { let N = Q . length ; for ( let i = 0 ; i < N ; i ++ ) { let temp = Q [ 0 ] ; Q . shift ( ) ; if ( i % 2 == 0 ) { document . write ( temp . data + " " ) ; } if ( temp . left != null ) { Q . push ( temp . left ) ; } if ( temp . right != null ) { Q . push ( temp . right ) ; } } document . write ( " " ) ; } } let root ; root = new Node ( 71 ) ; root . left = new Node ( 88 ) ; root . right = new Node ( 99 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 11 ) ; root . right . left . right = new Node ( 13 ) ; root . right . right . left = new Node ( 14 ) ; PrintAlternate ( root ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function countingSubarray ( arr , n ) { let a = new Array ( n ) ; let nsml = new Array ( n ) ; nsml . fill ( - 1 ) ; let nsmr = new Array ( n ) ; nsmr . fill ( n ) ; let st = [ ] ; for ( let i = n - 1 ; i >= 0 ; i -- ) { while ( st . length > 0 && arr [ st [ st . length - 1 ] ] >= arr [ i ] ) st . pop ( ) ; nsmr [ i ] = ( st . length > 0 ) ? st [ st . length - 1 ] : n ; st . push ( i ) ; } while ( st . length > 0 ) st . pop ( ) ; for ( let i = 0 ; i < n ; i ++ ) { while ( st . length > 0 && arr [ st [ st . length - 1 ] ] >= arr [ i ] ) st . pop ( ) ; nsml [ i ] = ( st . length > 0 ) ? st [ st . length - 1 ] : - 1 ; st . push ( i ) ; } for ( let i = 0 ; i < n ; i ++ ) { nsml [ i ] ++ ; nsmr [ i ] -- ; let r = nsmr [ i ] - i + 1 ; let l = i - nsml [ i ] + 1 ; a [ i ] = r * l ; } return a ; } let N = 5 ; let arr = [ 3 , 2 , 4 , 1 , 5 ] ; let a = countingSubarray ( arr , N ) ; document . write ( " " ) ; let n = a . length - 1 ; for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ; document . write ( a [ n ] + " " ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function reorderString ( A , B ) { let size_a = A . length ; let size_b = B . length ; let freq = new Array ( 300 ) ; for ( let i = 0 ; i < 300 ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < size_b ; i ++ ) freq [ B [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < size_a ; i ++ ) freq [ A [ i ] . charCodeAt ( 0 ) ] -- ; for ( let j = ' ' . charCodeAt ( 0 ) ; j <= ' ' . charCodeAt ( 0 ) ; j ++ ) { if ( freq [ j ] < 0 ) return " " ; } let answer = " " ; for ( let j = ' ' . charCodeAt ( 0 ) ; j < A [ 0 ] . charCodeAt ( 0 ) ; j ++ ) while ( freq [ j ] > 0 ) { answer += j ; freq [ j ] -- ; } let first = A [ 0 ] ; for ( let j = 0 ; j < size_a ; j ++ ) { if ( A [ j ] > A [ 0 ] ) break ; if ( A [ j ] < A [ 0 ] ) { answer += ( A ) . join ( " " ) ; A = new Array ( A . length ) ; break ; } } while ( freq [ first ] > 0 ) { answer += ( String . fromCharCode ( first ) ) ; -- freq [ first ] ; } answer += ( A ) . join ( " " ) ; for ( let j = ' ' . charCodeAt ( 0 ) ; j <= ' ' . charCodeAt ( 0 ) ; j ++ ) while ( freq [ j ] -- > 0 ) answer += String . fromCharCode ( j ) ; return answer ; } let A = " " ; let B = " " ; document . write ( reorderString ( A . split ( " " ) , B . split ( " " ) ) ) ;

Index/key variables: first, i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function maxConcurrentMeetingSlot ( meetings ) { meetings . sort ( function ( a , b ) { return ( a [ 0 ] != b [ 0 ] ) ? a [ 0 ] - b [ 0 ] : a [ 1 ] - b [ 1 ] } ) ; let pq = [ ] ; pq . push ( meetings [ 0 ] [ 1 ] ) ; pq . sort ( function ( a , b ) { return a - b ; } ) ; let max_len = 0 , max_start = 0 ; let max_end = 0 ; for ( let k = 0 ; k < meetings . length ; k ++ ) { while ( pq . length != 0 && meetings [ k ] [ 0 ] >= pq [ 0 ] ) pq . shift ( ) ; pq . push ( meetings [ k ] [ 1 ] ) ; pq . sort ( function ( a , b ) { return a - b ; } ) ; if ( pq . length > max_len ) { max_len = pq . length ; max_start = meetings [ k ] [ 0 ] ; max_end = pq [ 0 ] ; } } document . write ( max_start + " " + max_end + " " ) ; } let meetings = [ [ 100 , 200 ] , [ 50 , 300 ] , [ 300 , 400 ] ] ; maxConcurrentMeetingSlot ( meetings ) ;

Index/key variables: k
Accumulator variables: k
Iterator variables: k
Javascript program:
function func ( n ) { var count = 0 ; if ( n == 2 n == 1 ) return 1 ; if ( n % 2 == 0 ) count = 1 + func ( n / 2 ) ; if ( n % 2 != 0 ) count = 1 + func ( n * 3 + 1 ) ; return count ; } function findKthElement ( l , r , k ) { var arr = [ ] ; for ( var i = l ; i <= r ; i ++ ) arr . push ( i ) ; var result = [ ] ; arr . forEach ( i => { result . push ( [ i , func ( i ) ] ) ; } ) ; result . sort ( ) ; document . write ( result [ k - 1 ] [ 0 ] ) ; } var l = 12 ; var r = 15 ; var k = 2 ; findKthElement ( l , r , k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkHex ( s ) { let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { let ch = s [ i ] ; if ( ( ch < ' ' ch > ' ' ) && ( ch < ' ' ch > ' ' ) ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let s = " " ; checkHex ( s ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lenghtOfLongestAP ( A , n ) { var dp = new Map ( ) ; var res = 2 ; for ( var i = 0 ; i < n ; ++ i ) { for ( var j = i + 1 ; j < n ; ++ j ) { var d = A [ j ] - A [ i ] ; if ( dp . has ( d ) ) { if ( dp . get ( d ) . has ( i ) ) { var tmp = dp . get ( d ) ; tmp . set ( j , dp . get ( d ) . get ( i ) + 1 ) ; } else { var tmp = new Map ( ) ; tmp . set ( j , 2 ) ; dp . set ( d , tmp ) ; } } else { var tmp = new Map ( ) ; tmp . set ( j , 2 ) ; dp . set ( d , tmp ) ; } res = Math . max ( res , dp . get ( d ) . get ( j ) ) ; } } return res ; } var arr = [ 20 , 1 , 15 , 3 , 10 , 5 , 8 ] ; var N = arr . length ; document . write ( lenghtOfLongestAP ( arr , N ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
let N = 100005 function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } function LISPrime ( arr , n ) { let lisp = new Array ( n ) ; let prime = new Array ( N + 1 ) ; prime . fill ( true ) ; SieveOfEratosthenes ( prime , N ) ; lisp [ 0 ] = prime [ arr [ 0 ] ] ? 1 : 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( ! prime [ arr [ i ] ] ) { lisp [ i ] = 0 ; continue ; } lisp [ i ] = 1 ; for ( let j = 0 ; j < i ; j ++ ) { if ( prime [ arr [ j ] ] && arr [ i ] > arr [ j ] && lisp [ i ] < lisp [ j ] + 1 ) { lisp [ i ] = lisp [ j ] + 1 ; } } } return lisp . sort ( ( a , b ) => b - a ) [ 0 ] ; } let arr = [ 1 , 2 , 5 , 3 , 2 , 5 , 1 , 7 ] ; let M = arr . length ; document . write ( LISPrime ( arr , M ) ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, p
Iterator variables: i, j, p
Javascript program:
function checkSumOfNatural ( n ) { var i = 1 ; var flag = false ; while ( i * ( i + 1 ) < n * 2 ) { var X = i * ( i + 1 ) ; var t = n * 2 - X ; var k = parseInt ( Math . sqrt ( t ) ) ; if ( k * ( k + 1 ) == t ) { flag = true ; break ; } i += 1 ; } if ( flag ) document . write ( " " ) ; else document . write ( " " ) ; } var n = 25 ; checkSumOfNatural ( n ) ;

Accumulator variables: i
Boolean variables: flag
Javascript program:
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function catalan ( n ) { let c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } function findWays ( n ) { if ( n & 1 ) return 0 ; return catalan ( n / 2 ) ; } function countNonNPeriodic ( N ) { document . write ( findWays ( 2 * N ) - findWays ( N ) ) ; } let N = 4 ; countNonNPeriodic ( N ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function checkSameDiag ( li , x , y , m , n ) { let I = 0 , J = 0 ; let P = 0 , Q = 0 ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( li [ i ] [ j ] == x ) { I = i ; J = j ; } if ( li [ i ] [ j ] == y ) { P = i ; Q = j ; } } } if ( P - Q == I - J P + Q == I + J ) { document . write ( " " ) ; } else document . write ( " " ) ; } let m = 6 ; let n = 5 ; let li = [ [ 32 , 94 , 99 , 26 , 82 ] , [ 51 , 69 , 52 , 63 , 17 ] , [ 90 , 36 , 88 , 55 , 33 ] , [ 93 , 42 , 73 , 39 , 28 ] , [ 81 , 31 , 83 , 53 , 10 ] , [ 12 , 29 , 85 , 80 , 87 ] ] ; let x = 42 ; let y = 80 ; checkSameDiag ( li , x , y , m , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function nonLower ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! ( s [ i ] . charCodeAt ( ) >= 97 && s [ i ] . charCodeAt ( ) <= 122 ) ) { return true ; } } return false ; } function printCodes ( output ) { for ( let i = 0 ; i < output . length ; i ++ ) { if ( nonLower ( output [ i ] ) ) continue ; document . write ( output [ i ] + " " ) ; } } function getChar ( n ) { return String . fromCharCode ( n + 96 ) ; } function getCode ( str ) { if ( str . length == 0 ) { let ans = [ " " ] ; return ans ; } let output1 = getCode ( str . substring ( 1 ) ) ; let output2 = new Array ( 0 ) ; let firstDigit = ( str [ 0 ] - ' ' ) ; let firstTwoDigit = 0 ; if ( str . length >= 2 ) { firstTwoDigit = ( str [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) * 10 + ( str [ 1 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; if ( firstTwoDigit >= 10 && firstTwoDigit <= 26 ) { output2 = getCode ( str . substring ( 2 ) ) ; } } let output = new Array ( output1 . length + output2 . length ) ; let k = 0 ; for ( let i = 0 ; i < output1 . length ; i ++ ) { let ch = getChar ( firstDigit ) ; output [ i ] = ch + output1 [ i ] ; k ++ ; } for ( let i = 0 ; i < output2 . length ; i ++ ) { let ch = getChar ( firstTwoDigit ) ; output [ k ] = ch + output2 [ i ] ; k ++ ; } return output ; } let input = " " ; let output = getCode ( input ) ; printCodes ( output ) ;

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function isprm ( n ) { if ( n <= 1 ) return 0 ; if ( n <= 3 ) return 1 ; if ( n % 2 == 0 n % 3 == 0 ) return 0 ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) return 0 ; } return 1 ; } function countprime ( n ) { var count = 0 ; var primevector = [ ] ; for ( var i = 2 ; i <= n ; i ++ ) { if ( isprm ( i ) == 1 ) { primevector . push ( i ) ; } } var sum = primevector [ 0 ] ; for ( var i = 1 ; i < primevector . length ; i ++ ) { sum += primevector [ i ] ; if ( sum > n ) break ; if ( isprm ( sum ) == 1 ) { count ++ ; } } return count ; } var N = 45 ; document . write ( countprime ( N ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function isPerfectSquare ( n ) { var sr = Math . sqrt ( n ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function SubarrayHavingPerfectSquare ( arr , k ) { var ans = [ ] ; var sum = 0 , i ; for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } var found = false ; if ( isPerfectSquare ( sum ) ) { ans [ 0 ] = 0 ; ans [ 1 ] = i - 1 ; } else { for ( var j = i ; j < arr . length ; j ++ ) { sum = sum + arr [ j ] - arr [ j - k ] ; if ( isPerfectSquare ( sum ) ) { found = true ; ans [ 0 ] = j - k + 1 ; ans [ 1 ] = j ; } } for ( var k = ans [ 0 ] ; k <= ans [ 1 ] ; k ++ ) { document . write ( arr [ k ] + " " ) ; } } if ( found == false ) { document . write ( " " ) ; } } var arr = [ 20 , 34 , 51 , 10 , 99 , 87 , 23 , 45 ] ; var K = 3 ; SubarrayHavingPerfectSquare ( arr , K ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Boolean variables: found
Javascript program:
var TEN = 10 ; function updateFreq ( n , freq ) { while ( n ) { var digit = n % TEN ; freq [ digit ] ++ ; n = parseInt ( n / TEN ) ; } } function areAnagrams ( a , b ) { var freqA = Array ( TEN ) . fill ( 0 ) ; var freqB = Array ( TEN ) . fill ( 0 ) ; updateFreq ( a , freqA ) ; updateFreq ( b , freqB ) ; for ( var i = 0 ; i < TEN ; i ++ ) { if ( freqA [ i ] != freqB [ i ] ) return false ; } return true ; } function isPowerOf2 ( N ) { for ( var i = 0 ; i < 32 ; i ++ ) { if ( areAnagrams ( 1 << i , N ) ) { document . write ( ( 1 << i ) ) ; return true ; } } return false ; } var N = 46 ; if ( ! isPowerOf2 ( N ) ) { document . write ( " " ) ; }

Index/key variables: digit, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function right_angled ( n ) { var count = 0 ; for ( z = 1 ; z <= n ; z ++ ) { for ( y = 1 ; y <= z ; y ++ ) { for ( x = 1 ; x <= y ; x ++ ) { if ( ( x * x ) + ( y * y ) == ( z * z ) ) { count ++ ; } } } } return count ; } var n = 5 ; document . write ( right_angled ( n ) ) ;

Accumulator variables: count, x, y, z
Iterator variables: x, y, z
Javascript program:
function mirrorMatrix ( mat1 , mat2 , N ) { let row = 0 ; let col = 0 ; let isMirrorImage = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = N - 1 ; j >= 0 ; j -- ) { if ( mat2 [ row ] [ col ] != mat1 [ i ] [ j ] ) { isMirrorImage = false ; } col ++ ; } col = 0 ; row ++ ; } if ( isMirrorImage ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 4 ; let mat1 = [ [ 1 , 2 , 3 , 4 ] , [ 0 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let mat2 = [ [ 4 , 3 , 2 , 1 ] , [ 8 , 7 , 6 , 0 ] , [ 12 , 11 , 10 , 9 ] , [ 16 , 15 , 14 , 13 ] ] ; mirrorMatrix ( mat1 , mat2 , N ) ;

Index/key variables: col, i, j, row
Accumulator variables: col, i, j, row
Iterator variables: i, j
Boolean variables: isMirrorImage
Javascript program:
function dfs ( src , dest , vis , adj ) { vis [ src ] = 1 ; if ( src == dest ) { return 1 ; } for ( let u = 0 ; u < adj [ src ] . length ; u ++ ) { if ( vis [ adj [ src ] [ u ] ] == 0 ) { let temp = dfs ( adj [ src ] [ u ] , dest , vis , adj ) ; if ( temp != 0 ) { return temp + 1 ; } } } return 0 ; } function countNodes ( V , E , src , dest , edges ) { let adj = new Array ( V + 1 ) ; for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; for ( let i = 0 ; i < E ; i ++ ) { adj [ edges [ i ] [ 0 ] ] . push ( edges [ i ] [ 1 ] ) ; adj [ edges [ i ] [ 1 ] ] . push ( edges [ i ] [ 0 ] ) ; } let vis = new Array ( V + 1 ) ; for ( let i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = 0 ; } let count = dfs ( src , dest , vis , adj ) ; return count - 2 ; } let V = 8 , E = 7 ; let src = 5 , dest = 2 ; let edges = [ [ 1 , 4 ] , [ 4 , 5 ] , [ 4 , 2 ] , [ 2 , 6 ] , [ 6 , 3 ] , [ 2 , 7 ] , [ 3 , 8 ] ] ; document . write ( countNodes ( V , E , src , dest , edges ) ) ;

Index/key variables: i, src, u
Accumulator variables: i, u
Iterator variables: i, u
Javascript program:
function GCD ( a , b ) { if ( a == 0 ) return b ; return GCD ( b % a , a ) ; } function LCM ( a , b ) { return ( a * b ) / GCD ( a , b ) ; } function checkPairwiseCoPrime ( A , n ) { var prod = 1 ; var lcm = 1 ; for ( i = 0 ; i < n ; i ++ ) { prod *= A [ i ] ; lcm = LCM ( A [ i ] , lcm ) ; } if ( prod == lcm ) document . write ( " " ) ; else document . write ( " " ) ; } var A = [ 2 , 3 , 5 ] ; var n = A . length ; checkPairwiseCoPrime ( A , n ) ;

Index/key variables: i
Accumulator variables: i, prod
Iterator variables: i
Javascript program:
function maxDiffSubsets ( arr ) { var totalSum = 0 ; var pos = false , neg = false ; var min = Number . MAX_VALUE ; for ( i = 0 ; i < arr . length ; i ++ ) { totalSum += Math . abs ( arr [ i ] ) ; if ( arr [ i ] > 0 ) pos = true ; if ( arr [ i ] < 0 ) neg = true ; if ( arr [ i ] < min ) min = arr [ i ] ; } if ( pos && neg ) return totalSum ; else return totalSum - 2 * min ; } var S = [ 1 , 2 , 1 ] ; var N = S . length ; if ( N < 2 ) document . write ( " " ) ; else document . write ( maxDiffSubsets ( S ) ) ;

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Boolean variables: neg, pos
Javascript program:
function minDiffSubArray ( arr , n ) { let prefix_sum = new Array ( n ) ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ; let suffix_sum = new Array ( n ) ; suffix_sum [ n - 1 ] = arr [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) suffix_sum [ i ] = suffix_sum [ i + 1 ] + arr [ i ] ; let minDiff = Number . MAX_VALUE ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let diff = Math . abs ( prefix_sum [ i ] - suffix_sum [ i + 1 ] ) ; if ( diff < minDiff ) minDiff = diff ; } return minDiff ; } let arr = [ 7 , 9 , 5 , 10 ] ; let n = arr . length ; document . write ( minDiffSubArray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function dailyTemperatures ( T ) { var n = T . length ; var daysOfWait = Array ( n ) . fill ( - 1 ) ; var s = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { while ( s . length != 0 && T [ s [ s . length - 1 ] ] < T [ i ] ) { daysOfWait [ s [ s . length - 1 ] ] = i - s [ s . length - 1 ] ; s . pop ( ) ; } s . push ( i ) ; } for ( var i = 0 ; i < n ; i ++ ) { document . write ( daysOfWait [ i ] + " " ) ; } } var arr = [ 73 , 74 , 75 , 71 , 69 , 72 , 76 , 73 ] ; dailyTemperatures ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let timeT = 0 ; function dfs ( u , p , dis , vis , distance , parent , preTime , postTime , Adj ) { distance [ u ] = dis ; parent [ u ] = p ; vis [ u ] = 1 ; timeT ++ ; preTime [ u ] = timeT ; for ( let i = 0 ; i < Adj [ u ] . length ; i ++ ) { if ( vis [ Adj [ u ] [ i ] ] == 0 ) { dfs ( Adj [ u ] [ i ] , u , dis + 1 , vis , distance , parent , preTime , postTime , Adj ) ; } } timeT ++ ; postTime [ u ] = timeT ; } function addEdge ( Adj , u , v ) { Adj [ u ] . push ( v ) ; Adj [ v ] . push ( u ) ; } function findNodeU ( N , V , Vertices , Edges ) { let vis = new Array ( N + 1 ) ; vis . fill ( 0 ) ; let distance = new Array ( N + 1 ) ; distance . fill ( 0 ) ; let parent = new Array ( N + 1 ) ; parent . fill ( 0 ) ; let preTime = new Array ( N + 1 ) ; preTime . fill ( 0 ) ; let postTime = new Array ( N + 1 ) ; postTime . fill ( 0 ) ; let Adj = [ ] ; for ( let i = 0 ; i < N + 1 ; i ++ ) Adj . push ( [ ] ) ; let u = 0 , v ; for ( let i = 0 ; i < N - 1 ; i ++ ) { addEdge ( Adj , Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } dfs ( 1 , 0 , 0 , vis , distance , parent , preTime , postTime , Adj ) ; let maximumDistance = 0 ; maximumDistance = 0 ; for ( let k = 0 ; k < V ; k ++ ) { if ( maximumDistance < distance [ Vertices [ k ] ] ) { maximumDistance = distance [ Vertices [ k ] ] ; u = Vertices [ k ] ; } if ( parent [ Vertices [ k ] ] != 0 ) { Vertices [ k ] = parent [ Vertices [ k ] ] ; } } let ans = true ; let flag ; for ( let k = 0 ; k < V ; k ++ ) { if ( preTime [ Vertices [ k ] ] <= preTime [ u ] && postTime [ Vertices [ k ] ] >= postTime [ u ] ) flag = true ; else flag = false ; ans = ans & flag ; } if ( ans ) document . write ( u ) ; else document . write ( " " ) ; } let N = 10 ; let V = 5 ; let Vertices = [ 4 , 3 , 8 , 9 , 10 ] ; let Edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 2 , 5 ] , [ 2 , 6 ] , [ 3 , 7 ] , [ 7 , 8 ] , [ 7 , 9 ] , [ 9 , 10 ] ] ; findNodeU ( N , V , Vertices , Edges ) ;

Index/key variables: i, k, u, v
Accumulator variables: i, k, timeT
Iterator variables: i, k
Boolean variables: ans, flag