dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function printSequence ( A , n , k ) { var mp = new Map ( ) ; var sol = [ ] ; A . forEach ( x => { sol . push ( x ) ; } ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( ! mp . has ( sol [ i ] ) || mp . get ( sol [ i ] ) . size == 0 ) { var tmp = new Set ( ) ; tmp . add ( i ) mp . set ( sol [ i ] , tmp ) } else { var idxx = [ ... mp . get ( sol [ i ] ) ] . sort ( ( a , b ) => a - b ) [ 0 ] ; var idx = idxx ; var x = mp . get ( sol [ i ] ) ; x . delete ( idxx ) ; mp . set ( sol [ i ] , x ) ; sol [ idx ] += k ; if ( ! mp . has ( sol [ idx ] ) ) mp . set ( sol [ idx ] , new Set ( ) ) x = mp . get ( sol [ idx ] ) ; x . add ( idx ) ; mp . set ( sol [ idx ] , x ) ; x = mp . get ( sol [ i ] ) ; x . add ( i ) ; mp . set ( sol [ i ] , x ) ; } } sol . forEach ( x => { document . write ( x + " " ) ; } ) ; } var N = 5 ; var K = 6 ; var A = [ 1 , 4 , 1 , 1 , 4 ] ; printSequence ( A , N , K ) ;

Index/key variables: i, idx
Accumulator variables: i
Iterator variables: i
Javascript program:
function longestGP ( A , N ) { if ( N < 2 ) return N ; let length = 1 , common_ratio = 1 ; let maxlength = 1 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i + 1 ] % A [ i ] == 0 ) { if ( A [ i + 1 ] / A [ i ] == common_ratio ) { length = length + 1 ; maxlength = Math . max ( maxlength , length ) ; } else { common_ratio = A [ i + 1 ] / A [ i ] ; length = 2 ; } } else { maxlength = Math . max ( maxlength , length ) ; length = 1 ; } } maxlength = Math . max ( maxlength , length ) ; return maxlength ; } let arr = [ 1 , 2 , 4 , 7 , 14 , 28 , 56 , 89 ] ; let N = arr . length ; document . write ( longestGP ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function uncrossedLines ( a , b , n , m ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { dp [ i ] = new Array ( m + 1 ) ; for ( let j = 0 ; j < ( m + 1 ) ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= m ; 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 dp [ n ] [ m ] ; } let A = [ 3 , 9 , 2 ] ; let B = [ 3 , 2 , 9 ] ; let N = A . length ; let M = B . length ; document . write ( uncrossedLines ( A , B , N , M ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minFlips ( mat , s ) { let N = mat . length ; let M = mat [ 0 ] . length ; let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] != s [ ( i + j ) ] - ' ' ) { count ++ ; } } } return count ; } let mat = [ [ 1 , 0 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 0 , 0 ] ] ; let s = " " ; document . write ( minFlips ( mat , s ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function revNum ( N ) { var x = 0 ; while ( N ) { x = x * 10 + ( N % 10 ) ; N = N / 10 ; } return x ; } function ctNonPalin ( arr , N ) { var Res = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var x = revNum ( arr [ i ] ) ; if ( x == arr [ i ] ) { continue ; } else { Res += arr [ i ] % 10 == N % 10 ; } } return Res ; } var arr = [ 121 , 134 , 2342 , 4514 ] ; var N = arr . length ; document . write ( ctNonPalin ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: Res, i
Iterator variables: i
Javascript program:
function minlt ( arr , target , n ) { var dp = Array . from ( Array ( arr . length + 1 ) , ( ) => Array ( target + 1 ) . fill ( - 1 ) ) ; for ( var i = 0 ; i < arr . length + 1 ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( var j = 0 ; j < target + 1 ; j ++ ) dp [ 0 ] [ j ] = 1000000000 ; for ( var i = 1 ; i <= arr . length ; i ++ ) { for ( var j = 1 ; j <= target ; j ++ ) { if ( arr [ i - 1 ] > j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } else { dp [ i ] [ j ] = Math . min ( dp [ i - 1 ] [ j ] , ( dp [ i ] [ j - arr [ i - 1 ] ] ) != 1000000000 ? ( dp [ i ] [ j - arr [ i - 1 ] ] + 1 ) : 1000000000 ) ; } } } if ( dp [ arr . length ] [ target ] == 1000000000 ) { return - 1 ; } else { return dp [ arr . length ] [ target ] ; } } var arr = [ 2 , 3 , 5 , 4 , 1 ] ; var target = 11 ; var n = arr . length ; document . write ( minlt ( arr , target , n ) ) ;

Index/key variables: i, j, target
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minServerLoads ( n , servers ) { var totalLoad = 0 ; servers . forEach ( i => { totalLoad += i ; } ) ; var requiredLoad = parseInt ( totalLoad / 2 ) ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( requiredLoad + 1 ) . fill ( 0 ) ) ; for ( var i = 1 ; i < n + 1 ; i ++ ) { for ( var j = 1 ; j < requiredLoad + 1 ; j ++ ) { if ( servers [ i - 1 ] > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; else dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , servers [ i - 1 ] + dp [ i - 1 ] [ j - servers [ i - 1 ] ] ) ; } } return totalLoad - 2 * dp [ n ] [ requiredLoad ] ; } var N = 5 ; var servers = [ 1 , 2 , 3 , 4 , 5 ] ; document . write ( minServerLoads ( N , servers ) ) ;

Index/key variables: i, j, n, requiredLoad
Accumulator variables: i, j, totalLoad
Iterator variables: i, j
Javascript program:
function maxLenSub ( arr , N ) { var Pos = 0 ; var Neg = 0 ; var res = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { Pos = Neg = 0 ; } else if ( arr [ i ] > 0 ) { Pos += 1 ; if ( Neg != 0 ) { Neg += 1 ; } res = Math . max ( res , Pos ) ; } else { [ Pos , Neg ] = [ Neg , Pos ] ; Neg += 1 ; if ( Pos != 0 ) { Pos += 1 ; } res = Math . max ( res , Pos ) ; } } return res ; } var arr = [ - 1 , - 2 , - 3 , 0 , 1 ] ; var N = arr . length ; document . write ( maxLenSub ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: Neg, Pos, i
Iterator variables: i
Javascript program:
function maxLength ( arr ) { let len = Number . MIN_VALUE ; let N = arr . length ; for ( let i = 0 ; i < N ; i ++ ) { let l = arr [ i ] . length ; if ( len < l ) { len = l ; } } return len ; } function maxStrings ( arr , len ) { let N = arr . length ; let ans = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( len == arr [ i ] . length ) { ans . push ( arr [ i ] ) ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } function printStrings ( arr ) { let max = maxLength ( arr ) ; maxStrings ( arr , max ) ; } let arr = [ " " , " " , " " , " " , " " ] ; printStrings ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function min_flips ( str , k ) { if ( str . length == 0 ) return 0 ; let ans = 0 ; let cnt_zeros = 0 ; for ( let ch in str . split ( ' ' ) ) { if ( str [ ch ] == ' ' ) { ++ cnt_zeros ; } else { cnt_zeros = 0 ; } if ( cnt_zeros == k ) { ++ ans ; cnt_zeros = 0 ; } } return ans ; } let str = " " ; let k = 3 ; document . write ( min_flips ( str , k ) ) ;

Index/key variables: ch
Iterator variables: ch
Javascript program:
function maxSubArray ( arr , n , K ) { let solution = [ ] ; let multi = 1 ; let start = 0 ; if ( n <= 1 K < 0 ) { return solution ; } for ( let i = 0 ; i < n ; i ++ ) { multi = multi * arr [ i ] ; while ( multi > K ) { multi = Math . floor ( multi / arr [ start ] ) ; start ++ ; } let list = [ ] ; for ( let j = i ; j >= start ; j -- ) { list . unshift ( arr [ j ] ) ; solution . push ( list ) ; } } return solution ; } let arr = [ 2 , 7 , 1 , 4 ] ; let n = arr . length ; let K = 7 ; let v = maxSubArray ( arr , n , K ) ; document . write ( " " ) ; let first = true ; for ( let x = 0 ; x < v . length ; x ++ ) { if ( ! first ) { document . write ( " " ) ; } else { first = false ; } document . write ( " " ) ; let ff = true ; for ( let y = 0 ; y < v [ x ] . length ; y ++ ) { if ( ! ff ) { document . write ( " " ) ; } else { ff = false ; } document . write ( v [ x ] [ y ] ) ; } document . write ( " " ) ; } document . write ( " " ) ;

Index/key variables: i, j, start, x, y
Accumulator variables: i, j, start, x, y
Iterator variables: i, j, x, y
Boolean variables: ff, first
Javascript program:
function solve ( D , N , X , Y ) { let T = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { let x = D [ i ] [ 0 ] ; let y = D [ i ] [ 1 ] ; let speed = D [ i ] [ 2 ] ; let time = ( ( x * x - X * X ) + ( y * y - Y * Y ) ) / ( speed * speed ) ; T . push ( time ) ; } T . sort ( function ( a , b ) { return a - b ; } ) ; let i = 0 ; let total = 0 ; while ( i < ( T . length - 1 ) ) { let count = 1 ; while ( ( i < ( T . length - 1 ) ) && ( T [ i ] == T [ i + 1 ] ) ) { count += 1 ; i += 1 ; } total += ( count * ( count - 1 ) ) / 2 ; i += 1 ; } return total ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = 5 ; let D = [ [ 5 , 12 , 1 ] , [ 16 , 63 , 5 ] , [ - 10 , 24 , 2 ] , [ 7 , 24 , 2 ] , [ - 24 , 7 , 2 ] ] ; let X = 0 , Y = 0 ; document . write ( solve ( D , N , X , Y ) . toFixed ( 1 ) ) ;

Index/key variables: i
Accumulator variables: count, i, total
Iterator variables: i
Javascript program:
function getMaxLength ( arr , N ) { let res = 2 ; let dist = 2 ; let curradj = ( arr [ 1 ] - arr [ 0 ] ) ; let prevadj = ( arr [ 1 ] - arr [ 0 ] ) ; for ( let i = 2 ; i < N ; i ++ ) { curradj = arr [ i ] - arr [ i - 1 ] ; if ( curradj == prevadj ) { dist ++ ; } else { prevadj = curradj ; res = Math . max ( res , dist ) ; dist = 2 ; } } res = Math . max ( res , dist ) ; return res ; } let arr = [ 10 , 7 , 4 , 6 , 8 , 10 , 11 ] ; let N = arr . length ; document . write ( getMaxLength ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: dist, i
Iterator variables: i
Javascript program:
function minSteps ( str , N ) { var smaller , cost = 0 ; var f = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { var curr_ele = str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; smaller = 0 ; for ( var j = 0 ; j <= curr_ele ; j ++ ) { if ( f [ j ] !== 0 ) smaller += f [ j ] ; } if ( smaller === 0 ) cost += i + 1 ; else cost += i - smaller + 1 ; f [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } return cost ; } var str = " " ; var N = str . length ; document . write ( minSteps ( str , N ) ) ;

Index/key variables: i, j
Accumulator variables: cost, i, j, smaller
Iterator variables: i, j
Javascript program:
function findSubarrays ( a ) { let n = a . length ; let freq = new Array ( n + 1 ) . fill ( 0 ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { if ( count == 0 ) continue ; else { let value = count ; for ( let j = 1 ; j <= count ; j ++ ) { freq [ j ] += value ; value -- ; } count = 0 ; } } else count ++ ; } if ( count > 0 ) { let value = count ; for ( let j = 1 ; j <= count ; j ++ ) { freq [ j ] += value ; value -- ; } } return freq ; } function countRectangles ( a , b , K ) { let n = a . length ; let m = b . length ; let subA = findSubarrays ( a ) ; let subB = findSubarrays ( b ) ; let total = 0 ; for ( let i = 1 ; i < subA . length ; i ++ ) { if ( K % i == 0 && ( K / i ) <= m ) { total = total + subA [ i ] * subB [ K / i ] ; } } document . write ( total ) ; } let a = [ 0 , 0 , 1 , 1 ] ; let b = [ 1 , 0 , 1 ] ; let K = 2 ; countRectangles ( a , b , K ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, value
Iterator variables: i, j
Javascript program:
function printRes ( res ) { var n = res . length ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( res [ i ] + " " ) ; } } function printLBS ( arr , N ) { var lis = Array ( N ) ; var lds = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) { lis [ i ] = lds [ i ] = 1 ; } for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { if ( lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } } for ( var i = N - 1 ; i >= 0 ; i -- ) { for ( var j = N - 1 ; j > i ; j -- ) { if ( arr [ j ] < arr [ i ] ) { if ( lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; } } } var MaxVal = arr [ 0 ] , inx = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( MaxVal < lis [ i ] + lds [ i ] - 1 ) { MaxVal = lis [ i ] + lds [ i ] - 1 ; inx = i ; } } var ct1 = lis [ inx ] ; var res = [ ] ; for ( var i = inx ; i >= 0 && ct1 > 0 ; i -- ) { if ( lis [ i ] == ct1 ) { res . push ( arr [ i ] ) ; ct1 -- ; } } res . reverse ( ) ; var ct2 = lds [ inx ] - 1 ; for ( var i = inx ; i < N && ct2 > 0 ; i ++ ) { if ( lds [ i ] == ct2 ) { res . push ( arr [ i ] ) ; ct2 -- ; } } printRes ( res ) ; } var arr = [ 80 , 60 , 30 , 40 , 20 , 10 ] ; var N = arr . length ; printLBS ( arr , N ) ;

Index/key variables: i, inx, j
Accumulator variables: ct1, ct2, i, j
Iterator variables: i, j
Javascript program:
function possible ( T , arr , n , d ) { let partition = 1 ; let total = 0 ; for ( let i = 0 ; i < n ; i ++ ) { total = total + arr [ i ] ; if ( total > T ) { partition = partition + 1 ; total = arr [ i ] ; if ( partition > d ) { return false ; } } } return true ; } function calcT ( n , d , arr ) { let mx = - 1 , sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { mx = Math . max ( mx , arr [ i ] ) ; sum = sum + arr [ i ] ; } let lb = mx ; let ub = sum ; while ( lb < ub ) { let T_mid = lb + ( ub - lb ) / 2 ; if ( possible ( T_mid , arr , n , d ) == true ) { ub = T_mid ; } else { lb = T_mid + 1 ; } } document . write ( lb ) ; } let d = 2 ; let arr = [ 1 , 1 , 1 , 1 , 1 ] ; let n = arr . length ; calcT ( n , d , arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minReqSubstring ( s , n ) { let ongoing = ' ' ; let count = 0 , l = s . length ; for ( let i = 1 ; i < l ; i ++ ) { if ( ongoing == ' ' ) { if ( s [ i ] < s [ i - 1 ] ) { ongoing = ' ' ; } else if ( s [ i ] == s [ i - 1 ] ) { ongoing = ' ' ; } else { ongoing = ' ' ; } } else if ( ongoing == ' ' ) { if ( s [ i ] > s [ i - 1 ] ) { ongoing = ' ' ; } else if ( s [ i ] == s [ i - 1 ] ) { ongoing = ' ' ; } else { ongoing = ' ' ; count += 1 ; } } else { if ( s [ i ] < s [ i - 1 ] ) { ongoing = ' ' ; } else if ( s [ i ] == s [ i - 1 ] ) { ongoing = ' ' ; } else { ongoing = ' ' ; count += 1 ; } } } return count + 1 ; } let S = " " ; let n = S . length ; document . write ( minReqSubstring ( S , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minimum_required_operations ( arr , n , k ) { let answer = 0 ; let mod = 1000000007 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] + arr [ i + 1 ] > k ) { if ( arr [ i ] > k ) { answer += ( arr [ i ] - k ) ; arr [ i ] = k ; } answer += ( arr [ i ] + arr [ i + 1 ] ) - k ; arr [ i + 1 ] = ( k - arr [ i ] ) ; answer %= mod ; } } return answer ; } let a = [ 9 , 50 , 4 , 14 , 42 , 89 ] ; let k = 10 ; let n = a . length ; document . write ( minimum_required_operations ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
function findSmallestString ( str1 , str2 ) { let freq1 = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; let freq2 = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; let n1 = str1 . length ; let n2 = str2 . length ; for ( let i = 0 ; i < n1 ; ++ i ) { freq1 [ str1 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } for ( let i = 0 ; i < n2 ; ++ i ) { freq2 [ str2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } for ( let i = 0 ; i < 26 ; ++ i ) { freq1 [ i ] -= freq2 [ i ] ; } let res = " " ; let minIndex = str2 [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; for ( let i = 0 ; i < 26 ; ++ i ) { for ( let j = 0 ; j < freq1 [ i ] ; ++ j ) { res += String . fromCharCode ( i + ' ' . charCodeAt ( ) ) ; } if ( i == minIndex ) { res += str2 ; } } return res ; } let str1 = " " ; let str2 = " " ; document . write ( findSmallestString ( str1 , str2 ) ) ;

Index/key variables: i
Accumulator variables: res
Iterator variables: i, j
Javascript program:
function determineWinner ( str ) { let A = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { A [ str [ i ] . charCodeAt ( ) - 48 ] ++ ; } for ( let i = 0 ; i <= 9 ; i ++ ) { if ( i % 2 != 0 ) { sum1 = sum1 + A [ i ] ; } else { sum2 = sum2 + A [ i ] ; } } if ( sum1 == sum2 ) { document . write ( " " ) ; } else if ( sum1 > sum2 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str = " " ; determineWinner ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function manipulateStrings ( P , Q ) { var freq = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < P . length ; i ++ ) { freq [ P [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } for ( var i = 0 ; i < Q . length ; i ++ ) { freq [ Q [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] -- ; } var sb = " " ; var pos = Q [ 0 ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; for ( var i = 0 ; i <= pos ; i ++ ) { while ( freq [ i ] > 0 ) { var c = String . fromCharCode ( " " . charCodeAt ( 0 ) + i ) ; sb += c ; freq [ i ] -- ; } } sb += Q ; for ( var i = pos + 1 ; i < 26 ; i ++ ) { while ( freq [ i ] > 0 ) { var c = String . fromCharCode ( " " . charCodeAt ( 0 ) + i ) ; sb += c ; freq [ i ] -- ; } } document . write ( sb ) ; } var P = " " ; var Q = " " ; manipulateStrings ( P , Q ) ;

Index/key variables: i
Accumulator variables: i, sb
Iterator variables: i
Javascript program:
function solve ( n , arr ) { let i , ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { let left = Math . max ( i - 1 , 0 ) ; let right = Math . min ( n - 1 , i + 1 ) ; while ( left >= 0 ) { if ( arr [ left ] > arr [ i ] ) { left ++ ; break ; } left -- ; } if ( left < 0 ) left ++ ; while ( right < n ) { if ( arr [ right ] > arr [ i ] ) { right -- ; break ; } right ++ ; } if ( right >= n ) right -- ; ans = 1 + right - left ; document . write ( ans + " " ) ; } } let arr = [ 4 , 2 , 1 ] ; let n = arr . length ; solve ( n , arr ) ;

Index/key variables: i, left, right
Accumulator variables: i, left, right
Iterator variables: i
Javascript program:
function countSubstrings ( s , n ) { var count = 0 , sum = 0 ; var mp = new Map ( ) ; if ( mp . has ( 0 ) ) mp . set ( 0 , mp . get ( 0 ) + 1 ) else mp . set ( 0 , 1 ) ; for ( var i = 0 ; i < n ; ++ i ) { sum += ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; if ( mp . has ( sum - ( i + 1 ) ) ) count += mp . get ( sum - ( i + 1 ) ) ; if ( mp . has ( sum - ( i + 1 ) ) ) mp . set ( sum - ( i + 1 ) , mp . get ( sum - ( i + 1 ) ) + 1 ) else mp . set ( sum - ( i + 1 ) , 1 ) } return count ; } var str = " " ; var n = str . length ; document . write ( countSubstrings ( str , n ) ) ;

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Javascript program:
function findCount ( arr , n ) { let prefix_sum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ; let suffix_sum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; suffix_sum [ n - 1 ] = arr [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) suffix_sum [ i ] = suffix_sum [ i + 1 ] + arr [ i ] ; let s = 1 , e = 1 ; let curr_subarray_sum = 0 , count = 0 ; while ( s < n - 1 && e < n - 1 ) { while ( e < n - 1 && curr_subarray_sum < prefix_sum [ s - 1 ] ) { curr_subarray_sum += arr [ e ++ ] ; } if ( curr_subarray_sum <= suffix_sum [ e ] ) { count ++ ; } curr_subarray_sum -= arr [ s ++ ] ; } return count ; } let arr = [ 2 , 3 , 1 , 7 ] ; let n = arr . length ; document . write ( findCount ( arr , n ) ) ;

Index/key variables: e, i
Accumulator variables: count, curr_subarray_sum, e, i, s
Iterator variables: i
Javascript program:
function minOperation ( s , n ) { let ans = 0 ; let i = 0 , j = n - 1 ; while ( i < j ) { if ( s [ i ] == ' ' && s [ j ] == ' ' ) { ans ++ ; i ++ ; j -- ; continue ; } if ( s [ i ] == ' ' ) { i ++ ; } if ( s [ j ] == ' ' ) { j -- ; } } return ans ; } let n = 8 ; let s = " " ; document . write ( minOperation ( s , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Javascript program:
function count ( N ) { if ( N == 1 ) { document . write ( ( 10 ) + " " ) ; return ; } var dp = Array . from ( Array ( N ) , ( ) => Array ( 10 ) . fill ( 0 ) ) ; for ( var i = 1 ; i < 10 ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( var i = 1 ; i < N ; i ++ ) { var temp = 0 ; for ( var j = 0 ; j < 10 ; j ++ ) temp += dp [ i - 1 ] [ j ] ; for ( var j = 0 ; j < 10 ; j ++ ) dp [ i ] [ j ] = temp - dp [ i - 1 ] [ j ] ; } var ans = 0 ; for ( var i = 0 ; i < 10 ; i ++ ) ans += dp [ N - 1 ] [ i ] ; document . write ( ans ) ; } var N = 2 ; count ( N ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let ctr = 0 ; function find ( parent , x ) { if ( parent [ x ] == x ) return x ; parent [ x ] = find ( parent , parent [ x ] ) ; return parent [ x ] ; } function setUnion ( parent , rank , x , y ) { let parentx = find ( parent , x ) ; let parenty = find ( parent , y ) ; if ( parenty == parentx ) return ; ctr -- ; if ( rank [ parentx ] < rank [ parenty ] ) { parent [ parentx ] = parenty ; } else if ( rank [ parentx ] > rank [ parenty ] ) { parent [ parenty ] = parentx ; } else { parent [ parentx ] = parenty ; rank [ parenty ] ++ ; } } function solve ( n , m , query ) { let result = new Array ( query . length ) ; let parent = new Array ( n * m ) ; for ( let i = 0 ; i < n * m ; i ++ ) parent [ i ] = i ; let rank = new Array ( n * m ) ; let grid = new Array ( n * m ) ; for ( let i = 0 ; i < ( n * m ) ; i ++ ) { rank [ i ] = 0 ; grid [ i ] = false ; } for ( let i = 0 ; i < query . length ; i ++ ) { let x = query [ i ] [ 0 ] ; let y = query [ i ] [ 1 ] ; if ( grid [ m * x + y ] == true ) { result [ i ] = ctr ; continue ; } grid [ m * x + y ] = true ; ctr ++ ; if ( x > 0 && grid [ m * ( x - 1 ) + y ] == true ) setUnion ( parent , rank , m * x + y , m * ( x - 1 ) + y ) ; if ( y > 0 && grid [ m * ( x ) + y - 1 ] == true ) setUnion ( parent , rank , m * x + y , m * ( x ) + y - 1 ) ; if ( x < n - 1 && grid [ m * ( x + 1 ) + y ] == true ) setUnion ( parent , rank , m * x + y , m * ( x + 1 ) + y ) ; if ( y < m - 1 && grid [ m * ( x ) + y + 1 ] == true ) setUnion ( parent , rank , m * x + y , m * ( x ) + y + 1 ) ; result [ i ] = ctr ; } return result ; } let N = 3 , M = 3 , K = 4 ; let query = [ [ 0 , 0 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] ] ; let result = solve ( N , M , query ) ; for ( let i = 0 ; i < K ; i ++ ) document . write ( result [ i ] + " " ) ;

Index/key variables: i, parentx, parenty, x
Accumulator variables: ctr, i
Iterator variables: i
Javascript program:
function findMinSum ( A , K ) { let n = A . length ; let suffix_min = Array . from ( { length : n } , ( _ , i ) => 0 ) ; suffix_min [ n - 1 ] = A [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) suffix_min [ i ] = Math . min ( suffix_min [ i + 1 ] , A [ i ] ) ; let min_sum = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( i + K < n ) min_sum = Math . min ( min_sum , A [ i ] + suffix_min [ i + K ] ) ; } document . write ( min_sum ) ; } let A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let K = 2 ; findMinSum ( A , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxEnvelopes ( envelopes ) { var N = envelopes . length ; if ( N == 0 ) return N ; envelopes . sort ( ) ; var dp = Array ( N ) ; var max_envelope = 1 ; dp [ 0 ] = 1 ; for ( var i = 1 ; i < N ; ++ i ) { dp [ i ] = 1 ; for ( var j = 0 ; j < i ; ++ j ) { if ( envelopes [ i ] [ 0 ] > envelopes [ j ] [ 0 ] && envelopes [ i ] [ 1 ] > envelopes [ j ] [ 1 ] && dp [ i ] < dp [ j ] + 1 ) dp [ i ] = dp [ j ] + 1 ; } max_envelope = Math . max ( max_envelope , dp [ i ] ) ; } return max_envelope ; } var envelopes = [ [ 4 , 3 ] , [ 5 , 3 ] , [ 5 , 6 ] , [ 1 , 2 ] ] ; document . write ( maxEnvelopes ( envelopes ) ) ;

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