dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countPrecedingK ( a , n , K ) { let prefix = new Array ( n ) . fill ( 0 ) ; prefix [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; } let ctr = 0 ; if ( prefix [ K - 1 ] < a [ K ] ) ctr ++ ; for ( let i = K + 1 ; i < n ; i ++ ) { if ( prefix [ i - 1 ] - prefix [ i - K - 1 ] < a [ i ] ) ctr ++ ; } return ctr ; } let arr = [ 2 , 3 , 8 , 10 , - 2 , 7 , 5 , 5 , 9 , 15 ] ; let N = arr . length ; let K = 2 ; document . write ( countPrecedingK ( arr , N , K ) ) ;

Index/key variables: K, i
Accumulator variables: ctr, i
Iterator variables: i
Javascript program:
function convertBfromA ( a , b ) { let moves = 0 ; let x = Math . abs ( a - b ) ; for ( let i = 10 ; i > 0 ; i -- ) { moves += Math . floor ( x / i ) ; x = x % i ; } document . write ( moves + " " ) ; } let A = 188 , B = 4 ; convertBfromA ( A , B ) ;

Accumulator variables: i, moves
Iterator variables: i
Javascript program:
var M = 1000 ; function countNum ( N , sum , K , st , dp ) { if ( N == 0 && sum == 0 ) { return 1 ; } if ( N < 0 ) { return 0 ; } if ( dp [ N ] [ sum ] [ st ] != - 1 ) { return dp [ N ] [ sum ] [ st ] ; } var res = 0 ; var start = st == 1 ? 0 : 1 ; for ( var i = start ; i <= 9 ; i ++ ) { res += countNum ( N - 1 , ( sum + i ) % K , K , ( st i > 0 ) , dp ) ; } return dp [ N ] [ sum ] [ st ] = res ; } var N = 2 , K = 7 ; var dp = Array . from ( Array ( M ) , ( ) => Array ( M ) ) ; for ( var i = 0 ; i < M ; i ++ ) for ( var j = 0 ; j < M ; j ++ ) dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; document . write ( countNum ( N , 0 , K , 0 , dp ) ) ;

Index/key variables: N, i, j, st, sum
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function smallestNth ( A , B , N ) { let res = Number . MAX_VALUE ; for ( let i = 1 ; i < N ; i ++ ) { for ( let j = N ; j > i ; j -- ) { if ( ( B - A ) % ( j - i ) == 0 ) { let D = ( B - A ) / ( j - i ) ; let FirstTerm = A - ( i - 1 ) * D ; let NthTerm = FirstTerm + ( N - 1 ) * D ; if ( FirstTerm > 0 ) res = Math . min ( res , NthTerm ) ; } } } return res ; } let N = 3 ; let A = 1 ; let B = 6 ; document . write ( smallestNth ( A , B , N ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sieve ( prime ) { for ( var i = 0 ; i < 1000000 ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( var i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] ) { for ( var j = i * i ; j <= 1000000 ; j += i ) { prime [ j ] = false ; } } } } function subPrimeSum ( N , K , arr , prime ) { var currSum = 0 ; for ( var i = 0 ; i < K ; i ++ ) { currSum += arr [ i ] ; } if ( prime [ currSum ] ) { for ( var i = 0 ; i < K ; i ++ ) { document . write ( arr [ i ] + " " ) ; } return ; } var st = 1 , en = K ; while ( en < N ) { currSum += arr [ en ] - arr [ st - 1 ] ; if ( prime [ currSum ] ) { for ( var i = st ; i <= en ; i ++ ) { document . write ( arr [ i ] + " " ) ; } return ; } en ++ ; st ++ ; } } var arr = [ 20 , 7 , 5 , 4 , 3 , 11 , 99 , 87 , 23 , 45 ] var K = 4 ; var N = arr . length ; prime = Array ( 1000000 ) . fill ( 0 ) ; sieve ( prime ) ; subPrimeSum ( N , K , arr , prime ) ;

Index/key variables: currSum, en, i, j
Accumulator variables: currSum, en, i, j, st
Iterator variables: i, j
Javascript program:
function minDeletion ( str ) { let n = str . length ; let firstIdx1 = - 1 ; let lastIdx0 = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { firstIdx1 = i ; break ; } } for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) { lastIdx0 = i ; break ; } } if ( firstIdx1 == - 1 lastIdx0 == - 1 ) return 0 ; let count1 = 0 , count0 = 0 ; for ( let i = 0 ; i < lastIdx0 ; i ++ ) { if ( str [ i ] == ' ' ) { count1 ++ ; } } for ( let i = firstIdx1 + 1 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { count0 ++ ; } } return Math . min ( count0 , count1 ) ; } let str = " " ; document . write ( minDeletion ( str ) ) ;

Index/key variables: i
Accumulator variables: count0, count1, i
Iterator variables: i
Javascript program:
function maximumSum ( a , b , n , index , lastpicked ) { if ( index == n ) return 0 ; let option1 = 0 , option2 = 0 ; if ( lastpicked == - 1 a [ lastpicked ] != a [ index ] ) option1 = b [ index ] + maximumSum ( a , b , n , index + 1 , index ) ; option2 = maximumSum ( a , b , n , index + 1 , lastpicked ) ; return Math . max ( option1 , option2 ) ; } let arr = [ 1 , 2 , 3 , 3 , 3 , 1 ] ; let brr = [ - 1 , 2 , 10 , 20 , - 10 , - 9 ] ; let N = arr . length ; document . write ( maximumSum ( arr , brr , N , 0 , - 1 ) ) ;

Index/key variables: index, lastpicked
Javascript program:
function sumOfKElements ( arr , n , k ) { let rev = false ; if ( k < 0 ) { rev = true ; k *= - 1 ; let l = 0 , r = n - 1 ; while ( l < r ) { let tmp = arr [ l ] ; arr [ l ] = arr [ r ] ; arr [ r ] = tmp ; l ++ ; r -- ; } } let dp = new Uint8Array ( n ) ; dp [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { dp [ i ] += dp [ i - 1 ] + arr [ i ] ; } let ans = new Uint8Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i + k < n ) ans [ i ] = dp [ i + k ] - dp [ i ] ; else { let x = k - ( n - 1 - i ) ; let y = Math . floor ( x / n ) ; let rem = x % n ; ans [ i ] = dp [ n - 1 ] - dp [ i ] + y * dp [ n - 1 ] + ( rem - 1 >= 0 ? dp [ rem - 1 ] : 0 ) ; } } if ( rev ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { document . write ( ans [ i ] + " " ) ; } } else { for ( let i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } } let arr = [ 4 , 2 , - 5 , 11 ] ; let N = arr . length ; let K = 3 ; sumOfKElements ( arr , N , K ) ;

Index/key variables: i, l, r
Accumulator variables: i, k, l, r
Iterator variables: i
Boolean variables: rev
Javascript program:
let limit = 1000000000 ; function F ( N ) { let str = ( N ) . toString ( ) ; let sum = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { let val = ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; sum += val * val * val ; } return sum ; } function findDestination ( N ) { let s = new Set ( ) ; let prev = N , next = 0 ; s . add ( N ) ; while ( N <= limit ) { next = F ( N ) ; if ( s . has ( next ) ) { return next ; } prev = next ; s . add ( prev ) ; N = next ; } return next ; } function digitCubeLimit ( N ) { if ( N < 0 ) document . write ( " " ) ; else { let ans = findDestination ( N ) ; if ( ans > limit ) document . write ( " " ) ; else if ( ans == F ( ans ) ) { document . write ( N ) ; document . write ( " " + " " ) ; document . write ( ans ) ; } else { document . write ( N ) ; document . write ( " " + " " ) ; document . write ( ans ) ; } } } let N = 3 ; digitCubeLimit ( N ) ;

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

Index/key variables: j, l
Accumulator variables: ans, j, l, val
Iterator variables: j, l
Javascript program:
function minOperation ( arr ) { let minOp = Number . MIN_VALUE ; let minNeg = 0 , maxPos = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] < 0 ) { if ( arr [ i ] < minNeg ) minNeg = arr [ i ] ; } else { if ( arr [ i ] > maxPos ) maxPos = arr [ i ] ; } } return Math . abs ( minNeg ) + maxPos ; } let arr = [ 1 , 3 , 4 , 1 ] ; document . write ( minOperation ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) { return a ; } return GCD ( b , a % b ) ; } function GcdPair ( arr , k ) { var lo = 0 , hi = arr . length - 1 , mid ; var ans = [ - 1 , 0 ] ; while ( lo <= hi ) { mid = lo + parseInt ( ( hi - lo ) / 2 ) ; if ( GCD ( arr [ mid ] [ 0 ] , arr [ mid ] [ 1 ] ) > k ) { ans = arr [ mid ] ; hi = mid - 1 ; } else lo = mid + 1 ; } if ( ans [ 0 ] == - 1 ) document . write ( " " ) ; else document . write ( " " + ans [ 0 ] + " " + ans [ 1 ] + " " ) ; return ; } var arr = [ [ 3 , 6 ] , [ 15 , 30 ] , [ 25 , 75 ] , [ 30 , 120 ] ] ; var K = 16 ; GcdPair ( arr , K ) ;

Index/key variables: mid
Javascript program:
function isPossible ( arr , N ) { let mn = Number . MAX_VALUE ; let B = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { mn = Math . min ( mn , arr [ i ] ) ; B [ i ] = arr [ i ] ; } arr . sort ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != B [ i ] ) { if ( B [ i ] % mn != 0 ) { document . write ( " " ) ; return ; } } } document . write ( " " ) ; return ; } let N = 6 ; let arr = [ 4 , 3 , 6 , 6 , 2 , 9 ] ; isPossible ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function addEdge ( adj , u , v ) { ( adj [ u ] ) . push ( v ) ; ( adj [ v ] ) . push ( u ) ; } function DFSUtil ( u , adj , visited , componentMin , componentMax ) { visited [ u ] = true ; componentMax = Math . max ( componentMax , u ) ; componentMin = Math . min ( componentMin , u ) ; for ( var i = 0 ; i < ( adj [ u ] ) . length ; i ++ ) if ( visited [ ( adj [ u ] ) [ i ] ] == false ) DFSUtil ( ( adj [ u ] ) [ i ] , adj , visited , componentMin , componentMax ) ; } function isValid ( v ) { var MAX = - 1 ; var ans = false ; for ( var i of v ) { if ( i . first <= MAX ) { ans = true ; } MAX = Math . max ( MAX , i . second ) ; } return ( ans == false ? true : false ) ; } function DFS ( adj , V ) { var v = [ ] ; var visited = Array ( V + 1 ) . fill ( false ) ; for ( var u = 1 ; u <= V ; u ++ ) { if ( visited [ u ] == false ) { var componentMax = u ; var componentMin = u ; DFSUtil ( u , adj , visited , componentMin , componentMax ) ; v . push ( new pair ( componentMin , componentMax ) ) ; } } var check = isValid ( v ) ; if ( check ) document . write ( " " ) ; else document . write ( " " ) ; return ; } var N = 4 ; var adj = [ ] ; for ( var i = 0 ; i <= N + 1 ; i ++ ) adj . push ( new Array ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 2 , 3 ) ; addEdge ( adj , 3 , 4 ) ; DFS ( adj , N ) ;

Index/key variables: i, u, v
Accumulator variables: i, u
Iterator variables: i, u
Boolean variables: ans
Class/struct names: pair
Javascript program:
function checkArrInStack ( s , arr , n ) { var freq = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freq . has ( arr [ i ] ) ) freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) else freq . set ( arr [ i ] , 1 ) } while ( s . length != 0 ) { var poppedEle = s [ s . length - 1 ] ; s . pop ( ) ; if ( freq . has ( poppedEle ) ) freq . set ( poppedEle , freq . get ( poppedEle ) - 1 ) ; } if ( freq . size == 0 ) return 0 ; return 1 ; } var s = [ ] ; s . push ( 10 ) ; s . push ( 20 ) ; s . push ( 30 ) ; s . push ( 40 ) ; s . push ( 50 ) ; var arr = [ 20 , 30 ] ; var n = arr . length ; if ( checkArrInStack ( s , arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function longDelSub ( str1 , str2 ) { var N = str1 . length ; var M = str2 . length ; var prev_pos = 0 ; var pos = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { var index = prev_pos ; while ( index < N && str1 [ index ] != str2 [ i ] ) { index ++ ; } pos [ i ] = index ; prev_pos = index + 1 ; } var res = N - prev_pos ; prev_pos = N - 1 ; for ( let i = M - 1 ; i >= 0 ; i -- ) { var index = prev_pos ; while ( index >= 0 && str1 [ index ] != str2 [ i ] ) { index -- ; } if ( i != 0 ) { res = Math . max ( res , index - pos [ i - 1 ] - 1 ) ; } prev_pos = index - 1 ; } res = Math . max ( res , prev_pos + 1 ) ; return res ; } var str1 = " " ; var str2 = " " ; console . log ( longDelSub ( str1 , str2 ) ) ;

Index/key variables: i, index
Accumulator variables: i, index
Iterator variables: i
Javascript program:
function print_substring ( s ) { let n = s . length ; let str = " " ; let ans = [ ] ; if ( n == 0 ) { document . write ( " " ) ; return ; } let last_pos = Array ( 26 ) . fill ( - 1 ) ; for ( let i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] == - 1 ) { last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] = i ; } } let minp = - 1 ; for ( let i = 0 ; i < n ; ++ i ) { let lp = last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ; minp = Math . max ( minp , lp ) ; if ( i == minp ) { str += s [ i ] ; document . write ( str + ' ' ) ; minp = - 1 ; str = " " ; } else { str += s [ i ] ; } } } let S = " " ; print_substring ( S ) ;

Index/key variables: i
Accumulator variables: str
Iterator variables: i
Javascript program:
function partitionString ( s ) { let n = s . length ; let ans = [ ] ; if ( n == 0 ) { document . write ( " " ) ; return ; } let last_pos = Array ( 26 ) . fill ( - 1 ) ; for ( let i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] == - 1 ) { last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] = i ; } } let minp = - 1 , plen = 0 ; for ( let i = 0 ; i < n ; ++ i ) { let lp = last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ; minp = Math . max ( minp , lp ) ; ++ plen ; if ( i == minp ) { ans . push ( plen ) ; minp = - 1 ; plen = 0 ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let str = " " ; partitionString ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minFirstTerm ( X , diff , N ) { let first_term = Number . MAX_VALUE ; let low = 0 , high = N ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( X - mid * diff > 0 ) { first_term = X - mid * diff ; low = mid + 1 ; } else high = mid - 1 ; } return first_term ; } function prletAP ( N , X , Y ) { if ( X > Y ) { X = X + Y ; Y = X - Y ; X = X - Y ; } let maxDiff = Y - X ; let first_term = Number . MAX_VALUE , diff = 0 ; for ( let i = 1 ; i * i <= maxDiff ; i ++ ) { if ( maxDiff % i == 0 ) { let diff1 = i ; let diff2 = Math . floor ( maxDiff / diff1 ) ; let terms1 = diff2 + 1 ; let terms2 = diff1 + 1 ; let first_term1 = minFirstTerm ( X , diff1 , N - terms1 ) ; let first_term2 = minFirstTerm ( X , diff2 , N - terms2 ) ; if ( first_term1 < first_term ) { first_term = first_term1 ; diff = diff1 ; } if ( first_term2 < first_term ) { first_term = first_term2 ; diff = diff2 ; } } } for ( let i = 0 ; i < N ; i ++ ) { document . write ( first_term + " " ) ; first_term += diff ; } } let N = 5 , X = 10 , Y = 15 ; prletAP ( N , X , Y ) ;

Accumulator variables: first_term, i
Iterator variables: i
Javascript program:
function isCubeSum ( n ) { for ( var i = 1 ; i * i * i <= n ; i ++ ) { if ( i * i * i + ( i + 1 ) * ( i + 1 ) * ( i + 1 ) == n ) return true ; } return false ; } var n = 35 ; if ( isCubeSum ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function maxweight ( s , e , pre ) { if ( s == e ) return 0 ; let ans = 0 ; for ( let i = s ; i < e ; i ++ ) { if ( ! pre [ i ] ) pre [ i ] = 0 ; if ( ! pre [ e ] ) pre [ e ] = 0 ; if ( ! pre [ s - 1 ] ) pre [ s - 1 ] = 0 ; let left = pre [ i ] - pre [ s - 1 ] ; let right = pre [ e ] - pre [ i ] ; if ( left < right ) ans = Math . max ( ans , left + maxweight ( s , i , pre ) ) ; if ( left == right ) { ans = Math . max ( ans , Math . max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; } if ( left > right ) ans = Math . max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; } return ans ; } function maxSum ( arr ) { let pre = new Map ; pre [ - 1 ] = 0 ; pre [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } document . write ( maxweight ( 0 , arr . length - 1 , pre ) ) ; } arr = [ 6 , 2 , 3 , 4 , 5 , 5 ] ; maxSum ( arr ) ;

Index/key variables: e, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function palindromePrefix ( S ) { let n = S . length ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let curr = S . substr ( 0 , i + 1 ) ; let l = 0 , r = curr . length - 1 ; let is_palindrome = true ; while ( l < r ) { if ( curr [ l ] != curr [ r ] ) { is_palindrome = false ; break ; } l ++ ; r -- ; } if ( is_palindrome ) return curr ; } return " " ; } function maxPalindrome ( S ) { let n = S . length ; if ( n <= 1 ) { return S ; } let pre = " " , suff = " " ; let i = 0 , j = n - 1 ; while ( S [ i ] == S [ j ] && i < j ) { i ++ ; j -- ; } i -- ; j ++ ; pre = S . substr ( 0 , i + 1 ) ; suff = S . substr ( j ) ; if ( j - i == 1 ) { return pre + suff ; } if ( j - i == 2 ) { let mid_char = S . substr ( i + 1 , i + 2 ) ; return pre + mid_char + suff ; } let rem_str = S . substr ( i + 1 , j ) ; let pre_of_rem_str = palindromePrefix ( rem_str ) ; rem_str = reverse ( rem_str ) ; let suff_of_rem_str = palindromePrefix ( rem_str ) ; if ( pre_of_rem_str . length >= suff_of_rem_str . length ) { return pre + pre_of_rem_str + suff ; } else { return pre + suff_of_rem_str + suff ; } } function reverse ( input ) { let a = input . split ( ' ' ) ; let l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { let temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return parseInt ( a ) ; } let S = " " ; document . write ( maxPalindrome ( S ) ) ;

Index/key variables: i, j, l, r
Accumulator variables: i, j, l, r
Iterator variables: i, l
Boolean variables: is_palindrome
Javascript program:
function countNumEnds ( A , L , R ) { let temp = 0 , count = 0 , digits = 0 ; let cycle = 0 ; digits = Math . round ( Math . log10 ( A ) ) + 1 ; temp = Math . round ( Math . pow ( 10 , digits ) ) ; cycle = temp ; while ( temp <= R ) { if ( temp >= L ) count ++ ; temp += cycle ; } document . write ( count ) ; } let A = 2 , L = 2 , R = 20 ; countNumEnds ( A , L , R ) ;

Accumulator variables: count, temp
Javascript program:
function minOperations ( s ) { var len = s . length ; var result = 0 ; for ( var i = 0 ; i < len / 2 ; i ++ ) { var D1 = Math . max ( s [ i ] . charCodeAt ( 0 ) , s [ len - 1 - i ] . charCodeAt ( 0 ) ) - Math . min ( s [ i ] . charCodeAt ( 0 ) , s [ len - 1 - i ] . charCodeAt ( 0 ) ) ; var D2 = 26 - D1 ; result += Math . min ( D1 , D2 ) ; } return result ; } var s = " " ; document . write ( minOperations ( s ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function countSubSequence ( arr , n ) { let maximum = Math . max ( ... arr ) ; let minimum = Math . min ( ... arr ) ; if ( maximum == minimum ) return Math . pow ( 2 , n ) - 1 ; let i = count ( arr , maximum ) ; let j = count ( arr , minimum ) ; let res = ( Math . pow ( 2 , i ) - 1 ) * ( Math . pow ( 2 , j ) - 1 ) * Math . pow ( 2 , n - i - j ) ; return res ; } function count ( arr , value ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) if ( arr [ i ] == value ) sum ++ ; return sum ; } let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; document . write ( countSubSequence ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function transformSubsequence ( n , m , A , B ) { if ( B . length == 0 ) return n ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( m + 1 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n + 1 ; i ++ ) { for ( var j = 0 ; j < m + 1 ; j ++ ) { if ( i == 0 j == 0 ) dp [ i ] [ j ] = 0 ; else if ( A [ i - 1 ] == B [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return n - dp [ n ] [ m ] ; } var N = 5 ; var M = 6 ; var A = [ 1 , 2 , 3 , 4 , 5 ] ; var B = [ 2 , 5 , 6 , 4 , 9 , 12 ] ; document . write ( transformSubsequence ( N , M , A , B ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkForPerfectSquare ( arr , i , j ) { let mid , sum = 0 ; for ( let m = i ; m <= j ; m ++ ) { sum += arr [ m ] ; } let low = 0 , high = parseInt ( sum / 2 ) ; while ( low <= high ) { mid = low + parseInt ( ( high - low ) / 2 ) ; if ( mid * mid == sum ) { return mid ; } else if ( mid * mid > sum ) { high = mid - 1 ; } else { low = mid + 1 ; } } return - 1 ; } let arr = [ 2 , 19 , 33 , 48 , 90 , 100 ] ; let L = 1 , R = 3 ; document . write ( checkForPerfectSquare ( arr , L , R ) ) ;

Index/key variables: m
Accumulator variables: m, sum
Iterator variables: m
Javascript program:
function calcSubarray ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { let flag = true ; let comm_diff = A [ i + 1 ] - A [ i ] ; for ( let k = i ; k < j ; k ++ ) { if ( A [ k + 1 ] - A [ k ] == comm_diff ) { continue ; } else { flag = false ; break ; } } if ( flag ) { count ++ ; } } } return count ; } let A = [ 8 , 7 , 4 , 1 , 0 ] ; let N = A . length ; document . write ( calcSubarray ( A , N ) ) ;

Index/key variables: i, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Boolean variables: flag
Javascript program:
function maxSumSubarray ( arr , n ) { var i = 0 , j = 1 ; var set = new Set ( ) ; set . add ( arr [ 0 ] ) ; var sum = arr [ 0 ] ; var maxsum = sum ; while ( i < n - 1 && j < n ) { var is_in = set . has ( arr [ j ] ) ; if ( ! is_in ) { sum = sum + arr [ j ] ; maxsum = Math . max ( sum , maxsum ) ; set . add ( arr [ j ++ ] ) ; } else { sum -= arr [ i ] ; set . delete ( arr [ i ++ ] ) ; } } return maxsum ; } var arr = [ 1 , 2 , 3 , 1 , 5 ] ; var ans = maxSumSubarray ( arr , 5 ) ; document . write ( ans ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Javascript program:
function count_numbers ( L , R ) { let ans = 0 ; for ( let n = L ; n <= R ; n ++ ) { let no_of_bits = Math . floor ( Math . log ( n ) + 1 ) ; let no_of_set_bits = bitCount ( n ) ; if ( no_of_bits - no_of_set_bits == 1 ) { ans ++ ; } } return ans ; } function bitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let L = 4 , R = 9 ; document . write ( count_numbers ( L , R ) ) ;

Accumulator variables: ans, n, setBits
Iterator variables: n
Javascript program:
function count_numbers ( L , R ) { let ans = 0 ; let LogR = ( Math . log ( R ) + 1 ) ; for ( let zero_bit = 0 ; zero_bit < LogR ; zero_bit ++ ) { let cur = 0 ; for ( let j = 0 ; j < zero_bit ; j ++ ) { cur |= ( 1 << j ) ; } for ( let j = zero_bit + 1 ; j < LogR ; j ++ ) { cur |= ( 1 << j ) ; if ( cur >= L && cur <= R ) { ans ++ ; } } } return ans ; } let L = 4 , R = 9 ; document . write ( count_numbers ( L , R ) ) ;

Accumulator variables: ans, cur, j, zero_bit
Iterator variables: j, zero_bit
Javascript program:
function findSum ( s ) { let sum = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { for ( let j = i + 1 ; j < s . length ; j ++ ) { if ( s [ i ] == s [ j ] ) { sum += ( j - i ) ; } } } return sum ; } let s = " " ; document . write ( findSum ( s ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function countElements ( a , n ) { var cnt = Array ( n + 1 ) . fill ( 0 ) ; var ans = 0 ; for ( k = 0 ; k < n ; k ++ ) { cnt [ a [ k ] ] ++ ; } for ( l = 0 ; l < n ; ++ l ) { var sum = 0 ; for ( r = l ; r < n ; ++ r ) { sum += a [ r ] ; if ( l == r ) continue ; if ( sum <= n ) { ans += cnt [ sum ] ; cnt [ sum ] = 0 ; } } } return ans ; } var a = [ 1 , 1 , 1 , 1 , 1 ] ; document . write ( countElements ( a , a . length ) ) ;

Index/key variables: k, r, sum
Accumulator variables: ans, k, sum
Iterator variables: k, l, r
Javascript program:
function maxGCD ( n ) { var maxHcf = Number . MIN_VALUE ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = i + 1 ; j <= n ; j ++ ) { maxHcf = Math . max ( maxHcf , __gcd ( i , j ) ) ; } } return maxHcf ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var n = 4 ; document . write ( maxGCD ( n ) ) ;

Accumulator variables: i, j
Iterator variables: i, j