dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var MAX = 100005 ; var totBackEdges ; var countAdj = Array ( MAX ) . fill ( 0 ) ; var small = Array ( MAX ) . fill ( 0 ) ; var isPossible = Array ( MAX ) . fill ( 0 ) ; var depth = Array ( MAX ) . fill ( 0 ) ; var adj = [ ] ; var vis = Array ( MAX ) . fill ( 0 ) ; class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function change ( p , x ) { if ( p . second > x ) p . second = x ; if ( p . first > p . second ) { var tmp = p . first ; p . first = p . second ; p . second = tmp ; } } function dfs ( v , p = - 1 , de = 0 ) { var answer = new pair ( 100000000 , 100000000 ) ; depth [ v ] = de ; vis [ v ] = 1 ; isPossible [ v ] = 1 ; for ( var u of adj [ v ] ) { if ( ( u ^ p ) != 0 ) { if ( vis [ u ] == 0 ) { var x = dfs ( u , v , de + 1 ) ; small [ v ] += small [ u ] ; change ( answer , x . second ) ; change ( answer , x . first ) ; if ( x . second < de ) isPossible [ v ] = 0 ; } else if ( vis [ u ] == 1 ) { totBackEdges ++ ; countAdj [ v ] ++ ; countAdj [ u ] ++ ; small [ p ] ++ ; small [ u ] -- ; change ( answer , depth [ u ] ) ; } } } vis [ v ] = 2 ; return answer ; } function minNodetoRemove ( n , edges ) { for ( var i = 0 ; i < edges . length ; i ++ ) { ( adj [ ( edges [ i ] ) . first ] ) . push ( ( edges [ i ] ) . second ) ; ( adj [ ( edges [ i ] ) . second ] ) . push ( ( edges [ i ] ) . first ) ; } vis = Array ( MAX ) . fill ( 0 ) ; totBackEdges = 0 ; for ( var v = 1 ; v <= n ; v ++ ) { if ( vis [ v ] == 0 ) dfs ( v ) ; } if ( totBackEdges == 0 ) return - 1 ; var node = - 1 ; for ( var v = 1 ; v <= n ; v ++ ) { if ( ( countAdj [ v ] + small [ v ] == totBackEdges ) && isPossible [ v ] != 0 ) { node = v ; } if ( node != - 1 ) break ; } return node ; } var N = 5 ; var edges = [ ] ; for ( var i = 0 ; i < MAX ; i ++ ) { adj . push ( new Array ( ) ) ; } edges . push ( new pair ( 5 , 1 ) ) ; edges . push ( new pair ( 5 , 2 ) ) ; edges . push ( new pair ( 1 , 2 ) ) ; edges . push ( new pair ( 2 , 3 ) ) ; edges . push ( new pair ( 2 , 4 ) ) ; document . write ( minNodetoRemove ( N , edges ) ) ;

Index/key variables: i, p, u, v
Accumulator variables: i, totBackEdges, v
Iterator variables: i, u, v
Class/struct names: pair
Javascript program:
let N = 3 let M = 5 let Large = 1e6 ; let prime = new Array ( ) ; function SieveOfEratosthenes ( ) { let isPrime = new Array ( ) ; for ( let i = 0 ; i < Large + 1 ; i ++ ) { isPrime . push ( [ ] ) } isPrime . fill ( true ) ; for ( let p = 2 ; p * p <= Large ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * 2 ; i <= Large ; i += p ) isPrime [ i ] = false ; } } for ( let p = 2 ; p <= Large ; p ++ ) if ( isPrime [ p ] ) prime . push ( p ) ; } function Display ( arr , row ) { for ( let i = 0 ; i < M ; i ++ ) document . write ( arr [ row ] [ i ] + " " ) ; } function countDivisorsMult ( arr ) { let mp = new Map ( ) ; let row_no = 0 ; let max_factor = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { let no = arr [ i ] [ j ] ; for ( let k = 0 ; k < prime . length ; k ++ ) { while ( no > 1 && no % prime [ k ] == 0 ) { no /= prime [ k ] ; if ( mp . has ( prime [ k ] ) ) { mp . set ( prime [ k ] , mp . get ( prime [ k ] ) + 1 ) } else { mp . set ( prime [ k ] , 1 ) } } if ( no == 1 ) break ; } } let res = 1 ; for ( let it of mp ) { res *= ( it [ 1 ] + 1 ) ; } if ( max_factor < res ) { row_no = i ; max_factor = res ; } mp . clear ( ) ; } Display ( arr , row_no ) ; } let arr = [ [ 1 , 2 , 3 , 10 , 23 ] , [ 4 , 5 , 6 , 7 , 8 ] , [ 7 , 8 , 9 , 15 , 45 ] ] ; SieveOfEratosthenes ( ) ; countDivisorsMult ( arr ) ;

Index/key variables: i, j, k, p, row
Accumulator variables: i, j, k, no, p, res
Iterator variables: i, it, j, k, p
Javascript program:
function isSquare ( n ) { let k = Math . floor ( Math . sqrt ( n ) ) ; return k * k == n ? 1 : 0 ; } function calculate ( pos , prev , sum , v ) { if ( pos == v . length ) return isSquare ( sum ) ; for ( let i = prev ; i <= 9 ; i ++ ) { v [ pos ] = i ; sum += i * i ; if ( calculate ( pos + 1 , i , sum , v ) != 0 ) return 1 ; sum -= ( i * i ) ; } return 0 ; } function minValue ( n ) { let v = Array . from ( { length : n } , ( _ , i ) => 0 ) ; if ( calculate ( 0 , 1 , 0 , v ) != 0 ) { let answer = " " ; for ( let i = 0 ; i < v . length ; i ++ ) answer += ( v [ i ] + 0 ) ; return answer ; } else return " " ; } let N = 2 ; document . write ( minValue ( N ) ) ;

Index/key variables: i, pos
Accumulator variables: answer, i, sum
Iterator variables: i
Javascript program:
function checkOdd ( number ) { let n = number . length ; let num = number [ n - 1 ] - ' ' ; return ( num & 1 ) ; } function splitLetoOdds ( number ) { let numLen = number . length ; let splitDP = Array . from ( { length : numLen + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < numLen + 1 ; i ++ ) splitDP [ i ] = - 1 ; for ( let i = 1 ; i <= numLen ; i ++ ) { if ( i <= 9 && ( checkOdd ( number . substr ( 0 , i ) ) == 1 ) ) splitDP [ i ] = 1 ; if ( splitDP [ i ] != - 1 ) { for ( let j = 1 ; j <= 9 && i + j <= numLen ; j ++ ) { if ( checkOdd ( number . substr ( i , i + j ) ) == 1 ) { if ( splitDP [ i + j ] == - 1 ) splitDP [ i + j ] = 1 + splitDP [ i ] ; else splitDP [ i + j ] = Math . min ( splitDP [ i + j ] , 1 + splitDP [ i ] ) ; } } } } return splitDP [ numLen ] ; } document . write ( splitLetoOdds ( " " ) ) ;

Index/key variables: i, numLen
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var m , n , d ; var v = [ ] ; var k = 1000000007 ; var dp = Array ( 2001 ) ; for ( var i = 0 ; i < 2001 ; i ++ ) { dp [ i ] = Array . from ( Array ( 2001 ) , ( ) => Array ( 2 ) ) ; } function init ( l ) { for ( var i = 0 ; i < 2001 ; i ++ ) { for ( var j = 0 ; j < 2001 ; j ++ ) { for ( var k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } v = [ ] ; for ( var i = 0 ; i < l . length ; i ++ ) { v . push ( l [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; } n = l . length ; } function number_minus_one ( a ) { var s = a . substring ( 1 ) ; var s1 = " " ; for ( var i = 0 ; i < s . length - 1 ; i ++ ) s1 += ' ' ; if ( a [ 0 ] == ' ' && s === s1 ) { var l = s . length ; a = a . replace ( a [ 0 ] , ' ' ) ; for ( var i = 0 ; i < l ; i ++ ) a += ' ' ; } else { for ( var i = a . length - 1 ; i >= 0 ; i -- ) { if ( a [ i ] == ' ' ) a = a . replace ( a [ i ] , ' ' ) ; else { a = a . replace ( a [ i ] , String . fromCharCode ( ( ( a [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) - 1 ) + ' ' . charCodeAt ( 0 ) ) ) ; break ; } } } return a . toString ( ) ; } function fun ( pos , sum , f ) { if ( pos == n ) { if ( sum == 0 ) { return 1 ; } return 0 ; } if ( dp [ pos ] [ sum ] [ f ] != - 1 ) return dp [ pos ] [ sum ] [ f ] ; var lmt = 9 ; if ( f == 0 ) lmt = v [ pos ] ; var ans = 0 ; for ( var i = 0 ; i <= lmt ; i ++ ) { if ( i == d && pos % 2 == 1 ) ans += 0 ; else if ( i != d && pos % 2 == 0 ) ans += 0 ; else { var new_f = f ; if ( f == 0 && i < lmt ) new_f = 1 ; var new_sum = sum ; new_sum *= 10 ; new_sum += i ; new_sum %= m ; ans += fun ( pos + 1 , new_sum , new_f ) ; ans %= k ; } } dp [ pos ] [ sum ] [ f ] = ans ; return dp [ pos ] [ sum ] [ f ] ; } function operations ( L , R ) { init ( R ) ; var ans = fun ( 0 , 0 , 0 ) ; L = number_minus_one ( L ) ; init ( L ) ; ans -= fun ( 0 , 0 , 0 ) ; if ( ans < 0 ) ans += k ; document . write ( ans + " " ) ; } m = 2 ; d = 2 ; var Q = 1 ; var arr = [ [ " " , " " ] ] ; for ( var i = 0 ; i < Q ; i ++ ) { operations ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; }

Index/key variables: f, i, j, k, pos, sum
Accumulator variables: a, ans, i, j, k, new_sum, s1
Iterator variables: i, j, k
Javascript program:
function checkPrime ( number ) { let num = String ( number ) ; for ( let i = 2 ; i * i <= num ; i ++ ) if ( ( num % i ) == 0 ) return false ; return true ; } function splitIntoPrimes ( number ) { if ( number . length == 0 ) return 0 ; if ( number . length <= 6 && checkPrime ( number ) ) return 1 ; else { let numLen = number . length ; let ans = 1000000 ; for ( let i = 1 ; i <= 6 && i <= numLen ; i ++ ) { if ( checkPrime ( number . substr ( 0 , i ) ) ) { let val = splitIntoPrimes ( number . substr ( i ) ) ; if ( val != - 1 ) { ans = Math . min ( ans , 1 + val ) ; } } } if ( ans == 1000000 ) return - 1 ; return ans ; } } document . write ( splitIntoPrimes ( " " ) + " " ) ; document . write ( splitIntoPrimes ( " " ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function k_nonzero_numbers ( s , n , k ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = new Array ( k + 1 ) ; for ( let x = 0 ; x <= k ; x ++ ) dp [ i ] [ j ] [ x ] = 0 ; } } dp [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( let i = 0 ; i < n ; ++ i ) { let sm = 0 ; while ( sm < 2 ) { for ( let j = 0 ; j < k + 1 ; ++ j ) { let x = 0 ; while ( x <= ( sm != 0 ? 9 : s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) { if ( j + ( x > 0 ? 1 : 0 ) < k + 1 ) { dp [ i + 1 ] [ ( sm != 0 || x < ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ? 1 : 0 ] [ j + ( x > 0 ? 1 : 0 ) ] += dp [ i ] [ sm ] [ j ] ; } ++ x ; } } ++ sm ; } } return dp [ n ] [ 0 ] [ k ] + dp [ n ] [ 1 ] [ k ] ; } let s = " " ; let k = 2 ; let n = s . length ; document . write ( k_nonzero_numbers ( s , n , k ) ) ;

Index/key variables: i, j, k, n, sm, x
Accumulator variables: i, j, x
Iterator variables: i, j, x
Javascript program:
function maximumOccurrence ( s ) { var n = s . length ; var freq = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { var temp = " " ; temp += s [ i ] ; if ( freq . has ( temp ) ) freq . set ( temp , freq . get ( temp ) + 1 ) else freq . set ( temp , 1 ) } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { var temp = " " ; temp += s [ i ] ; temp += s [ j ] ; if ( freq . has ( temp ) ) freq . set ( temp , freq . get ( temp ) + 1 ) else freq . set ( temp , 1 ) } } var answer = - 1000000000 ; freq . forEach ( ( value , key ) => { answer = Math . max ( answer , value ) ; } ) ; return answer ; } var s = " " ; document . write ( maximumOccurrence ( s ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, temp
Iterator variables: i, j
Javascript program:
function distinctChars ( s ) { let freq = [ ] ; for ( let i = 0 ; i < 26 ; i ++ ) freq . push ( 0 ) ; let count = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) freq [ s . charCodeAt ( i ) - 97 ] ++ ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) count ++ ; } return count ; } function waysToSplit ( s ) { let n = s . length ; let answer = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let left = s . substr ( 0 , i ) ; let right = s . substr ( i , n - i ) ; if ( distinctChars ( left ) == distinctChars ( right ) ) answer ++ ; } return answer ; } let s = " " ; document . write ( waysToSplit ( s ) ) ;

Index/key variables: i
Accumulator variables: answer, count, i
Iterator variables: i
Javascript program:
function waysToSplit ( s ) { var n = s . length ; var answer = 0 ; var prefix = Array ( n ) . fill ( 0 ) ; var suffix = Array ( n ) . fill ( 0 ) ; var seen = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var prev = ( i - 1 >= 0 ? prefix [ i - 1 ] : 0 ) ; if ( seen [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) { prefix [ i ] += ( prev + 1 ) ; } else prefix [ i ] = prev ; seen [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 1 ; } seen = Array ( 26 ) . fill ( 0 ) ; suffix [ n - 1 ] = 0 ; for ( var i = n - 1 ; i >= 1 ; i -- ) { var prev = suffix [ i ] ; if ( seen [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) { suffix [ i - 1 ] += ( prev + 1 ) ; } else suffix [ i - 1 ] = prev ; seen [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 1 ; } for ( var i = 0 ; i < n ; i ++ ) { if ( prefix [ i ] == suffix [ i ] ) answer ++ ; } return answer ; } var s = " " ; document . write ( waysToSplit ( s ) ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
var MAX_SIZE = 100005 ; var fib = Array ( MAX_SIZE + 1 ) . fill ( 0 ) ; function fibonacci ( ) { var i ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( i = 2 ; i <= MAX_SIZE ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } function printLevel ( level ) { var left_index = parseInt ( Math . pow ( 2 , level - 1 ) ) ; var right_index = parseInt ( ( Math . pow ( 2 , level ) - 1 ) ) ; for ( i = left_index ; i <= right_index ; i ++ ) { document . write ( fib [ i - 1 ] + " " ) ; } document . write ( ) ; } fibonacci ( ) ; var K = 4 ; printLevel ( K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculate ( pos , prev , left , k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; let answer = 0 ; for ( let i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return answer ; } function countWaystoDivide ( n , k ) { return calculate ( 0 , 1 , n , k ) ; } let N = 8 ; let K = 4 ; document . write ( countWaystoDivide ( N , K ) ) ;

Accumulator variables: answer, i
Iterator variables: i
Javascript program:
let dp = new Array ( 500 ) ; for ( let i = 0 ; i < 500 ; i ++ ) { dp [ i ] = new Array ( 500 ) ; for ( let j = 0 ; j < 500 ; j ++ ) { dp [ i ] [ j ] = new Array ( 500 ) ; for ( let k = 0 ; k < 500 ; k ++ ) dp [ i ] [ j ] [ k ] = 0 ; } } function calculate ( pos , prev , left , k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; if ( dp [ pos ] [ prev ] [ left ] != - 1 ) return dp [ pos ] [ prev ] [ left ] ; let answer = 0 ; for ( let i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return dp [ pos ] [ prev ] [ left ] = answer ; } function countWaystoDivide ( n , k ) { for ( let i = 0 ; i < 500 ; i ++ ) { for ( let j = 0 ; j < 500 ; j ++ ) { for ( let l = 0 ; l < 500 ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } return calculate ( 0 , 1 , n , k ) ; } let N = 8 ; let K = 4 ; document . write ( countWaystoDivide ( N , K ) ) ;

Index/key variables: i, j, k, l, left, pos, prev
Accumulator variables: answer, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function maxScore ( l , r , prefix_sum , num ) { if ( l > r ) return 0 ; let current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; return current_sum + Math . max ( maxScore ( l + 1 , r , prefix_sum , num + 1 ) , maxScore ( l , r - 1 , prefix_sum , num + 1 ) ) ; } function findMaxScore ( a , n ) { let prefix_sum = new Uint8Array ( n ) ; prefix_sum [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } return maxScore ( 0 , n - 1 , prefix_sum , 1 ) ; } let n = 6 ; let A = [ 1 , 2 , 3 , 4 , 2 , 6 ] ; document . write ( findMaxScore ( A , n ) ) ;

Index/key variables: i, r
Accumulator variables: current_sum, i
Iterator variables: i
Javascript program:
function FindMaxLength ( A , B , n , m ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( m + 1 ) ; for ( let j = 0 ; j <= m ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = n - 1 ; i >= 0 ; i -- ) { for ( let j = m - 1 ; j >= 0 ; j -- ) { if ( A [ i ] == B [ j ] ) dp [ j ] [ i ] = dp [ j + 1 ] [ i + 1 ] + 1 ; } } let maxm = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { maxm = Math . max ( maxm , dp [ i ] [ j ] ) ; } } return maxm ; } let A = [ 1 , 2 , 8 , 2 , 1 ] ; let B = [ 8 , 2 , 1 , 4 , 7 ] ; let n = A . length ; let m = B . length ; document . write ( FindMaxLength ( A , B , n , m ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxLength ( a , n ) { let maximum = 1 ; let left = new Array ( n ) ; let right = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { left [ i ] = 1 ; right [ i ] = 1 ; } for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] > a [ i + 1 ] ) { right [ i ] = right [ i + 1 ] + 1 ; } maximum = Math . max ( maximum , right [ i ] ) ; } for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { left [ i ] = left [ i - 1 ] + 1 ; } } if ( n > 2 ) { for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i - 1 ] > a [ i + 1 ] ) { maximum = Math . max ( maximum , left [ i - 1 ] + right [ i + 1 ] ) ; } } } return maximum ; } let arr = [ 8 , 7 , 3 , 5 , 2 , 9 ] ; let n = arr . length ; document . write ( maxLength ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let LAS = new Array ( ) ; for ( let i = 0 ; i < 1000 ; i ++ ) { let temp = new Array ( ) for ( let j = 0 ; j < 2 ; j ++ ) { temp . push ( [ ] ) } LAS . push ( temp ) ; } for ( let i = 0 ; i < 1000 ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { LAS [ i ] [ j ] = false } } function solve ( arr , n , i , pos ) { if ( i == n ) return 0 ; if ( LAS [ i ] [ pos ] ) return LAS [ i ] [ pos ] ; let inc = 0 , exc = 0 ; if ( arr [ i ] > 0 && pos == true ) { pos = false ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } else if ( arr [ i ] < 0 && pos == false ) { pos = true ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } exc = solve ( arr , n , i + 1 , pos ) ; LAS [ i ] [ pos ] = Math . max ( inc , exc ) ; return LAS [ i ] [ pos ] ; } let arr = [ - 1 , 2 , 3 , 4 , 5 , - 6 , 8 , - 99 ] ; let n = arr . length ; document . write ( Math . max ( solve ( arr , n , 0 , 0 ) , solve ( arr , n , 0 , 1 ) ) ) ;

Index/key variables: i, j, pos
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: pos
Javascript program:
function cntSubSeq ( arr , n ) { var pos_count = 0 ; var neg_count = 0 ; var result ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = Math . pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= Math . pow ( 2 , neg_count - 1 ) ; else result = 0 ; return result ; } var arr = [ 3 , - 4 , - 1 , 6 ] ; var n = arr . length ; document . write ( cntSubSeq ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, neg_count, pos_count, result
Iterator variables: i
Javascript program:
function minSteps ( str , n , k ) { if ( str [ n - 1 ] == ' ' ) return - 1 ; if ( n == 1 ) return 0 ; if ( n < 4 ) return 1 ; var dp = Array ( n ) ; dp [ n - 1 ] = 0 ; dp [ n - 2 ] = 1 ; dp [ n - 3 ] = 1 ; for ( var i = n - 4 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) continue ; var steps = 1000000000 ; if ( i + k < n && str [ i + k ] == ' ' ) steps = Math . min ( steps , dp [ i + k ] ) ; if ( str [ i + 1 ] == ' ' ) steps = Math . min ( steps , dp [ i + 1 ] ) ; if ( str [ i + 2 ] == ' ' ) steps = Math . min ( steps , dp [ i + 2 ] ) ; dp [ i ] = ( steps == 1000000000 ) ? steps : 1 + steps ; } if ( dp [ 0 ] == 1000000000 ) return - 1 ; return dp [ 0 ] ; } var str = " " ; var n = str . length ; var k = 5 ; document . write ( minSteps ( str , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var dp = new Map ( ) ; function solve ( s , c ) { if ( s . length == 1 ) return 0 ; if ( s . length == 2 ) { if ( s [ 0 ] == s [ 1 ] && s [ 0 ] == c ) return 1 ; else return 0 ; } if ( dp . has ( s + " " + c ) ) return dp . get ( s + " " + c ) ; var ans = 0 ; if ( s [ 0 ] == s [ s . length - 1 ] && s [ 0 ] == c ) { for ( var c1 = ' ' . charCodeAt ( 0 ) ; c1 <= ' ' . charCodeAt ( 0 ) ; c1 ++ ) if ( String . fromCharCode ( c1 ) != c ) ans = Math . max ( ans , 1 + solve ( s . substring ( 1 , s . length - 1 ) , String . fromCharCode ( c1 ) ) ) ; } else { for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == c ) { for ( var j = s . length - 1 ; j > i ; j -- ) if ( s [ j ] == c ) { if ( j == i ) break ; ans = solve ( s . substring ( i , j + 1 ) , c ) ; break ; } break ; } } } dp . set ( s + " " + c , ans ) ; return ans ; } var s = " " ; var ma = 0 ; for ( var c1 = ' ' . charCodeAt ( 0 ) ; c1 <= ' ' . charCodeAt ( 0 ) ; c1 ++ ) ma = Math . max ( ma , solve ( s , String . fromCharCode ( c1 ) ) * 2 ) ; document . write ( ma ) ;

Index/key variables: i, j
Accumulator variables: c1, i, j
Iterator variables: c1, i, j
Javascript program:
function eggDrop ( n , k ) { let dp = new Array ( ) ; for ( let i = 0 ; i < k + 1 ; i ++ ) { dp . push ( new Array ( n + 1 ) . fill ( 0 ) ) } let x = 0 ; while ( dp [ x ] [ n ] < k ) { x ++ ; for ( let i = 1 ; i <= n ; i ++ ) dp [ x ] [ i ] = dp [ x - 1 ] [ i - 1 ] + dp [ x - 1 ] [ i ] + 1 ; } return x ; } let n = 2 , k = 36 ; document . write ( eggDrop ( n , k ) ) ;

Index/key variables: i, n, x
Accumulator variables: i, x
Iterator variables: i
Javascript program:
function maxIncSubarr ( a , n ) { let pre = new Array ( n ) ; let pos = new Array ( n ) ; pre . fill ( 0 ) ; pos . fill ( 0 ) ; pre [ 0 ] = 1 ; pos [ n - 1 ] = 1 ; let l = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) pre [ i ] = pre [ i - 1 ] + 1 ; else pre [ i ] = 1 ; } l = 1 ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] < a [ i + 1 ] ) pos [ i ] = pos [ i + 1 ] + 1 ; else pos [ i ] = 1 ; } let ans = 0 ; l = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) l ++ ; else l = 1 ; ans = Math . max ( ans , l ) ; } for ( let i = 1 ; i <= n - 2 ; i ++ ) { if ( a [ i - 1 ] < a [ i + 1 ] ) ans = Math . max ( pre [ i - 1 ] + pos [ i + 1 ] , ans ) ; } return ans ; } let arr = [ 1 , 2 ] ; let n = arr . length ; document . write ( maxIncSubarr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, l
Iterator variables: i
Javascript program:
var n = 3 var m = 3 function countSquareMatrices ( a , N , M ) { var count = 0 ; for ( var i = 1 ; i < N ; i ++ ) { for ( var j = 1 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == 0 ) continue ; a [ i ] [ j ] = Math . min ( Math . min ( a [ i - 1 ] [ j ] , a [ i ] [ j - 1 ] ) , a [ i - 1 ] [ j - 1 ] ) + 1 ; } } for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < M ; j ++ ) count += a [ i ] [ j ] ; return count ; } var arr = [ [ 1 , 0 , 1 ] , [ 1 , 1 , 0 ] , [ 1 , 1 , 0 ] ] ; document . write ( countSquareMatrices ( arr , n , m ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
var N = 10000 ; var seg = Array ( 3 * N ) . fill ( 0 ) ; function update ( inVal , l , r , up_in , val ) { if ( r < up_in l > up_in ) return seg [ inVal ] ; if ( l == up_in && r == up_in ) return seg [ inVal ] = val ; var m = parseInt ( ( l + r ) / 2 ) ; seg [ inVal ] = update ( 2 * inVal + 1 , l , m , up_in , val ) + update ( 2 * inVal + 2 , m + 1 , r , up_in , val ) ; return seg [ inVal ] ; } function query ( inVal , l , r , l1 , r1 ) { if ( l > r ) return 0 ; if ( r < l1 l > r1 ) return 0 ; if ( l1 <= l && r <= r1 ) return seg [ inVal ] ; var m = parseInt ( ( l + r ) / 2 ) ; return query ( 2 * inVal + 1 , l , m , l1 , r1 ) + query ( 2 * inVal + 2 , m + 1 , r , l1 , r1 ) ; } function findCnt ( arr , n ) { var brr = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; brr . sort ( ( a , b ) => a - b ) ; var r = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) r [ brr [ i ] ] = i + 1 ; var dp = Array ( n ) . fill ( 0 ) ; var ans = 0 ; for ( var i = n - 1 ; i >= 0 ; i -- ) { var rank = r [ arr [ i ] ] ; dp [ i ] = 1 + query ( 0 , 0 , n - 1 , rank , n - 1 ) ; ans += dp [ i ] ; update ( 0 , 0 , n - 1 , rank - 1 , dp [ i ] + query ( 0 , 0 , n - 1 , rank - 1 , rank - 1 ) ) ; } return ans ; } var arr = [ 1 , 2 , 10 , 9 ] ; var n = arr . length ; document . write ( findCnt ( arr , n ) ) ;

Index/key variables: i, inVal
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let N = 1000005 function maximum_set ( a , n ) { let dp = new Array ( N ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) dp [ a [ i ] ] = 1 ; let ans = 1 ; for ( let i = N - 1 ; i >= 1 ; i -- ) { if ( dp [ i ] != 0 ) { for ( let j = 2 * i ; j < N ; j += i ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ j ] ) ; ans = Math . max ( ans , dp [ i ] ) ; } } } return ans ; } let arr = [ 3 , 4 , 6 , 8 , 10 , 18 , 21 , 24 ] ; let n = arr . length ; document . write ( maximum_set ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j