dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function prefixArr ( arr , prefix , N ) { for ( var i = 0 ; i < N ; i ++ ) { if ( i == 0 ) { prefix [ i ] [ 0 ] = arr [ i ] ; prefix [ i ] [ 1 ] = arr [ i ] ; } else { prefix [ i ] [ 0 ] = Math . max ( prefix [ i - 1 ] [ 0 ] , arr [ i ] ) ; prefix [ i ] [ 1 ] = Math . min ( prefix [ i - 1 ] [ 1 ] , arr [ i ] ) ; } } } function suffixArr ( arr , suffix , N ) { for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 ) { suffix [ i ] [ 0 ] = arr [ i ] ; suffix [ i ] [ 1 ] = arr [ i ] ; } else { suffix [ i ] [ 0 ] = Math . max ( suffix [ i + 1 ] [ 0 ] , arr [ i ] ) ; suffix [ i ] [ 1 ] = Math . min ( suffix [ i + 1 ] [ 1 ] , arr [ i ] ) ; } } } function maxAndmin ( prefix , suffix , N , L , R ) { var maximum , minimum ; if ( L == 0 && R == N - 1 ) { document . write ( " " + " " ) ; return ; } else if ( L == 0 ) { maximum = suffix [ R + 1 ] [ 0 ] ; minimum = suffix [ R + 1 ] [ 1 ] ; } else if ( R == N - 1 ) { maximum = prefix [ L - 1 ] [ 0 ] ; minimum = prefix [ R - 1 ] [ 1 ] ; } else { maximum = Math . max ( prefix [ L - 1 ] [ 0 ] , suffix [ R + 1 ] [ 0 ] ) ; minimum = Math . min ( prefix [ L - 1 ] [ 1 ] , suffix [ R + 1 ] [ 1 ] ) ; } document . write ( maximum + " " + minimum + " " ) ; } function MinMaxQueries ( a , Q ) { var N = arr . length ; var q = queries . length ; var prefix = Array . from ( Array ( N ) , ( ) => Array ( 2 ) ) ; var suffix = Array . from ( Array ( N ) , ( ) => Array ( 2 ) ) ; prefixArr ( arr , prefix , N ) ; suffixArr ( arr , suffix , N ) ; for ( var i = 0 ; i < q ; i ++ ) { var L = queries [ i ] [ 0 ] ; var R = queries [ i ] [ 1 ] ; maxAndmin ( prefix , suffix , N , L , R ) ; } } var arr = [ 2 , 3 , 1 , 8 , 3 , 5 , 7 , 4 ] ; var queries = [ [ 4 , 6 ] , [ 0 , 4 ] , [ 3 , 7 ] , [ 2 , 5 ] ] ; MinMaxQueries ( arr , queries ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( s1 , s2 ) { let s1_0 = 0 , s2_0 = 0 ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] == ' ' ) { s1_0 ++ ; } if ( s2 [ i ] == ' ' ) { s2_0 ++ ; } } if ( s1_0 != s2_0 ) { document . write ( " " ) ; return ; } else { let Count1 = 0 , Count2 = 0 ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] == ' ' ) { Count1 ++ ; } if ( s2 [ i ] == ' ' ) { Count2 ++ ; } if ( Count1 < Count2 ) { document . write ( " " + " " ) ; return ; } } document . write ( " " + " " ) ; } } let s1 = " " ; let s2 = " " ; check ( s1 , s2 ) ; s1 = " " ; s2 = " " ; check ( s1 , s2 ) ;

Index/key variables: i
Accumulator variables: Count1, Count2, i, s1_0, s2_0
Iterator variables: i
Javascript program:
function isBinaryStringsEqual ( list1 , list2 ) { var str1 = list1 . split ( " " ) ; var str2 = list2 . split ( " " ) ; var str1Zeros = 0 , str1Ones = 0 ; var str2Zeros = 0 , str2Ones = 0 ; var flag = 0 ; var curStr1Ones = 0 ; for ( var i = 0 ; i < str1 . length ; i ++ ) { if ( str1 [ i ] === " " ) { str1Ones ++ ; } else if ( str1 [ i ] === " " ) { str1Zeros ++ ; } if ( str2 [ i ] === " " ) { str2Ones ++ ; } else if ( str2 [ i ] === " " ) { str2Zeros ++ ; } } if ( str1Zeros !== str2Zeros && str1Ones !== str2Ones ) { document . write ( " " ) ; } else { for ( var i = 0 ; i < str1 . length ; i ++ ) { if ( str1 [ i ] !== str2 [ i ] ) { if ( str1 [ i ] === " " && curStr1Ones > 0 ) { str1 [ i ] = " " ; curStr1Ones -- ; } if ( str1 [ i ] === " " && curStr1Ones === 0 ) { flag ++ ; break ; } if ( str1 [ i ] === " " && str2 [ i ] === " " ) { str1 [ i ] = " " ; curStr1Ones ++ ; } } } if ( flag === 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } var str1 = " " ; var str2 = " " ; isBinaryStringsEqual ( str1 , str2 ) ;

Index/key variables: i
Accumulator variables: curStr1Ones, flag, i, str1Ones, str1Zeros, str2Ones, str2Zeros
Iterator variables: i
Javascript program:
function noOfValidKbers ( K , arr ) { var set = new Set ( ) ; while ( K != 0 ) { set . add ( K % 10 ) ; K = parseInt ( K / 10 ) ; } var count = 0 ; for ( i = 0 ; i < arr . length ; i ++ ) { var no = arr [ i ] ; var flag = true ; while ( no != 0 ) { var digit = no % 10 ; if ( ! set . has ( digit ) ) { flag = false ; break ; } no = parseInt ( no / 10 ) ; } if ( flag == true ) { count ++ ; } } return count ; } var K = 12 ; var arr = [ 1 , 12 , 1222 , 13 , 2 ] ; document . write ( noOfValidKbers ( K , arr ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
let maxN = 100 ; let Tree = new Array ( 4 * maxN ) ; function build ( arr , index , s , e ) { if ( s == e ) Tree [ index ] = arr [ s ] ; else { let m = parseInt ( ( s + e ) / 2 , 10 ) ; build ( arr , 2 * index , s , m ) ; build ( arr , 2 * index + 1 , m + 1 , e ) ; Tree [ index ] = Math . max ( Tree [ 2 * index ] , Tree [ 2 * index + 1 ] ) ; } } function atleast_x ( index , s , e , ql , qr , x ) { if ( ql > e qr < s ) return - 1 ; if ( s <= ql && e <= qr ) { if ( Tree [ index ] < x ) return - 1 ; while ( s != e ) { let m = parseInt ( ( s + e ) / 2 , 10 ) ; if ( Tree [ 2 * index ] >= x ) { e = m ; index = 2 * index ; } else { s = m + 1 ; index = 2 * index + 1 ; } } return s ; } let m = parseInt ( ( s + e ) / 2 , 10 ) ; let val = atleast_x ( 2 * index , s , m , ql , qr , x ) ; if ( val != - 1 ) return val ; return atleast_x ( 2 * index + 1 , m + 1 , e , ql , qr , x ) ; } function update ( index , s , e , new_val , pos ) { if ( s == e ) Tree [ index ] = new_val ; else { let m = parseInt ( ( s + e ) / 2 , 10 ) ; if ( pos <= m ) { update ( 2 * index , s , m , new_val , pos ) ; } else { update ( 2 * index + 1 , m + 1 , e , new_val , pos ) ; } Tree [ index ] = Math . max ( Tree [ 2 * index ] , Tree [ 2 * index + 1 ] ) ; } } function printAnswer ( arr , n ) { build ( arr , 1 , 0 , n - 1 ) ; document . write ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 2 ) + " " ) ; arr [ 2 ] = 5 ; update ( 1 , 0 , n - 1 , 5 , 2 ) ; document . write ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 4 ) + " " ) ; document . write ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 0 ) + " " ) ; } let arr = [ 1 , 3 , 2 , 4 , 6 ] ; let N = arr . length ; printAnswer ( arr , N ) ;

Index/key variables: index, s
Javascript program:
class TreeNode { constructor ( data ) { this . left = null ; this . right = null ; this . val = data ; } } function find_ht ( root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return 1 ; return Math . max ( find_ht ( root . left ) , find_ht ( root . right ) ) + 1 ; } function find_node ( root , req_node ) { if ( root == null ) return req_node ; let left_ht = find_ht ( root . left ) ; let right_ht = find_ht ( root . right ) ; if ( left_ht > right_ht ) { req_node = find_node ( root . left , req_node ) ; } else if ( right_ht > left_ht ) { req_node = find_node ( root . right , req_node ) ; } else { req_node = root ; return req_node ; } return req_node ; } let root = new TreeNode ( 1 ) ; root . left = new TreeNode ( 2 ) ; root . right = new TreeNode ( 3 ) ; let req_node = null ; req_node = find_node ( root , req_node ) ; document . write ( req_node . val ) ;

Class/struct names: TreeNode
Javascript program:
function maxEvenIntegers ( arr , N , M ) { let ans = 0 ; for ( let i = 0 ; i <= N - M ; i ++ ) { let cnt = 0 ; for ( let j = 0 ; j < M ; j ++ ) { if ( arr [ i + j ] % 2 == 0 ) cnt ++ ; } ans = Math . max ( ans , cnt ) ; } return ans ; } let arr = [ 2 , 3 , 5 , 4 , 7 , 6 ] ; let K = 3 ; let N = arr . length ; document . write ( maxEvenIntegers ( arr , N , K ) + " " ) ;

Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function countDiv ( arr ) { let rem0 = 0 ; let rem1 = 0 ; let rem2 = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { let digitSum = 0 ; digitSum += arr [ i ] ; if ( digitSum % 3 == 0 ) { rem0 += 1 ; } else if ( digitSum % 3 == 1 ) { rem1 += 1 ; } else { rem2 += 1 ; } } return ( parseInt ( rem0 / 2 , 10 ) + Math . min ( rem1 , rem2 ) ) ; } let arr = [ 5 , 3 , 2 , 8 , 7 ] ; document . write ( countDiv ( arr ) ) ;

Index/key variables: i
Accumulator variables: digitSum, i, rem0, rem1, rem2
Iterator variables: i
Javascript program:
function MaxNonEmpSubSeq ( a , n ) { let sum = 0 ; let max = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( max < a [ i ] ) { max = a [ i ] ; } } if ( max <= 0 ) { return max ; } for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > 0 ) { sum += a [ i ] ; } } return sum ; } let arr = [ - 2 , 11 , - 4 , 2 , - 3 , - 10 ] ; let N = arr . length ; document . write ( MaxNonEmpSubSeq ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function getcount ( n , k ) { let res = ( n >> ( k + 1 ) ) << k ; if ( ( ( n >> k ) & 1 ) != 0 ) res += n & ( ( 1 << k ) - 1 ) ; return res ; } let N = 14 ; let K = 2 ; document . write ( getcount ( N + 1 , K ) ) ;

Accumulator variables: res
Javascript program:
function splitString ( S , N ) { var c = S . charAt ( N - 1 ) ; var f = 0 ; for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( S . charAt ( i ) == c ) { f = 1 ; break ; } } if ( f > 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var S = " " ; var N = S . length ; splitString ( S , N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function longestLastingBulb ( onTime , s ) { let ans ; let n = onTime . length ; let maxDur = Number . MIN_VALUE ; let maxPos = Number . MIN_VALUE ; let currentDiff = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { currentDiff = onTime [ i ] ; maxDur = currentDiff ; maxPos = i ; } else { currentDiff = onTime [ i ] - onTime [ i - 1 ] ; if ( maxDur < currentDiff ) { maxDur = currentDiff ; maxPos = i ; } else { if ( maxDur == currentDiff ) { let one = s [ i ] ; let two = s [ maxPos ] ; if ( one > two ) { maxDur = currentDiff ; maxPos = i ; } } } } } ans = s [ maxPos ] ; return ans ; } let S = " " ; let arr = [ 12 , 23 , 36 , 46 , 62 ] ; document . write ( longestLastingBulb ( arr , S ) ) ;

Index/key variables: i, maxPos
Accumulator variables: i
Iterator variables: i
Javascript program:
let tup = [ ] ; function findIntersectingRange ( N , ranges ) { let curr ; let currPos ; for ( let i = 0 ; i < N ; i ++ ) { let x , y ; x = ranges [ i ] [ 0 ] ; y = ranges [ i ] [ 1 ] ; let arr = [ x , y , i + 1 ] ; tup . push ( arr ) ; } tup . sort ( function ( a , b ) { if ( a [ 0 ] == b [ 0 ] ) { if ( a [ 1 ] == b [ 1 ] ) { return a [ 2 ] - b [ 2 ] ; } else { return a [ 1 ] - b [ 1 ] ; } } return a [ 0 ] - b [ 0 ] ; } ) ; curr = tup [ 0 ] [ 1 ] ; currPos = tup [ 0 ] [ 2 ] ; for ( let i = 1 ; i < N ; i ++ ) { let Q = tup [ i - 1 ] [ 0 ] ; let R = tup [ i ] [ 0 ] ; if ( Q == R ) { if ( tup [ i - 1 ] [ 1 ] < tup [ i ] [ 1 ] ) document . write ( tup [ i - 1 ] [ 2 ] + " " + tup [ i ] [ 2 ] ) ; else document . write ( tup [ i ] [ 2 ] + " " + tup [ i - 1 ] [ 2 ] ) ; return ; } let T = tup [ i ] [ 1 ] ; if ( T <= curr ) { document . write ( tup [ i ] [ 2 ] + " " + currPos ) ; return ; } else { curr = T ; currPos = tup [ i ] [ 2 ] ; } } document . write ( " " ) ; } let N = 5 ; let ranges = [ [ 1 , 5 ] , [ 2 , 10 ] , [ 3 , 10 ] , [ 2 , 2 ] , [ 2 , 15 ] ] ; findIntersectingRange ( N , ranges ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printNGE ( arr , n ) { let s = [ ] ; let nge = new Array ( n ) ; let i = 0 ; for ( i = 0 ; i < n ; i ++ ) { nge [ i ] = - 1 ; } i = 0 ; while ( i < 2 * n ) { while ( s . length != 0 && arr [ i % n ] > arr [ s [ s . length - 1 ] ] ) { nge [ s [ s . length - 1 ] ] = arr [ i % n ] ; s . pop ( ) ; } s . push ( i % n ) ; i ++ ; } for ( i = 0 ; i < n ; i ++ ) { document . write ( nge [ i ] + " " ) ; } } let arr = [ 4 , - 2 , 5 , 8 ] ; let N = arr . length ; printNGE ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var N = 100005 ; function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; var p , i ; for ( p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } function digitProduct ( number ) { var res = 1 ; while ( number > 0 ) { res *= ( number % 10 ) ; number = parseInt ( number / 10 ) ; } return res ; } function DistinctCompositeDigitProduct ( arr , n ) { var output = new Set ( ) ; var prime = Array ( N + 1 ) . fill ( true ) ; SieveOfEratosthenes ( prime , N ) ; var i ; for ( i = 0 ; i < n ; i ++ ) { var ans = digitProduct ( arr [ i ] ) ; if ( ans <= 1 ) { continue ; } if ( prime [ ans ] == false ) { output . add ( ans ) ; } } document . write ( output . size ) ; } var arr = [ 13 , 55 , 7 , 13 , 11 , 71 , 233 , 233 , 144 , 89 ] ; var n = arr . length ; DistinctCompositeDigitProduct ( arr , n ) ;

Index/key variables: ans, i, p
Accumulator variables: i, p, res
Iterator variables: i, p
Javascript program:
function simpleSieve ( lmt , prime ) { let Sieve = new Array ( lmt + 1 ) ; Sieve . fill ( true ) Sieve [ 0 ] = Sieve [ 1 ] = false ; for ( let i = 2 ; i <= lmt ; ++ i ) { if ( Sieve [ i ] == true ) { prime . push ( i ) ; for ( let j = i * i ; j <= lmt ; j += i ) { Sieve [ j ] = false ; } } } } function SegmentedSieveFn ( low , high ) { let lmt = Math . floor ( Math . sqrt ( high ) ) + 1 ; let prime = new Array ( ) ; simpleSieve ( lmt , prime ) ; let n = high - low + 1 ; let segmentedSieve = new Array ( n + 1 ) . fill ( true ) ; for ( let i = 0 ; i < prime . length ; i ++ ) { let lowLim = Math . floor ( low / prime [ i ] ) * prime [ i ] ; if ( lowLim < low ) { lowLim += prime [ i ] ; } for ( let j = lowLim ; j <= high ; j += prime [ i ] ) { if ( j != prime [ i ] ) { segmentedSieve [ j - low ] = false ; } } } return segmentedSieve ; } function countPairsWhoseSumPrimeL_R ( L , R ) { let segmentedSieve = SegmentedSieveFn ( L , R ) ; let cntPairs = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( segmentedSieve [ i - L ] ) { cntPairs += Math . floor ( i / 2 ) ; } } return cntPairs ; } let L = 1 , R = 5 ; document . write ( countPairsWhoseSumPrimeL_R ( L , R ) ) ;

Index/key variables: i, j
Accumulator variables: cntPairs, i, j, lowLim
Iterator variables: i, j
Javascript program:
function count_zeroes ( n , str ) { var cnt = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] === " " ) cnt ++ ; } return cnt ; } function kReducingStringUtil ( n , k , str , no_of_zeroes ) { var zeroes_in_2k = parseInt ( ( no_of_zeroes * ( 2 * k ) ) / n ) ; var ones_in_2k = 2 * k - zeroes_in_2k ; var temp_str = " " ; for ( var i = 0 ; i < zeroes_in_2k / 2 ; i ++ ) { temp_str += " " ; } for ( var i = 0 ; i < ones_in_2k ; i ++ ) { temp_str += " " ; } for ( var i = 0 ; i < zeroes_in_2k / 2 ; i ++ ) { temp_str += " " ; } var final_str = " " ; for ( var i = 0 ; i < n / ( 2 * k ) ; i ++ ) { final_str += temp_str ; } for ( var i = 0 ; i < n % ( 2 * k ) ; i ++ ) { final_str += temp_str [ i ] ; } return final_str ; } function kReducingString ( n , k , str ) { var no_of_zeroes = count_zeroes ( n , str ) ; var no_of_ones = n - no_of_zeroes ; if ( no_of_zeroes === 0 no_of_zeroes === n ) { return str ; } if ( k === 1 ) { if ( no_of_zeroes === 0 no_of_zeroes === n ) { return str ; } else { return " " ; } } var check = false ; for ( var i = n / k ; i < n ; i += n / k ) { if ( no_of_zeroes === i no_of_ones === i ) { check = true ; break ; } } if ( check === false ) { return " " ; } return kReducingStringUtil ( n , k , str , no_of_zeroes ) ; } var str = " " ; var K = 4 ; var N = str . length ; document . write ( kReducingString ( N , K , str ) ) ;

Index/key variables: i
Accumulator variables: cnt, final_str, i, temp_str
Iterator variables: i
Boolean variables: check
Javascript program:
function countSum ( a , n , sum ) { let i , j , k ; let count = 0 ; let m = new Map ( ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { let temp = a [ i ] + a [ j ] ; if ( temp < sum && m . has ( sum - temp ) ) count += m . get ( sum - temp ) ; } for ( j = 0 ; j < i ; j ++ ) { let temp = a [ i ] + a [ j ] ; if ( temp < sum ) if ( m . has ( temp ) ) m . set ( temp , m . get ( temp ) + 1 ) ; else m . set ( temp , 1 ) ; } } return count ; } let arr = [ 4 , 5 , 3 , 1 , 2 , 4 ] ; let S = 13 ; let N = arr . length ; document . write ( countSum ( arr , N , S ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function check ( arr , n ) { var hm = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { hm . set ( arr [ i ] , 1 ) ; for ( var j = i + 1 ; j < n ; j ++ ) { if ( hm . has ( arr [ j ] ) ) hm . set ( arr [ j ] , hm . get ( arr [ j ] ) + 1 ) ; else hm . set ( arr [ j ] , 1 ) var flag = false ; hm . forEach ( ( value , key ) => { if ( value == 1 ) { flag = true ; } } ) ; if ( ! flag ) return " " ; } hm = new Map ( ) ; } return " " ; } var arr = [ 1 , 2 , 1 ] ; var N = arr . length ; document . write ( check ( arr , N ) ) ;

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

Index/key variables: mid
Javascript program:
function computePos ( arr , n , value ) { if ( value < arr [ 0 ] ) return 0 ; if ( value > arr [ n - 1 ] ) return n - 1 ; var start = 0 ; var end = n - 1 ; while ( start < end ) { var mid = parseInt ( ( start + end + 1 ) / 2 ) ; if ( arr [ mid ] >= value ) end = mid - 1 ; else start = mid ; } return start ; } function countShift ( arr , n , queries ) { for ( var i = 0 ; i < queries . length ; i ++ ) { var index = queries [ i ] [ 0 ] ; var update = queries [ i ] [ 1 ] ; var newElement = arr [ index ] + update ; var newIndex = computePos ( arr , n , newElement ) ; document . write ( Math . abs ( newIndex - index ) + " " ) ; } } var arr = [ 2 , 3 , 4 , 5 , 6 ] ; var N = arr . length ; var queries = [ [ 0 , - 1 ] , [ 4 , - 11 ] ] ; countShift ( arr , N , queries ) ;

Index/key variables: i, index, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( key ) { this . left = null ; this . right = null ; this . key = key ; } } function newNode ( key ) { let temp = new Node ( key ) ; return temp ; } let ans ; function countReqNodes ( root , minNodeVal ) { if ( root == null ) return ; if ( root . key <= minNodeVal ) { minNodeVal = root . key ; ans ++ ; } countReqNodes ( root . left , minNodeVal ) ; countReqNodes ( root . right , minNodeVal ) ; } let root = newNode ( 8 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 6 ) ; root . left . right = newNode ( 7 ) ; root . right . left = newNode ( 3 ) ; root . right . right = newNode ( 9 ) ; let minNodeVal = Number . MAX_VALUE ; ans = 0 ; countReqNodes ( root , minNodeVal ) ; document . write ( ans ) ;

Accumulator variables: ans
Class/struct names: Node
Javascript program:
function isPalindrome ( str ) { var i = 0 , j = str . length - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } function formPalindrome ( a , b , n ) { var aa = new Array ( n + 2 ) ; var bb = new Array ( n + 2 ) ; for ( var i = 0 ; i < n + 2 ; i ++ ) { aa [ i ] = ' ' ; bb [ i ] = ' ' ; } for ( var i = 1 ; i <= n ; i ++ ) { aa [ i ] = a [ i - 1 ] ; bb [ i ] = b [ i - 1 ] ; } var ok = Boolean ( false ) ; for ( var i = 0 ; i <= n + 1 ; i ++ ) { var la = " " ; var ra = " " ; var lb = " " ; var rb = " " ; for ( var j = 1 ; j <= i - 1 ; j ++ ) { if ( aa [ j ] == ' ' ) la += " " ; else la += aa [ j ] ; if ( bb [ j ] == ' ' ) lb += " " ; else lb += bb [ j ] ; } for ( var j = i ; j <= n + 1 ; j ++ ) { if ( aa [ j ] == ' ' ) ra += " " ; else ra += aa [ j ] ; if ( bb [ j ] == ' ' ) rb += " " ; else rb += bb [ j ] ; } if ( isPalindrome ( la + rb ) || isPalindrome ( lb + ra ) ) { ok = true ; break ; } } if ( ok ) document . write ( " " ) ; else document . write ( " " ) ; } var A = " " ; var B = " " ; var N = 4 ; formPalindrome ( A , B , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, la, lb, ra, rb
Iterator variables: i, j
Boolean variables: ok
Javascript program:
function minElements ( A , B , N , M ) { var map = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { map . set ( A [ i ] , i ) ; } var subseq = [ ] ; var l = 0 , r = - 1 ; for ( var i = 0 ; i < M ; i ++ ) { if ( map . has ( B [ i ] ) ) { var e = map . get ( B [ i ] ) ; while ( l <= r ) { var m = l + parseInt ( ( r - l ) / 2 ) ; if ( subseq [ m ] < e ) l = m + 1 ; else r = m - 1 ; } if ( r + 1 < subseq . length ) { subseq [ r + 1 ] = e ; } else { subseq . push ( e ) ; } l = 0 ; r = subseq . length - 1 ; } } return N - subseq . length ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var B = [ 2 , 5 , 6 , 4 , 9 , 12 ] ; var M = A . length ; var N = B . length ; document . write ( minElements ( A , B , M , N ) ) ;

Index/key variables: i, m
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function sfpa ( V , src , Edges , M ) { var g = Array . from ( Array ( V ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < M ; i ++ ) { var u = Edges [ i ] [ 0 ] ; var v = Edges [ i ] [ 1 ] ; var w = Edges [ i ] [ 2 ] ; g [ u ] . push ( new pair ( v , w ) ) ; } var dist = Array ( V ) ; for ( var i = 0 ; i < V ; i ++ ) dist [ i ] = 1000000000 ; var inQueue = Array ( V ) . fill ( false ) ; var cnt = Array ( V ) . fill ( 0 ) ; dist [ src ] = 0 ; var q = [ ] ; q . push ( src ) ; inQueue [ src ] = true ; while ( q . length != 0 ) { var u = q [ 0 ] ; q . shift ( ) ; inQueue [ u ] = false ; for ( var x of g [ u ] ) { var v = x . first ; var cost = x . second ; if ( dist [ v ] > dist [ u ] + cost ) { dist [ v ] = dist [ u ] + cost ; if ( ! inQueue [ v ] ) { q . push ( v ) ; inQueue [ v ] = true ; cnt [ v ] ++ ; if ( cnt [ v ] >= V ) return true ; } } } } return false ; } var N = 4 ; var src = 0 ; var M = 4 ; var Edges = [ [ 0 , 1 , 1 ] , [ 1 , 2 , - 1 ] , [ 2 , 3 , - 1 ] , [ 3 , 0 , - 1 ] ] ; if ( sfpa ( N , src , Edges , M ) == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, src, u, v
Accumulator variables: i
Iterator variables: i, x
Class/struct names: pair
Javascript program:
let INF = 99999 ; function floyd_warshall ( graph , V ) { let dist = new Array ( V ) ; for ( let i = 0 ; i < V ; i ++ ) { dist [ i ] = new Array ( V ) ; } let i , j , k ; for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { dist [ i ] [ j ] = graph [ i ] [ j ] ; } } for ( k = 0 ; k < V ; k ++ ) { for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } } let sum = 0 ; for ( i = 0 ; i < V ; i ++ ) { for ( j = i + 1 ; j < V ; j ++ ) { sum += dist [ i ] [ j ] ; } } return sum ; } function sumOfshortestPath ( N , E , edges ) { let g = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { g [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { g [ i ] [ j ] = INF ; } } for ( let i = 0 ; i < E ; i ++ ) { let u = edges [ i ] [ 0 ] ; let v = edges [ i ] [ 1 ] ; let w = edges [ i ] [ 2 ] ; g [ u ] [ v ] = w ; g [ v ] [ u ] = w ; } return floyd_warshall ( g , N ) ; } let N = 4 ; let E = 3 ; let Edges = [ [ 0 , 1 , 1 ] , [ 1 , 2 , 2 ] , [ 2 , 3 , 3 ] ] ; document . write ( sumOfshortestPath ( N , E , Edges ) ) ;

Index/key variables: i, j, k, u, v
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k