dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findMinimumOperations ( a , b ) { var step = 0 ; var last_index = 0 ; while ( a !== b ) { for ( var i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] !== b [ i ] ) { last_index = i ; } } var ch = a . split ( " " ) ; for ( var i = 0 ; i <= last_index ; i ++ ) { if ( ch [ i ] === " " ) { ch [ i ] = " " ; } else { ch [ i ] = " " ; } } a = ch . join ( " " ) ; step ++ ; } document . write ( step ) ; } var A = " " ; var B = " " ; findMinimumOperations ( A , B ) ;

Index/key variables: i
Accumulator variables: i, step
Iterator variables: i
Javascript program:
function isValid ( arr , n , m , d ) { for ( i = 0 ; i < m ; i ++ ) { if ( Math . abs ( arr [ n - m + i ] - arr [ i ] ) < d ) { return 0 ; } } return 1 ; } function countPairs ( arr , N , K ) { var ans = 0 ; var left = 0 , right = N / 2 + 1 ; arr . sort ( ) ; while ( left < right ) { var mid = parseInt ( ( left + right ) / 2 ) ; if ( isValid ( arr , N , mid , K ) == 1 ) { ans = mid ; left = mid + 1 ; } else right = mid - 1 ; } document . write ( ans ) ; } var arr = [ 1 , 3 , 3 , 5 ] ; var K = 2 ; var N = arr . length ; countPairs ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function max_distance ( a , temp , n ) { var mp = new Map ( ) ; for ( var i = 1 ; i <= n ; i ++ ) { temp [ i ] = - 1 ; } for ( var i = 0 ; i < n ; i ++ ) { if ( ! mp . has ( a [ i ] ) ) temp [ a [ i ] ] = i + 1 ; else temp [ a [ i ] ] = Math . max ( temp [ a [ i ] ] , i - mp [ a [ i ] ] ) ; mp . set ( a [ i ] , i ) ; } for ( var i = 1 ; i <= n ; i ++ ) { if ( temp [ i ] != - 1 ) temp [ i ] = Math . max ( temp [ i ] , n - mp . get ( i ) ) ; } } function min_comm_ele ( a , ans , temp , n ) { max_distance ( a , temp , n ) ; for ( var i = 1 ; i <= n ; i ++ ) { ans [ i ] = - 1 ; } for ( var i = 1 ; i <= n ; i ++ ) { if ( ans [ temp [ i ] ] == - 1 ) ans [ temp [ i ] ] = i ; } for ( var i = 1 ; i <= n ; i ++ ) { if ( i > 1 && ans [ i - 1 ] != - 1 ) { if ( ans [ i ] == - 1 ) ans [ i ] = ans [ i - 1 ] ; else ans [ i ] = Math . min ( ans [ i ] , ans [ i - 1 ] ) ; } document . write ( ans [ i ] + " " ) ; } } var N = 6 ; var a = [ 1 , 3 , 4 , 5 , 6 , 7 ] ; var temp = new Array ( 100 ) , ans = Array ( 100 ) ; min_comm_ele ( a , ans , temp , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function FindTrip ( arr , N ) { for ( let i = 1 ; i < N - 1 ; i ++ ) { let p = arr [ i - 1 ] ; let q = arr [ i ] ; let r = arr [ i + 1 ] ; if ( p < q && q > r ) { document . write ( ( i - 1 ) + " " + ( i ) + " " + ( i + 1 ) ) ; return ; } } document . write ( - 1 ) ; } let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; FindTrip ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function cntSubarrays ( arr , N ) { var cntSub = 0 ; var cntUnique = 0 ; var cntFreq = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = i ; j < N ; j ++ ) { if ( cntFreq . has ( arr [ j ] ) ) cntFreq . set ( arr [ j ] , cntFreq . get ( arr [ j ] ) + 1 ) else cntFreq . set ( arr [ j ] , 1 ) ; if ( cntFreq . get ( arr [ j ] ) == 1 ) { cntUnique ++ ; } else if ( cntFreq . get ( arr [ j ] ) == 2 ) { cntUnique -- ; } if ( cntUnique == 0 ) { cntSub ++ ; } } cntFreq = new Map ( ) ; cntUnique = 0 ; } return cntSub ; } var arr = [ 1 , 1 , 2 , 2 , 2 ] ; var N = arr . length ; document . write ( cntSubarrays ( arr , N ) ) ;

Index/key variables: j
Accumulator variables: cntSub, cntUnique, i, j
Iterator variables: i, j
Javascript program:
function checkPalinK ( str , K ) { var N = str . length ; var cntFreq = Array ( 256 ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] ] += 1 ; } var cntOddFreq = 0 ; for ( i = 0 ; i < 256 ; i ++ ) { if ( cntFreq [ i ] % 2 == 1 ) { cntOddFreq ++ ; } } if ( cntOddFreq <= ( K + 1 ) ) { return true ; } return false ; } var str = " " ; var K = 2 ; if ( checkPalinK ( str , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: cntOddFreq, i
Iterator variables: i
Javascript program:
function countRemovableElem ( arr , N ) { let hash = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { hash [ i ] = 0 ; } let mex = N + 1 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] <= N ) hash [ arr [ i ] ] = 1 ; } for ( let i = 1 ; i <= N ; i ++ ) { if ( hash [ i ] == 0 ) { mex = i ; break ; } } document . write ( N - ( mex - 1 ) ) ; } let arr = [ 2 , 3 , 5 , 1 , 6 ] ; let N = arr . length ; countRemovableElem ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printIndexes ( str ) { var N = str . length ; var cntFreq = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } var cntLeftFreq = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { var cntLeft = 0 ; var cntRight = 0 ; for ( var j = str [ i ] . charCodeAt ( 0 ) - 1 ; j >= 0 ; j -- ) { cntLeft += cntLeftFreq [ j ] ; cntRight += cntFreq [ j ] - cntLeftFreq [ j ] ; } cntLeftFreq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; if ( cntLeft == cntRight && cntLeft != 0 ) { document . write ( i + " " ) ; } } } var str = " " ; printIndexes ( str ) ;

Index/key variables: i, j
Accumulator variables: cntLeft, cntRight, i, j
Iterator variables: i, j
Javascript program:
function Count_Number ( x ) { let ans = 0 ; if ( x % 99 != 0 ) { ans = - 1 ; } else { let diff = x / 99 ; for ( let i = 1 ; i < 10 ; i ++ ) { for ( let j = 1 ; j < 10 ; j ++ ) { if ( ( i - j ) == diff ) { ans += 10 ; } } } } return ans ; } let x = 792 ; document . write ( Count_Number ( x ) ) ;

Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let INF = Number . MAX_VALUE ; function findMaxPoint ( arr , i , n ) { if ( i == n ) return [ INF , INF ] ; let flag = true ; for ( let j = 0 ; j < n ; j ++ ) { if ( j == i ) continue ; if ( arr [ j ] [ 0 ] >= arr [ i ] [ 0 ] arr [ j ] [ 1 ] >= arr [ i ] [ 1 ] ) { flag = false ; break ; } } if ( flag ) return arr [ i ] ; return findMaxPoint ( arr , i + 1 , n ) ; } function findMaxPoints ( arr , n ) { let ans = findMaxPoint ( arr , 0 , n ) ; if ( ans [ 0 ] == INF ) { document . write ( - 1 ) ; } else { document . write ( " " + ans [ 0 ] + " " + ans [ 1 ] + " " ) ; } } let arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 5 , 5 ] ] ; let N = arr . length ; findMaxPoints ( arr , N ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSubarray ( arr , N ) { var m = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { var mini = 1000000000 ; for ( var j = i ; j < N ; j ++ ) { mini = Math . min ( mini , arr [ j ] ) ; if ( m . has ( mini ) ) m . set ( mini , m . get ( mini ) + 1 ) else m . set ( mini , 1 ) } } for ( var i = 0 ; i < N ; i ++ ) { document . write ( m . get ( arr [ i ] ) + " " ) ; } } var arr = [ 3 , 2 , 1 , 4 ] ; var N = arr . length ; minSubarray ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minSubarray ( arr , N ) { let result = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) result [ i ] = 0 ; let l = [ ] ; let r = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { let count = 1 ; while ( l . length != 0 && l [ l . length - 1 ] [ 0 ] > arr [ i ] ) { count += l [ l . length - 1 ] [ 1 ] ; l . pop ( ) ; } l . push ( [ arr [ i ] , count ] ) ; result [ i ] = count ; } for ( let i = N - 1 ; i >= 0 ; i -- ) { let count = 1 ; while ( r . length != 0 && r [ r . length - 1 ] [ 0 ] >= arr [ i ] ) { count += r [ r . length - 1 ] [ 1 ] ; r . pop ( ) ; } r . push ( [ arr [ i ] , count ] ) ; result [ i ] *= count ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( result [ i ] + " " ) ; } } let arr = [ 3 , 2 , 1 , 4 ] ; let N = arr . length ; minSubarray ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isPrime ( num ) { if ( num <= 1 ) return false ; for ( let i = 2 ; i * i <= num ; i ++ ) if ( num % i == 0 ) return false ; return true ; } function isFulPrime ( n ) { if ( ! isPrime ( n ) ) return false ; else { while ( n > 0 ) { let rem = n % 10 ; if ( ! ( rem == 2 rem == 3 rem == 5 rem == 7 ) ) return false ; n = Math . floor ( n / 10 ) ; } } return true ; } function countFulPrime ( L , R ) { let cnt = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( ( i % 2 ) != 0 && isFulPrime ( i ) ) { cnt ++ ; } } return cnt ; } let L = 1 , R = 100 ; let ans = 0 ; if ( L < 3 ) ans ++ ; document . write ( ans + countFulPrime ( L , R ) ) ;

Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function printAlter ( arr , N ) { for ( var currIndex = 0 ; currIndex < N ; currIndex ++ ) { if ( currIndex % 2 == 0 ) { document . write ( arr [ currIndex ] + " " ) ; } } } var arr = [ 1 , 2 , 3 , 4 , 5 ] var N = arr . length ; printAlter ( arr , N ) ;

Index/key variables: currIndex
Accumulator variables: currIndex
Iterator variables: currIndex
Javascript program:
function findmin ( s ) { let n = s . length ; let i , j , maximum = 0 ; var incr = new Array ( n + 1 ) ; incr . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { incr [ i + 1 ] = incr [ i ] ; if ( s [ i ] == ' ' ) { incr [ i + 1 ] ++ ; } } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { maximum = Math . max ( maximum , incr [ i ] + j - i + 1 - ( incr [ j + 1 ] - incr [ i ] ) + incr [ n ] - incr [ j + 1 ] ) ; } } return n - maximum ; } let S = " " ; let minimum = findmin ( S ) ; document . write ( minimum + ' ' ) ;

Index/key variables: i, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPower ( x ) { return ( x && ( ! ( x & ( x - 1 ) ) ) ) ; } function maximumlength ( arr , N ) { var max_length = 0 ; var max_len_subarray = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( isPower ( arr [ i ] ) == 1 ) { max_length ++ ; max_len_subarray = Math . max ( max_length , max_len_subarray ) ; } else { max_length = 0 ; } } document . write ( max_len_subarray ) ; } var arr = [ 2 , 5 , 4 , 6 , 8 , 8 , 2 ] ; var N = arr . length ; maximumlength ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, max_length
Iterator variables: i
Javascript program:
function findLengthOfShortestSubarray ( arr , N ) { let minlength = Number . MAX_VALUE ; let left = 0 ; let right = N - 1 ; while ( left < right && arr [ left + 1 ] >= arr [ left ] ) { left ++ ; } if ( left == N - 1 ) return 0 ; while ( right > left && arr [ right - 1 ] <= arr [ right ] ) { right -- ; } minlength = Math . min ( N - left - 1 , right ) ; let j = right ; for ( let i = 0 ; i < left + 1 ; i ++ ) { if ( arr [ i ] <= arr [ j ] ) { minlength = Math . min ( minlength , j - i - 1 ) ; } else if ( j < N - 1 ) { j ++ ; } else { break ; } } return minlength ; } let arr = [ 6 , 3 , 10 , 11 , 15 , 20 , 13 , 3 , 18 , 12 ] ; let N = arr . length ; document . write ( ( findLengthOfShortestSubarray ( arr , N ) ) ) ;

Index/key variables: i, j, left, right
Accumulator variables: i, j, left, right
Iterator variables: i
Javascript program:
function minSub ( N ) { let count = 0 ; while ( N >= 0 ) { let num = N ; let rev = 0 ; while ( num != 0 ) { let digit = num % 10 ; rev = ( rev * 10 ) + digit ; num = Math . floor ( num / 10 ) ; } if ( N == rev ) { break ; } count ++ ; N -- ; } document . write ( count ) ; } let N = 3456 ; minSub ( N ) ;

Accumulator variables: N, count
Javascript program:
function numberOfGP ( L , N ) { if ( N <= 2 ) return 0 ; let count = 0 ; let res = 0 ; for ( let i = 2 ; i < N ; ++ i ) { if ( L [ i - 1 ] * L [ i - 1 ] == L [ i ] * L [ i - 2 ] ) { ++ count ; } else { count = 0 ; } res += count ; } return res ; } let arr = [ 1 , 2 , 4 , 8 , 16 , 24 ] ; let N = arr . length ; document . write ( numberOfGP ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Javascript program:
function cntSubarr ( arr , N ) { var res = 0 ; var prefixXor = 0 ; var i , j ; for ( i = 0 ; i < N - 1 ; i ++ ) { prefixXor = arr [ i ] ; for ( j = i + 1 ; j < N ; j ++ ) { prefixXor ^= arr [ j ] ; if ( prefixXor == 0 && ( j - i + 1 ) % 2 == 0 ) { res ++ ; } } } return res ; } var arr = [ 2 , 2 , 3 , 3 , 6 , 7 , 8 ] ; var N = arr . length ; document . write ( cntSubarr ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, prefixXor, res
Iterator variables: i, j
Javascript program:
let M = 1000000 ; function cntSubXor ( arr , N ) { let prefixXor = 0 ; let Even = Array . from ( { length : M } , ( _ , i ) => 0 ) ; let Odd = Array . from ( { length : M } , ( _ , i ) => 0 ) ; let cntSub = 0 ; Odd [ 0 ] = 1 ; for ( let i = 0 ; i < N ; i ++ ) { prefixXor = Math . floor ( prefixXor ^ arr [ i ] ) ; if ( i % 2 == 1 ) { cntSub += Odd [ prefixXor ] ; Odd [ prefixXor ] ++ ; } else { cntSub += Even [ prefixXor ] ; Even [ prefixXor ] ++ ; } } return cntSub ; } let arr = [ 2 , 2 , 3 , 3 , 6 , 7 , 8 ] ; let N = arr . length ; document . write ( cntSubXor ( arr , N ) ) ;

Index/key variables: i, prefixXor
Accumulator variables: cntSub, i
Iterator variables: i
Javascript program:
var S = 0 ; function findMaxSum ( arr , n , min , k ) { var A = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { A . push ( [ arr [ i ] , min [ i ] ] ) ; } A . sort ( ( a , b ) => b [ 0 ] - a [ 0 ] ) ; var K = 0 ; for ( var i = 0 ; i < n ; i ++ ) { S += Math . max ( A [ i ] [ 0 ] - K , A [ i ] [ 1 ] ) ; K += k ; } } var arr = [ ] , min = [ ] ; arr = [ 3 , 5 , 2 , 1 ] ; min = [ 3 , 2 , 1 , 3 ] ; var N = arr . length ; var K = 3 ; findMaxSum ( arr , N , min , K , S ) ; document . write ( S ) ;

Index/key variables: i
Accumulator variables: K, S, i
Iterator variables: i
Javascript program:
function is_prime ( n ) { if ( n <= 1 ) return false ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function countSmallerPrimes ( ar , N ) { for ( let i = 0 ; i < N ; i ++ ) { let count = 0 ; for ( let j = i + 1 ; j < N ; j ++ ) { if ( ar [ j ] <= ar [ i ] && is_prime ( ar [ j ] ) ) { count ++ ; } } document . write ( count + " " ) ; } } let ar = [ 43 , 3 , 5 , 7 , 2 , 41 ] ; let N = ar . length ; countSmallerPrimes ( ar , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function checkConcat ( str1 , str2 ) { let N = str1 . length ; let M = str2 . length ; if ( N % M != 0 ) { return false ; } for ( let i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] != str2 [ i % M ] ) { return false ; } } return true ; } let str1 = " " ; let str2 = " " ; if ( checkConcat ( str1 , str2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function MinLen ( str , K ) { var N = str . length ; var i = 0 ; while ( i < N - 1 ) { if ( str . charAt ( i ) != str . charAt ( i + 1 ) ) { break ; } i ++ ; } if ( i == N - 1 ) { return N ; } return Math . max ( 1 , N - K ) ; } var str = " " ; var K = 1 ; document . write ( MinLen ( str , K ) ) ;

Accumulator variables: i
Javascript program:
var M = new Map ( ) ; class node { constructor ( data , left , right ) { this . data = data ; this . left = left ; this . right = right ; } } ; function newnode ( d ) { var temp = new node ( d , null , null ) ; return temp ; } function dfs ( root , l ) { if ( root == null ) return ; if ( ! M . has ( l ) ) { var temp = [ ] ; temp . push ( root . data ) ; M . set ( l , temp ) ; } else { var temp = M . get ( l ) ; temp . push ( root . data ) ; M . set ( l , temp ) ; } dfs ( root . left , l + 1 ) ; dfs ( root . right , l + 1 ) ; } function printMidNodes ( root ) { M = new Map ( ) ; dfs ( root , 0 ) ; M . forEach ( ( value , key ) => { var size = value . length ; if ( size % 2 == 1 ) { document . write ( value [ parseInt ( ( size - 1 ) / 2 ) ] + " " ) ; } else { document . write ( value [ parseInt ( ( size - 1 ) / 2 ) ] + " " + value [ parseInt ( ( ( size - 1 ) / 2 ) + 1 ) ] + " " ) ; } } ) ; } var root = newnode ( 1 ) ; root . left = newnode ( 2 ) ; root . right = newnode ( 3 ) ; root . left . left = newnode ( 4 ) ; root . left . right = newnode ( 5 ) ; root . left . right . left = newnode ( 11 ) ; root . left . right . right = newnode ( 6 ) ; root . left . right . right . left = newnode ( 7 ) ; root . left . right . right . right = newnode ( 9 ) ; root . right . left = newnode ( 10 ) ; root . right . right = newnode ( 8 ) ; printMidNodes ( root ) ;

Class/struct names: node
Javascript program:
function minLength ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return 1 ; } } return N ; } let arr = [ 2 , 1 , 3 , 1 ] ; let N = arr . length ; document . write ( minLength ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function PrintIndexes ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let currSubSum = 0 ; for ( let j = i ; j < N ; j ++ ) { currSubSum += arr [ j ] ; let sq = Math . floor ( Math . sqrt ( currSubSum ) ) ; if ( sq * sq == currSubSum ) { document . write ( " " + i + " " + j + " " + " " ) ; } } } } let arr = [ 65 , 79 , 81 ] ; PrintIndexes ( arr , arr . length ) ;

Index/key variables: j
Accumulator variables: currSubSum, i, j
Iterator variables: i, j
Javascript program:
function countPosition ( mat ) { var n = mat . length ; var m = mat [ 0 ] . length ; var row = Array . from ( { length : n } , ( _ , i ) => 0 ) ; var col = Array . from ( { length : m } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { col [ j ] ++ ; row [ i ] ++ ; } } } var count = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( row [ i ] == col [ j ] ) { count ++ ; } } } return count ; } var mat = [ [ 0 , 1 ] , [ 1 , 1 ] ] ; document . write ( countPosition ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function maxAtLevel ( N , M , Value , Edges ) { let adj = new Array ( N ) ; for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; for ( let i = 0 ; i < M ; i ++ ) { let u = Edges [ i ] [ 0 ] ; let v = Edges [ i ] [ 1 ] ; adj [ u ] . push ( v ) ; } let q = [ ] ; q . push ( 0 ) ; while ( q . length > 0 ) { let count = q . length ; let maxVal = 0 ; while ( count -- > 0 ) { let temp = q [ 0 ] ; q . shift ( ) ; maxVal = Math . max ( maxVal , Value [ temp ] ) ; for ( let i = 0 ; i < adj [ temp ] . length ; i ++ ) { q . push ( adj [ temp ] [ i ] ) ; } } document . write ( maxVal + " " ) ; } } let N = 10 ; let Edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 0 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 3 , 6 ] , [ 6 , 7 ] , [ 6 , 8 ] , [ 6 , 9 ] ] ; let Value = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 ] ; maxAtLevel ( N , N - 1 , Value , Edges ) ;

Index/key variables: i, temp, u
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function ctTriplets ( arr , N ) { arr . sort ( ) ; let temp = [ ] ; let index = 0 ; for ( let i = 1 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } for ( let i = 0 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } let ct = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i > 0 && i + 1 < N ) { if ( temp [ i ] < temp [ i + 1 ] && temp [ i ] < temp [ i - 1 ] ) { ct ++ ; } } } document . write ( " " + ct + " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( temp [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let N = arr . length ; ctTriplets ( arr , N ) ;

Index/key variables: i
Accumulator variables: ct, i, index
Iterator variables: i
Javascript program:
function check ( a , n ) { let b = new Array ( n ) . fill ( 0 ) ; let minElement = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { b [ i ] = a [ i ] ; minElement = Math . min ( minElement , a [ i ] ) ; } b . sort ( ) ; let k = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] && a [ i ] % minElement != 0 ) { k = 0 ; break ; } } return k == 1 ? true : false ; } let a = [ 4 , 3 , 6 , 6 , 2 , 9 ] ; let n = a . length ; if ( check ( a , n ) == true ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function numSpecial ( mat ) { var m = mat . length ; var n = mat [ 0 ] . length ; var rows = Array . from ( { length : m } , ( _ , i ) => 0 ) ; var cols = Array . from ( { length : n } , ( _ , i ) => 0 ) ; var i , j ; for ( i = 0 ; i < m ; i ++ ) { rows [ i ] = 0 ; for ( j = 0 ; j < n ; j ++ ) rows [ i ] += mat [ i ] [ j ] ; } for ( i = 0 ; i < n ; i ++ ) { cols [ i ] = 0 ; for ( j = 0 ; j < m ; j ++ ) cols [ i ] += mat [ j ] [ i ] ; } var cnt = 0 ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 1 && rows [ i ] == 1 && cols [ j ] == 1 ) cnt ++ ; } } return cnt ; } var mat = [ [ 1 , 0 , 0 ] , [ 0 , 0 , 1 ] , [ 0 , 0 , 0 ] ] ; document . write ( numSpecial ( mat ) + " " ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function minmaxNumbers ( matrix , res ) { var set = new Set ( ) ; for ( var i = 0 ; i < matrix . length ; i ++ ) { var minr = 1000000000 ; for ( var j = 0 ; j < matrix [ i ] . length ; j ++ ) { minr = Math . min ( minr , matrix [ i ] [ j ] ) ; } set . add ( minr ) ; } for ( var j = 0 ; j < matrix [ 0 ] . length ; j ++ ) { var maxc = - 1000000000 ; for ( var i = 0 ; i < matrix . length ; i ++ ) { maxc = Math . max ( maxc , matrix [ i ] [ j ] ) ; } if ( set . has ( maxc ) ) { res . push ( maxc ) ; } } return res ; } var mat = [ [ 1 , 10 , 4 ] , [ 9 , 3 , 8 ] , [ 15 , 16 , 17 ] ] ; var ans = [ ] ; minmaxNumbers ( mat , ans ) ; if ( ans . length == 0 ) document . write ( " " ) ; for ( var i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var mini = 105 , ans , n ; var g = Array . from ( Array ( 100 ) , ( ) => new Array ( ) ) ; var size = Array ( 100 ) . fill ( 0 ) ; function create_graph ( ) { g [ 1 ] . push ( 2 ) ; g [ 2 ] . push ( 1 ) ; g [ 1 ] . push ( 3 ) ; g [ 3 ] . push ( 1 ) ; g [ 1 ] . push ( 4 ) ; g [ 4 ] . push ( 1 ) ; g [ 2 ] . push ( 5 ) ; g [ 5 ] . push ( 2 ) ; g [ 2 ] . push ( 6 ) ; g [ 6 ] . push ( 2 ) ; } function dfs ( node , parent ) { size [ node ] = 1 ; var mx = 0 ; g [ node ] . forEach ( y => { if ( y != parent ) { dfs ( y , node ) ; size [ node ] += size [ y ] ; mx = Math . max ( mx , size [ y ] ) ; } } ) ; mx = Math . max ( mx , n - size [ node ] ) ; if ( mx < mini ) { mini = mx ; ans = node ; } } n = 6 ; create_graph ( ) ; dfs ( 1 , - 1 ) ; document . write ( ans ) ;

Index/key variables: node, y
Javascript program:
function minOperation ( s ) { var n = s . length ; var temp1 = - 1 , temp2 = - 1 ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var curr = s [ i ] ; if ( curr == ' ' ) { if ( temp1 == - 1 && temp2 == - 1 ) { temp1 = i ; } else if ( temp1 != - 1 && temp2 == - 1 && i - temp1 == 1 ) { temp2 = i ; } else if ( temp1 != - 1 ) { temp1 = - 1 ; ans ++ ; } else if ( temp1 == - 1 && temp2 != - 1 && i - temp2 != 1 ) { temp2 = - 1 ; ans ++ ; } } } if ( temp1 != - 1 && temp2 != - 1 ) { ans += 2 ; } else if ( temp1 != - 1 temp2 != - 1 ) { ans += 1 ; } return ans ; } var s = " " ; document . write ( minOperation ( s ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findMinLength ( arr ) { let index = parseInt ( arr . length ) - 1 ; while ( index > 0 && arr [ index ] >= arr [ index - 1 ] ) { index -- ; } return index ; } let arr = [ 7 , 8 , 5 , 0 , - 1 , - 1 , 0 , 1 , 2 , 3 , 4 ] ; let n = arr . length ; document . write ( findMinLength ( arr ) ) ;

Index/key variables: index
Accumulator variables: index