dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function checkExists ( arr , N , M , K ) { let count = 0 ; for ( let i = 0 ; i < N - M ; i ++ ) { if ( arr [ i ] == arr [ i + M ] ) count ++ ; else count = 0 ; if ( count == M * ( K - 1 ) ) return true ; } return false ; } let arr = [ 2 , 1 , 2 , 1 , 1 , 1 , 3 ] ; let N = arr . length ; let M = 2 , K = 2 ; if ( checkExists ( arr , N , M , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function CommonDigits ( N , M ) { var count = 0 ; var freq1 = Array ( 10 ) . fill ( 0 ) ; var freq2 = Array ( 10 ) . fill ( 0 ) ; while ( N > 0 ) { freq1 [ N % 10 ] ++ ; N = Math . floor ( N / 10 ) ; } while ( M > 0 ) { freq2 [ M % 10 ] ++ ; M = Math . floor ( M / 10 ) ; } var i ; for ( i = 0 ; i < 10 ; i ++ ) { if ( freq1 [ i ] > 0 & freq2 [ i ] > 0 ) { count ++ ; } } return count ; } var N = 748294 ; var M = 34298156 ; document . write ( CommonDigits ( N , M ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minimumNumber ( K , X ) { if ( K > X ) { document . write ( " " ) ; return ; } let ans = 0 ; let sum = 0 ; for ( let i = K ; i <= X ; i ++ ) { sum += i ; if ( sum >= X ) { ans = i ; break ; } } document . write ( ans ) ; } let K = 5 , X = 13 ; minimumNumber ( K , X ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function CountPairs ( arr , n ) { var count = 0 ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( ( i * j ) == ( arr [ i ] * arr [ j ] ) ) count ++ ; } } return count ; } var arr = [ 1 , 0 , 3 , 2 , 6 ] ; var N = arr . length ; document . write ( CountPairs ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
var distance = 0 ; function dfs ( src , Adj , visited , level ) { visited [ src ] = true ; distance = Math . max ( distance , level ) ; for ( var child of Adj [ src ] ) { if ( ( child != src ) && ( visited [ child ] == false ) ) { dfs ( child , Adj , visited , level + 1 ) ; } } visited [ src ] = false ; } function maximumLength ( mat , v ) { distance = 0 ; var N = mat [ 0 ] . length ; var visited = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { visited . push ( false ) ; } var Adj = Array . from ( Array ( N ) , ( ) => Array ( ) ) ; var i , j ; for ( i = 0 ; i < mat [ 0 ] . length ; i ++ ) { for ( j = 0 ; j < mat . length ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { Adj [ i ] . push ( j ) ; } } } dfs ( v , Adj , visited , 0 ) ; return distance ; } var mat = [ [ 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] ] ; var v = 2 ; document . write ( maximumLength ( mat , v ) ) ;

Index/key variables: child, i, j, src
Accumulator variables: i, j
Iterator variables: child, i, j
Javascript program:
function findLength ( s , i , j ) { var required = i ; let length = 0 ; for ( let k = 0 ; k < s . length ; k ++ ) { var curr = s . charAt ( k ) ; if ( curr == required ) { length += 1 ; if ( required == i ) required = j ; else required = i ; } } return length ; } function minimumDeletions ( S ) { let len = 0 ; let n = S . length ; for ( let i = 0 ; i < 26 ; i ++ ) { for ( let j = i + 1 ; j < 26 ; j ++ ) { let newLen = findLength ( S , String . fromCharCode ( i + 97 ) , String . fromCharCode ( j + 97 ) ) ; len = Math . max ( len , newLen ) ; } } return n - len ; } let S = " " ; document . write ( minimumDeletions ( S ) ) ;

Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function inv ( a , m ) { var m0 = m , t , q ; var x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = parseInt ( a / m ) ; t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } function findMinX ( A , B , N ) { var prod = 1 ; for ( var i = 0 ; i < N ; i ++ ) prod *= A [ i ] ; var result = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var pp = parseInt ( prod / A [ i ] ) ; result += B [ i ] * inv ( pp , A [ i ] ) * pp ; } return result % prod ; } function product ( a , n ) { var ans = 1 ; for ( var i = 0 ; i < n ; i ++ ) { ans *= a [ i ] ; } return ans ; } function findSmallestInteger ( A , B , P , n ) { var Y = findMinX ( A , B , n ) ; var M = product ( A , n ) ; var K = Math . ceil ( ( P - Y ) / M ) ; var X = Y + K * M ; document . write ( X ) ; } var A = [ 3 , 4 , 5 ] ; var B = [ 2 , 3 , 1 ] ; var n = A . length ; var P = 72 ; findSmallestInteger ( A , B , P , n ) ;

Index/key variables: i
Accumulator variables: ans, i, prod, result, x1
Iterator variables: i
Javascript program:
function numberOfGates ( s ) { let N = s . length ; let ans = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { ans ++ ; } } document . write ( ans ) ; } let S = " " ; numberOfGates ( S ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findPairs ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) arr [ i ] = Math . abs ( arr [ i ] ) ; arr . sort ( ( a , b ) => a - b ) ; let left = 0 ; let ans = 0 ; for ( let right = 0 ; right < N ; right ++ ) { while ( 2 * arr [ left ] < arr [ right ] ) left ++ ; ans += ( right - left ) ; } document . write ( ans ) ; } let arr = [ 1 , 3 , 5 , 7 ] ; let N = arr . length ; findPairs ( arr , N ) ;

Index/key variables: i, left, right
Accumulator variables: ans, i, left, right
Iterator variables: i, right
Javascript program:
function GetDiff ( A , N ) { let SuffMaxArr = Array ( N ) . fill ( 0 ) ; SuffMaxArr [ N - 1 ] = A [ N - 1 ] ; for ( let i = N - 2 ; i >= 0 ; -- i ) { SuffMaxArr [ i ] = Math . max ( SuffMaxArr [ i + 1 ] , A [ i + 1 ] ) ; } let MaximumSum = Number . MIN_VALUE ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] < SuffMaxArr [ i ] ) MaximumSum = Math . max ( MaximumSum , A [ i ] + SuffMaxArr [ i ] ) ; } let MinimumSum = Number . MAX_VALUE ; let SuffMinArr = Array ( N ) . fill ( 0 ) ; SuffMinArr [ N - 1 ] = Number . MAX_VALUE ; for ( let i = N - 2 ; i >= 0 ; -- i ) { SuffMinArr [ i ] = Math . min ( SuffMinArr [ i + 1 ] , A [ i + 1 ] ) ; } for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] < SuffMinArr [ i ] ) { MinimumSum = Math . min ( MinimumSum , A [ i ] + SuffMinArr [ i ] ) ; } } return Math . abs ( MaximumSum - MinimumSum ) ; } let arr = [ 2 , 4 , 1 , 3 , 7 , 5 , 6 ] ; let N = arr . length ; document . write ( GetDiff ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumSwaps ( arr , N ) { let even = 0 , odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != i % 2 ) { if ( i % 2 == 0 ) { even ++ ; } else { odd ++ ; } } } if ( even != odd ) { document . write ( - 1 ) ; } else { document . write ( even ) ; } } let arr = [ 3 , 2 , 7 , 6 ] ; let N = arr . length ; minimumSwaps ( arr , N ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function smallestSubstring ( a ) { let a1 = [ ] ; for ( let i = 0 ; i < a . length ; i ++ ) { for ( let j = i + 1 ; j <= a . length ; j ++ ) { if ( i != j ) a1 . push ( a . substring ( i , j ) ) ; } } let a2 = new Map ( ) ; for ( let s = 0 ; s < a1 . length ; s ++ ) { if ( a2 . has ( a1 [ s ] ) ) a2 . set ( a1 [ s ] , a2 . get ( a1 [ s ] ) + 1 ) ; else a2 . set ( a1 [ s ] , 1 ) ; } let freshlist = [ ] ; for ( let s of a2 . keys ( ) ) { if ( a2 . get ( s ) == 1 ) freshlist . push ( s ) ; } let dictionary = new Map ( ) ; for ( let s = 0 ; s < freshlist . length ; s ++ ) { dictionary . set ( freshlist [ s ] , freshlist [ s ] . length ) ; } let newlist = [ ] ; for ( let s of dictionary . keys ( ) ) newlist . push ( dictionary . get ( s ) ) ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < newlist . length ; i ++ ) ans = Math . min ( ans , newlist [ i ] ) ; return ans == Number . MAX_VALUE ? 0 : ans ; } let S = " " ; document . write ( smallestSubstring ( S ) ) ;

Index/key variables: i, s
Accumulator variables: i, j, s
Iterator variables: i, j, s
Javascript program:
function mininsert ( arr , K , N ) { var ans = 0 ; for ( i = 0 ; i < N - 1 ; i ++ ) { var a = Math . min ( arr [ i ] , arr [ i + 1 ] ) ; var b = Math . max ( arr [ i ] , arr [ i + 1 ] ) ; while ( K * a < b ) { a *= K ; ans ++ ; } } return ans ; } var arr = [ 2 , 10 , 25 , 21 ] ; var K = 2 ; var N = arr . length ; document . write ( mininsert ( arr , K , N ) ) ;

Index/key variables: i
Accumulator variables: a, ans, i
Iterator variables: i
Javascript program:
function sumOfDigits ( s ) { var curr = 0 ; var ret = 0 ; s . split ( ' ' ) . forEach ( ch => { if ( parseInt ( ch ) ) { curr = curr * 10 + ch . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } else { ret += curr ; curr = 0 ; } } ) ; ret += curr ; return ret ; } var S = " " ; document . write ( sumOfDigits ( S ) ) ;

Accumulator variables: ret
Javascript program:
function print_triplet ( arr , n ) { for ( var i = 1 ; i <= n - 2 ; i ++ ) { if ( arr [ i - 1 ] < arr [ i ] && arr [ i ] > arr [ i + 1 ] ) { document . write ( i - 1 + " " + i + " " + ( i + 1 ) ) ; return ; } } document . write ( - 1 ) ; } var arr = [ 4 , 3 , 5 , 2 , 1 , 6 ] ; var N = arr . length ; print_triplet ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findConcatenatedNumbers ( a , b ) { var ans = true ; var n1 = a . length ; var n2 = b . length ; var cnt = new Map ( ) ; for ( var i = 0 ; i < n1 ; i ++ ) { cnt . set ( a [ i ] , 1 ) ; } for ( var i = 0 ; i < n2 ; i ++ ) { var left = b [ i ] ; var right = 0 ; var mul = 1 ; while ( left > 9 ) { right += ( left % 10 ) * mul ; left = parseInt ( left / 10 ) ; mul *= 10 ; if ( cnt . has ( left ) && cnt . has ( right ) ) { ans = false ; document . write ( b [ i ] + " " ) ; } } } if ( ans ) document . write ( " " ) ; } var a = [ 2 , 34 , 4 , 5 ] ; var b = [ 26 , 24 , 345 , 4 , 22 ] ; findConcatenatedNumbers ( a , b ) ;

Index/key variables: i
Accumulator variables: i, mul, right
Iterator variables: i
Boolean variables: ans
Javascript program:
function evenproduct ( arr , length ) { var count = 0 ; var i , j ; for ( i = 0 ; i < length + 1 ; i ++ ) { var product = 1 ; for ( j = i ; j < length + 1 ; j ++ ) { product *= arr [ j ] ; if ( product % 2 == 0 ) ++ count ; } } document . write ( count ) ; } var arr = [ 7 , 5 , 4 , 9 ] ; var length = arr . length ; evenproduct ( arr , length ) ;

Index/key variables: j
Accumulator variables: i, j, product
Iterator variables: i, j
Javascript program:
var ans = 0 ; var adj = Array . from ( Array ( 100001 ) , ( ) => Array ( ) ) ; function dfsUtil ( u , par , depth ) { adj [ u ] . forEach ( it => { if ( it != par ) { dfsUtil ( it , u , depth + 1 ) ; } } ) ; ans += depth ; } function dfs ( u , par , depth ) { dfsUtil ( u , par , depth ) ; document . write ( ans + " " ) ; } function countPairs ( edges ) { for ( var i = 0 ; i < edges . length ; i ++ ) { var u = edges [ i ] [ 0 ] ; var v = edges [ i ] [ 1 ] ; adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } dfs ( 1 , 1 , 1 ) ; } var edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 2 , 4 ] ] ; countPairs ( edges ) ;

Index/key variables: i, u, v
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
class TreeNode { constructor ( ) { this . val = 0 ; this . left = null ; this . right = null ; } } ; function newNode ( key ) { var temp = new TreeNode ( ) ; temp . val = key ; temp . left = temp . right = null ; return temp ; } function convertBinaryToDecimal ( arr ) { var ans = 0 ; for ( var i of arr ) ans = ( ans << 1 ) | i ; return ans ; } function decimalEquilvalentAtEachLevel ( root ) { var ans = 0 ; var que = [ ] ; que . push ( root ) ; while ( true ) { var length = que . length ; if ( length == 0 ) break ; var eachLvl = [ ] ; while ( length > 0 ) { var temp = que [ 0 ] ; que . shift ( ) ; eachLvl . push ( temp . val ) ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; length -= 1 ; } ans += convertBinaryToDecimal ( eachLvl ) ; } document . write ( ans ) ; } var root = newNode ( 0 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 0 ) ; root . left . left = newNode ( 0 ) ; root . left . right = newNode ( 1 ) ; root . right . left = newNode ( 1 ) ; root . right . right = newNode ( 1 ) ; decimalEquilvalentAtEachLevel ( root ) ;

Accumulator variables: ans
Iterator variables: i
Class/struct names: TreeNode
Javascript program:
function minimumOperations ( arr , N ) { let oddCnt = 0 , evenCnt = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { evenCnt ++ ; } else { oddCnt ++ ; } } document . write ( Math . min ( oddCnt , evenCnt ) ) ; } let arr = [ 4 , 1 , 2 ] ; let N = arr . length ; minimumOperations ( arr , N ) ;

Index/key variables: i
Accumulator variables: evenCnt, i, oddCnt
Iterator variables: i
Javascript program:
function minIncr ( arr , n ) { let forEven = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 ) { if ( ( arr [ i ] % 2 ) == 0 ) forEven += 1 ; } else { if ( arr [ i ] % 2 ) forEven += 1 ; } } return Math . min ( forEven , n - forEven ) ; } let arr = [ 1 , 4 , 6 , 8 , 9 , 5 ] ; let n = arr . length ; document . write ( minIncr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: forEven, i
Iterator variables: i
Javascript program:
function minOperations ( arr , N , Q , M ) { var m1 = new Map ( ) ; var m2 = new Map ( ) ; var front = 0 , rear = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { front += arr [ i ] ; m1 . set ( arr [ i ] , front ) ; } for ( i = N - 1 ; i >= 0 ; i -- ) { rear += arr [ i ] ; m2 . set ( arr [ i ] , rear ) ; } for ( i = 0 ; i < M ; i ++ ) { document . write ( Math . min ( m1 . get ( Q [ i ] ) , m2 . get ( Q [ i ] ) ) + " " ) ; } } var arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 1 ] ; var N = arr . length ; var Q = [ 7 , 6 ] ; var M = Q . length ; minOperations ( arr , N , Q , M ) ;

Index/key variables: i
Accumulator variables: front, i, rear
Iterator variables: i
Javascript program:
function checkAnagram ( s1 , s2 ) { var s2hash = Array ( 26 ) . fill ( 0 ) ; var s1hash = Array ( 26 ) . fill ( 0 ) ; var s1len = s1 . length ; var s2len = s2 . length ; if ( s1len > s2len ) return false ; var left = 0 , right = 0 ; while ( right < s1len ) { s1hash [ s1 [ right ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; s2hash [ s2 [ right ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; right ++ ; } right -= 1 ; while ( right < s2len ) { var ans = true ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( s1hash [ i ] != s2hash [ i ] ) { ans = false ; } } if ( ans ) return true ; right ++ ; if ( right != s2len ) s2hash [ s2 [ right ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; s2hash [ s2 [ left ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -= 1 ; left ++ ; } return false ; } var s1 = " " ; var s2 = " " ; if ( checkAnagram ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, left, right
Accumulator variables: i, left, right
Iterator variables: i
Boolean variables: ans
Javascript program:
function canPlace ( s , n , k ) { var cnt = 0 ; var i = 0 ; while ( i < n ) { if ( s . charAt ( i ) == ' ' ) { i += 2 ; } else { if ( i == 0 ) { if ( s . charAt ( i + 1 ) == ' ' ) { cnt ++ ; i += 2 ; } else i ++ ; } else if ( i == n - 1 ) { if ( s . charAt ( i - 1 ) == ' ' ) { cnt ++ ; i += 2 ; } else i ++ ; } else { if ( s . charAt ( i + 1 ) == ' ' && s . charAt ( i - 1 ) == ' ' ) { cnt ++ ; i += 2 ; } else i ++ ; } } } if ( cnt >= k ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var S = " " ; var K = 1 ; var N = 5 ; canPlace ( S , N , K ) ;

Accumulator variables: cnt, i
Javascript program:
function findMaxIntervals ( v , n ) { var maxi = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var c = n ; for ( var j = 0 ; j < n ; j ++ ) { if ( v [ i ] [ 1 ] < v [ j ] [ 0 ] v [ i ] [ 0 ] > v [ j ] [ 1 ] ) { c -- ; } } maxi = Math . max ( c , maxi ) ; } document . write ( maxi ) ; } var arr = [ [ 1 , 2 ] , [ 3 , 4 ] , [ 2 , 5 ] ] ; var N = arr . length ; findMaxIntervals ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function check ( a , n ) { flag = false ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i + 1 ] > a [ i ] && a [ i ] < a [ i - 1 ] ) flag = true ; } if ( flag ) return false ; else return true ; } var arr = [ 1 , 3 , 5 , 2 ] ; var N = arr . length ; if ( check ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function smallestNumber ( arr , len ) { let maxi = 0 ; for ( let i = 0 ; i < len ; i ++ ) { maxi = Math . max ( maxi , arr [ i ] ) ; } let ans = - 1 ; for ( let i = 2 ; i < maxi + 2 ; i ++ ) { let flag = true ; for ( let j = 0 ; j < len ; j ++ ) { if ( arr [ j ] % i == 0 ) { flag = false ; break ; } } if ( flag ) { ans = i ; break ; } } document . write ( ans ) ; } let arr = [ 3 , 2 , 6 , 9 , 2 ] ; let N = arr . length ; smallestNumber ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function findDuplicate ( str , N ) { let first = 0 ; let second = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( ( first & ( 1 << ( str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ) ) != 0 ) { second = second | ( 1 << ( str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ) ; } else { first = first | ( 1 << ( str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ) ; } } for ( let i = 0 ; i < 26 ; i ++ ) { if ( ( ( first & ( 1 << i ) ) & ( second & ( 1 << i ) ) ) != 0 ) { document . write ( String . fromCharCode ( i + ' ' . charCodeAt ( ) ) + " " ) ; } } } let str = " " ; let N = str . length ; findDuplicate ( str , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( S ) { var count = 0 ; for ( var i = 1 ; i < S . length ; i ++ ) { if ( S [ i ] !== S [ i - 1 ] ) { count += 1 ; } } document . write ( count ) ; } var S = " " ; minOperations ( S ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function numberOfPairs ( arr , N ) { let set_bits = [ ] ; for ( let i = 0 ; i < 31 ; i ++ ) { set_bits [ i ] = 0 ; } let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let x = arr [ i ] ; let bitpos = - 1 ; while ( x > 0 ) { bitpos ++ ; x = Math . floor ( x / 2 ) ; } for ( let j = 0 ; j <= bitpos ; j ++ ) { count += set_bits [ j ] ; } set_bits [ bitpos ] ++ ; } document . write ( count ) ; } let arr = [ 4 , 16 , 8 , 64 ] ; let N = arr . length ; numberOfPairs ( arr , N ) ;

Index/key variables: bitpos, i, j
Accumulator variables: bitpos, count, i, j
Iterator variables: i, j
Javascript program:
function calculateQuery ( arr , N , query , M ) { for ( let i = 0 ; i < M ; i ++ ) { let X = query [ i ] ; let sum_start = 0 , sum_end = 0 ; for ( let j = 0 ; j < N ; j ++ ) { sum_start += arr [ j ] ; if ( arr [ j ] == X ) break ; } for ( let j = N - 1 ; j >= 0 ; j -- ) { sum_end += arr [ j ] ; if ( arr [ j ] == X ) break ; } document . write ( Math . min ( sum_end , sum_start ) + " " ) ; } } let arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 30 ] ; let queries = [ 6 , 5 ] ; let N = arr . length ; let M = queries . length ; calculateQuery ( arr , N , queries , M ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum_end, sum_start
Iterator variables: i, j
Javascript program:
function calculateQuery ( arr , N , query , M ) { var prefix = 0 , suffix = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { prefix += arr [ i ] ; if ( ! mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , [ 0 , 0 ] ) ; } var tmp = mp . get ( arr [ i ] ) ; tmp [ 0 ] = prefix ; mp . set ( arr [ i ] , tmp ) ; } for ( var i = N - 1 ; i >= 0 ; i -- ) { suffix += arr [ i ] ; if ( ! mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , [ 0 , 0 ] ) ; } var tmp = mp . get ( arr [ i ] ) ; tmp [ 1 ] = suffix ; mp . set ( arr [ i ] , tmp ) ; } for ( var i = 0 ; i < M ; i ++ ) { var X = query [ i ] ; var tmp = mp . get ( X ) ; document . write ( Math . min ( tmp [ 0 ] , tmp [ 1 ] ) + " " ) ; } } var arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 30 ] ; var queries = [ 6 , 5 ] ; var N = arr . length ; var M = queries . length ; calculateQuery ( arr , N , queries , M ) ;

Index/key variables: i
Accumulator variables: i, prefix, suffix
Iterator variables: i
Javascript program:
function findMaximum ( arr , N , Q , queries ) { let prefix_max = [ ] ; let suffix_max = [ ] ; prefix_max [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { prefix_max [ i ] = Math . max ( prefix_max [ i - 1 ] , arr [ i ] ) ; } suffix_max [ N - 1 ] = arr [ N - 1 ] ; for ( let i = N - 2 ; i >= 0 ; i -- ) { suffix_max [ i ] = Math . max ( suffix_max [ i + 1 ] , arr [ i ] ) ; } for ( let i = 0 ; i < Q ; i ++ ) { let l = queries [ i ] [ 0 ] ; let r = queries [ i ] [ 1 ] ; if ( l == 0 && r == ( N - 1 ) ) document . write ( " " ) ; else if ( l == 0 ) document . write ( suffix_max [ r + 1 ] + " " ) ; else if ( r == ( N - 1 ) ) document . write ( prefix_max [ l - 1 ] + " " ) ; else document . write ( Math . max ( prefix_max [ l - 1 ] , suffix_max [ r + 1 ] ) + " " ) ; } } let arr = [ 5 , 6 , 8 , 10 , 15 ] ; let N = arr . length ; let queries = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 4 ] ] ; let Q = queries . length ; findMaximum ( arr , N , Q , queries ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function oddOneOut ( arr , N ) { let odd = 0 , even = 0 ; let lastOdd = 0 , lastEven = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { even ++ ; lastEven = i ; } else { odd ++ ; lastOdd = i ; } } if ( odd == 1 ) { document . write ( lastOdd ) ; } else { document . write ( lastEven ) ; } } let arr = [ 2 , 4 , 7 , 8 , 10 ] ; let N = arr . length ; oddOneOut ( arr , N ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function minEmail ( email ) { let ans = " " ; let len = email . length ; ans += email [ 0 ] ; let i = 1 ; let notAt = true ; while ( i < len ) { if ( i < len - 3 && notAt && email [ i ] == ' ' && email [ i + 1 ] == ' ' ) { ans += ' ' ; i += 1 ; notAt = false ; } else if ( i < len - 4 && email [ i ] == ' ' && email [ i + 1 ] == ' ' && email [ i + 2 ] == ' ' ) { ans += ' ' ; i += 2 ; } else { ans += email [ i ] ; } i += 1 ; } return ans ; } let email = " " ; document . write ( minEmail ( email ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Boolean variables: notAt
Javascript program:
function isGreaterEqual ( N , X ) { return parseInt ( ( N * ( N + 1 ) ) / 2 ) >= X ; } function minimumPossible ( X ) { for ( let i = 1 ; i <= X ; i ++ ) { if ( isGreaterEqual ( i , X ) ) return i ; } } let X = 14 ; document . write ( minimumPossible ( X ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
const Max = 1000005 ; function CheckDivByAllDigits ( number ) { let n = number ; while ( n > 0 ) { if ( n % 10 ) if ( number % ( n % 10 ) ) { return false ; } n = parseInt ( n / 10 ) ; } return true ; } function cntNumInRang ( arr , N ) { let prefCntDiv = new Array ( Max ) . fill ( 0 ) ; for ( let i = 1 ; i <= Max ; i ++ ) { prefCntDiv [ i ] = prefCntDiv [ i - 1 ] + ( CheckDivByAllDigits ( i ) ) ; } for ( let i = 0 ; i < N ; i ++ ) document . write ( ( prefCntDiv [ arr [ i ] [ 1 ] ] - prefCntDiv [ arr [ i ] [ 0 ] - 1 ] ) + " " ) ; } let arr = [ [ 1 , 5 ] , [ 12 , 14 ] ] ; let N = arr . length ; cntNumInRang ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function arrayNesting ( arr ) { let res = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == i ) { res = Math . max ( res , 1 ) ; } else { let count = 0 ; let curr_index = i ; while ( arr [ curr_index ] != curr_index ) { let next_index = arr [ curr_index ] ; arr [ curr_index ] = curr_index ; curr_index = next_index ; count ++ ; } res = Math . max ( res , count ) ; } } return res ; } let arr = [ 5 , 4 , 0 , 3 , 1 , 6 , 2 ] ; let res = arrayNesting ( arr ) ; document . write ( res ) ;

Index/key variables: curr_index, i
Accumulator variables: count, i
Iterator variables: i