dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countSubAllOnes ( s ) { var l = 0 , r = 0 , ans = 0 ; while ( l <= r ) { if ( r == s . length ) { ans += ( ( r - l ) * ( r - l + 1 ) ) / 2 ; break ; } if ( s [ r ] == ' ' ) r ++ ; else { ans += ( ( r - l ) * ( r - l + 1 ) ) / 2 ; l = r + 1 ; r ++ ; } } return ans ; } function flip ( s ) { for ( var i = 0 ; s [ i ] ; i ++ ) { if ( s [ i ] == ' ' ) s [ i ] = ' ' ; else s [ i ] = ' ' ; } return s ; } function countSubAllZerosOnes ( s ) { var only_1s = countSubAllOnes ( s ) ; s = flip ( s . split ( ' ' ) ) ; var only_0s = countSubAllOnes ( s ) ; return only_0s + only_1s ; } var s = " " ; document . write ( countSubAllZerosOnes ( s ) ) ;

Index/key variables: i, r
Accumulator variables: ans, i, r
Iterator variables: i
Javascript program:
function sumSquare ( p ) { return ( p - 1 ) % 4 == 0 ; } function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function countOfPrimes ( L , R ) { var count = 0 ; for ( var i = L ; i <= R ; i ++ ) { if ( isPrime ( i ) ) { if ( sumSquare ( i ) ) count ++ ; } } return count ; } var L = 5 , R = 41 ; document . write ( countOfPrimes ( L , R ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function count_elements ( arr , n ) { let count = 1 ; let max = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { count += 1 ; max = arr [ i ] ; } } return count ; } let arr = [ 2 , 1 , 4 , 6 , 3 ] ; let n = arr . length ; document . write ( count_elements ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function subString ( str , n ) { var c = 0 ; for ( var len = 1 ; len <= n ; len ++ ) { for ( var i = 0 ; i <= n - len ; i ++ ) { var j = i + len - 1 ; var temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } var k = i + 1 ; while ( temp < str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; f = 2 ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp > str [ k ] && k <= j && f != 2 ) { k ++ ; f = 0 ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } document . write ( c ) ; } var str = " " . split ( ' ' ) ; subString ( str , str . length ) ;

Index/key variables: i, k
Accumulator variables: c, i, k, len
Iterator variables: i, len
Javascript program:
function findNumberDivByPowerofTwo ( ar , k , n ) { var found = - 1 , m = k ; while ( m > 0 ) { var l = 0 ; var r = n - 1 ; while ( l <= r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( ar [ mid ] == m ) { found = m ; break ; } else if ( ar [ mid ] > m ) { r = mid - 1 ; } else if ( ar [ mid ] < m ) { l = mid + 1 ; } } if ( found != - 1 ) { break ; } m = parseInt ( m / 2 ) ; } return found ; } var arr = [ 3 , 5 , 7 , 8 , 10 ] ; var k = 4 , n = 5 ; document . write ( findNumberDivByPowerofTwo ( arr , k , n ) ) ;

Index/key variables: mid
Javascript program:
function findSubset ( a , n ) { let sum = 0 ; let cnt = 0 ; let v = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { if ( a [ i - 1 ] - i <= 0 ) { sum += a [ i - 1 ] - i ; cnt += 1 ; } else { v . push ( a [ i - 1 ] - i ) ; } } v . sort ( ) ; let ptr = 0 ; while ( ptr < v . length && sum + v [ ptr ] <= 0 ) { cnt += 1 ; ptr += 1 ; sum += v [ ptr ] ; } return cnt ; } let arr = [ 4 , 1 , 6 , 7 , 8 , 2 ] ; let n = arr . length ; document . write ( findSubset ( arr , n ) ) ;

Index/key variables: ptr
Accumulator variables: cnt, i, ptr, sum
Iterator variables: i
Javascript program:
function setElement ( arr , n , index , x ) { arr [ index ] = x ; } function getCount ( arr , n , l , r ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= l && arr [ i ] <= r ) { count ++ ; } } return count ; } function SolveQuery ( arr , n , Q ) { let x ; for ( let i = 0 ; i < Q . length ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { x = getCount ( arr , n , Q [ i ] [ 1 ] [ 0 ] , Q [ i ] [ 1 ] [ 1 ] ) ; document . write ( x + " " ) ; } else { setElement ( arr , n , Q [ i ] [ 1 ] [ 0 ] , Q [ i ] [ 1 ] [ 1 ] ) ; } } } let arr = [ 1 , 2 , 2 , 3 , 4 , 4 , 5 , 6 ] ; let n = arr . length ; let Q = [ [ 1 , [ 3 , 5 ] ] , [ 1 , [ 2 , 4 ] ] , [ 1 , [ 1 , 2 ] ] , [ 2 , [ 1 , 7 ] ] , [ 1 , [ 1 , 2 ] ] ] ; SolveQuery ( arr , n , Q ) ;

Index/key variables: i, index
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function generateSequence ( freq , n ) { let m = new Map ( ) ; let total = 0 ; for ( let i = 0 ; i < n ; i ++ ) { m . set ( i , freq [ i ] ) ; total += freq [ i ] ; } for ( let i = 0 ; i < n ; i ++ ) { if ( m . has ( i ) ) { let sequence = [ ] ; let mcopy = new Map ( ) ; for ( let [ key , value ] of m . entries ( ) ) { mcopy . set ( key , value ) ; } if ( mcopy . has ( i ) && mcopy . get ( i ) > 0 ) mcopy . set ( i , mcopy . get ( i ) - 1 ) ; sequence . push ( i ) ; let last = i ; for ( let i1 = 0 ; i1 < total - 1 ; i1 ++ ) { if ( mcopy . has ( last - 1 ) && mcopy . get ( last - 1 ) > 0 ) { mcopy . set ( last - 1 , mcopy . get ( last - 1 ) - 1 ) ; sequence . push ( last - 1 ) ; last -- ; } else if ( mcopy . has ( last + 1 ) ) { mcopy . set ( last + 1 , mcopy . get ( last + 1 ) - 1 ) ; sequence . push ( last + 1 ) ; last ++ ; } else break ; } if ( sequence . length == total ) { return sequence ; } } } let empty = [ ] ; return empty ; } function PrintSequence ( freq , n ) { let sequence = generateSequence ( freq , n ) ; if ( sequence . length == 0 ) { document . write ( " " ) ; } else { for ( let i = 0 ; i < sequence . length ; i ++ ) { document . write ( sequence [ i ] + " " ) ; } } } let freq = [ 2 , 2 , 2 , 3 , 1 ] ; let N = 5 ; PrintSequence ( freq , N ) ;

Index/key variables: i
Accumulator variables: i, i1, last, total
Iterator variables: i, i1
Javascript program:
function getMinimumDistance ( a , n ) { var min_set = new Set ( ) ; var max_set = new Set ( ) ; var max = 0 , min = 1000000000 ; var frequency = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( frequency . has ( a [ i ] ) ) frequency . set ( a [ i ] , frequency . get ( a [ i ] ) + 1 ) else frequency . set ( a [ i ] , 1 ) } for ( var i = 0 ; i < n ; i ++ ) { var count = frequency . get ( a [ i ] ) ; if ( count == max ) { max_set . add ( a [ i ] ) ; } else if ( count > max ) { max_set = new Set ( ) ; max = count ; max_set . add ( a [ i ] ) ; } if ( count == min ) { min_set . add ( a [ i ] ) ; } else if ( count < min ) { min_set = new Set ( ) ; min = count ; min_set . add ( a [ i ] ) ; } } var min_dist = 1000000000 ; var last_min_found = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( min_set . has ( a [ i ] ) ) last_min_found = i ; if ( max_set . has ( a [ i ] ) && last_min_found != - 1 ) { if ( ( i - last_min_found ) < min_dist ) min_dist = i - last_min_found ; } } last_min_found = - 1 ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( min_set . has ( a [ i ] ) ) last_min_found = i ; if ( max_set . has ( a [ i ] ) && last_min_found != - 1 ) { if ( ( last_min_found - i ) > min_dist ) min_dist = last_min_found - i ; } } document . write ( min_dist ) ; } var arr = [ 1 , 1 , 2 , 3 , 2 , 3 , 3 ] ; var N = arr . length ; getMinimumDistance ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printSubsequenceString ( str , k ) { let n = str . length ; let i ; let factors = new Array ( ) ; for ( let i = 2 ; i <= Math . sqrt ( k ) ; i ++ ) { while ( k % i == 0 ) { factors . push ( i ) ; k /= i ; } } if ( k > 1 ) factors . push ( k ) ; let count = new Array ( n ) . fill ( 1 ) ; let index = 0 ; while ( factors . length > 0 ) { count [ index ++ ] *= factors [ factors . length - 1 ] ; factors . pop ( ) ; if ( index == n ) index = 0 ; } let s = new String ( ) ; for ( i = 0 ; i < n ; i ++ ) { while ( count [ i ] -- > 0 ) { s += str [ i ] ; } } document . write ( s ) ; } let str = " " ; let k = 20 ; printSubsequenceString ( str , k ) ;

Index/key variables: i
Accumulator variables: i, index, k, s
Iterator variables: i
Javascript program:
function changeArr ( input , N ) { var newArray = JSON . parse ( JSON . stringify ( input ) ) ; newArray . sort ( ( a , b ) => a - b ) ; var i ; var ranks = new Map ( ) ; var rank = 1 ; for ( var index = 0 ; index < N ; index ++ ) { var element = newArray [ index ] ; if ( ! ranks . has ( element ) ) { ranks . set ( element , rank ) ; rank ++ ; } } for ( var index = 0 ; index < N ; index ++ ) { var element = input [ index ] ; input [ index ] = ranks . get ( input [ index ] ) ; } return input ; } var arr = [ 100 , 2 , 70 , 2 ] ; var N = arr . length ; arr = changeArr ( arr , N ) ; document . write ( " " ) ; for ( var i = 0 ; i < N - 1 ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( arr [ N - 1 ] + " " ) ;

Index/key variables: i, index
Accumulator variables: i, index, rank
Iterator variables: i, index
Javascript program:
function findPair ( arr , n ) { var i , j ; if ( n < 2 ) { document . write ( " " ) ; } var hashMap = new Set ( ) ; for ( var k = 0 ; k < n ; k ++ ) { hashMap . add ( arr [ k ] ) ; } for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var sum = arr [ i ] + arr [ j ] ; if ( ! hashMap . has ( sum ) ) { document . write ( " " + arr [ i ] + " " + arr [ j ] + " " ) ; } } } } var arr = [ 2 , 4 , 2 , 6 ] ; var n = arr . length ; findPair ( arr , n ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findLengthOfMaxSubset ( arr , n , m ) { let s = new Set ( ) ; let answer = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let tmp = arr [ i ] ; if ( tmp != m ) { s . add ( tmp ) ; answer ++ ; } } let min = 1 ; while ( s . has ( min ) ) { min ++ ; } if ( min != m ) { answer = - 1 ; } return answer ; } let arr = [ 1 , 2 , 4 ] ; let N = arr . length ; let M = 3 ; document . write ( findLengthOfMaxSubset ( arr , N , M ) ) ;

Index/key variables: i
Accumulator variables: answer, i, min
Iterator variables: i
Javascript program:
var m = 5 ; function countSubsquare ( arr , n , X ) { var dp = Array ( n + 1 ) ; for ( var i = 0 ; i < n + 1 ; i ++ ) dp [ i ] = Array ( m + 1 ) . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { dp [ i + 1 ] [ j + 1 ] = arr [ i ] [ j ] ; } } for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; } } var cnt = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { var lo = 1 ; var hi = Math . min ( n - i , m - j ) + 1 ; var found = false ; while ( lo <= hi ) { var mid = parseInt ( ( lo + hi ) / 2 ) ; var ni = i + mid - 1 ; var nj = j + mid - 1 ; var sum = dp [ ni ] [ nj ] - dp [ ni ] [ j - 1 ] - dp [ i - 1 ] [ nj ] + dp [ i - 1 ] [ j - 1 ] ; if ( sum >= X ) { if ( sum == X ) { found = true ; } hi = mid - 1 ; } else { lo = mid + 1 ; } } if ( found == true ) { cnt ++ ; } } } return cnt ; } var N = 4 , X = 10 ; var arr = [ [ 2 , 4 , 3 , 2 , 10 ] , [ 3 , 1 , 1 , 1 , 5 ] , [ 1 , 1 , 2 , 1 , 4 ] , [ 2 , 1 , 1 , 1 , 3 ] ] ; document . write ( countSubsquare ( arr , N , X ) + " " ) ;

Index/key variables: i, j, ni, nj
Accumulator variables: cnt, i, j
Iterator variables: i, j
Boolean variables: found
Javascript program:
function checkArray ( A , B , N ) { var start = 0 ; var end = N - 1 ; for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] != B [ i ] ) { start = i ; break ; } } for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] != B [ i ] ) { end = i ; break ; } } var l = start ; var r = end ; var d = parseInt ( ( r - l + 2 ) / 2 ) ; for ( var i = 0 ; i < d ; i ++ ) { var t = A [ l + i ] ; A [ l + i ] = A [ r - i ] ; A [ r - i ] = t ; } for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] != B [ i ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var A = [ 1 , 3 , 2 , 4 ] ; var B = [ 1 , 2 , 3 , 4 ] ; var N = A . length ; checkArray ( A , B , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSub ( str ) { var n = str . length ; var ans = 0 ; var cnt = Array ( 26 ) . fill ( 0 ) ; var i = 0 , j = 0 ; while ( i < n ) { if ( j < n && ( cnt [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) ) { cnt [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; ans += ( j - i + 1 ) ; j ++ ; } else { cnt [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; i ++ ; } } return ans ; } var str = " " ; document . write ( countSub ( str ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Javascript program:
function solve ( n , k ) { let ans = 0 ; for ( let j = 1 ; j * j <= n ; j ++ ) { if ( n % j == 0 ) { if ( j <= k ) { ans = Math . max ( ans , j ) ; } if ( n / j <= k ) { ans = Math . max ( ans , n / j ) ; } } } return ans ; } let N = 8 , K = 7 ; document . write ( ( N / solve ( N , K ) ) ) ;

Accumulator variables: j
Iterator variables: j
Javascript program:
function max_sum_subarray ( arr , L , R ) { let n = arr . length ; let pre = new Array ( n ) ; pre [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } let s1 = [ ] s1 . push ( 0 ) ; let ans = Number . MIN_VALUE ; ans = Math . max ( ans , pre [ L - 1 ] ) ; let flag = 0 ; for ( let i = L ; i < n ; i ++ ) { if ( i - R >= 0 ) { if ( flag == 0 ) { let it = s1 . indexOf ( 0 ) ; s1 . splice ( it , 1 ) ; flag = 1 ; } } if ( i - L >= 0 ) s1 . push ( pre [ i - L ] ) ; ans = Math . max ( ans , pre [ i ] - s1 [ 0 ] ) ; if ( i - R >= 0 ) { let it = s1 . indexOf ( pre [ i - R ] ) ; s1 . splice ( it , 1 ) ; } } document . write ( ans ) ; } let L , R ; L = 1 ; R = 3 ; let arr = [ 1 , 2 , 2 , 1 ] ; max_sum_subarray ( arr , L , R ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function rowWise ( v , n , m , k ) { var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var countcons = 0 ; for ( var j = 0 ; j < m ; j ++ ) { if ( ( v + i * m + j ) == ' ' ) { countcons = 0 ; } else { countcons ++ ; } if ( countcons >= k ) { ans ++ ; } } } return ans ; } function colWise ( v , n , m , k ) { var ans = 0 ; for ( var i = 0 ; i < m ; i ++ ) { var countcons = 0 ; for ( var j = 0 ; j < n ; j ++ ) { if ( ( v + j * n + i ) == ' ' ) { countcons = 0 ; } else { countcons ++ ; } if ( countcons >= k ) { ans ++ ; } } } return ans ; } var n = 3 , m = 3 , k = 1 ; var v = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; if ( k == 1 ) { document . write ( rowWise ( v [ 0 ] , n , m , k ) ) ; } else { document . write ( colWise ( v [ 0 ] , n , m , k ) + rowWise ( v [ 0 ] , n , m , k ) ) ; }

Accumulator variables: ans, countcons, i, j
Iterator variables: i, j
Javascript program:
function solve ( a , n ) { let mx = 0 ; for ( let j = 1 ; j < n ; j ++ ) { if ( mx > a [ j ] ) return false ; mx = Math . max ( mx , a [ j - 1 ] ) ; } return true ; } let a = [ 1 , 0 , 2 ] ; let n = a . length ; let possible = solve ( a , n ) ; if ( possible ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: j
Iterator variables: j
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } var spf = Array ( 100009 ) . fill ( 0 ) ; function sieve ( ) { for ( var i = 0 ; i < 100005 ; i ++ ) spf [ i ] = - 1 ; for ( var i = 2 ; i * i <= 100005 ; i ++ ) { for ( var j = i ; j <= 100005 ; j += i ) { if ( spf [ j ] == - 1 ) { spf [ j ] = i ; } } } } function findPrimeFactors ( s , n ) { while ( n > 1 ) { s . add ( spf [ n ] ) ; n /= spf [ n ] ; } return s ; } function MinimumSteps ( n , m ) { var q = [ ] ; var s = new Set ( ) ; q . push ( new pair ( n , 0 ) ) ; while ( q . length != 0 ) { var newNum = q [ 0 ] . first ; var distance = q [ 0 ] . second ; q . shift ( ) ; var k = findPrimeFactors ( s , newNum ) ; for ( var i of k ) { if ( newNum == m ) { return distance ; } else if ( newNum > m ) { break ; } else { q . push ( new pair ( newNum + i , distance + 1 ) ) ; } } } return - 1 ; } var N = 7 , M = 16 ; sieve ( ) ; document . write ( MinimumSteps ( N , M ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, n
Iterator variables: i, j
Class/struct names: pair
Javascript program:
function countPairs ( X , Y , m , n ) { let suffix = Array . from ( { length : 1005 } , ( _ , i ) => 0 ) ; let total_pairs = 0 ; for ( let i = 0 ; i < n ; i ++ ) suffix [ Y [ i ] ] ++ ; for ( let i = 1e3 ; i >= 3 ; i -- ) suffix [ i ] += suffix [ i + 1 ] ; for ( let i = 0 ; i < m ; i ++ ) { if ( X [ i ] == 0 ) continue ; else if ( X [ i ] == 1 ) { total_pairs += suffix [ 0 ] ; continue ; } else if ( X [ i ] == 2 ) total_pairs += suffix [ 5 ] ; else if ( X [ i ] == 3 ) total_pairs += suffix [ 2 ] + suffix [ 4 ] ; else total_pairs += suffix [ X [ i ] + 1 ] ; total_pairs += suffix [ 0 ] + suffix [ 1 ] ; } return total_pairs ; } let X = [ 10 , 19 , 18 ] ; let Y = [ 11 , 15 , 9 ] ; let m = X . length ; let n = Y . length ; document . write ( countPairs ( X , Y , m , n ) ) ;

Index/key variables: i
Accumulator variables: i, total_pairs
Iterator variables: i
Javascript program:
function solve ( A , N , M ) { var B = Array . from ( Array ( N ) , ( ) => Array ( M ) ) ; var c = 1 ; var s = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) B [ i ] [ j ] = c ++ ; } for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { if ( i != 0 ) { if ( A [ i - 1 ] [ j ] == A [ i ] [ j ] ) B [ i - 1 ] [ j ] = B [ i ] [ j ] ; } if ( i != N - 1 ) { if ( A [ i + 1 ] [ j ] == A [ i ] [ j ] ) B [ i + 1 ] [ j ] = B [ i ] [ j ] ; } if ( j != 0 ) { if ( A [ i ] [ j - 1 ] == A [ i ] [ j ] ) B [ i ] [ j - 1 ] = B [ i ] [ j ] ; } if ( j != M - 1 ) { if ( A [ i ] [ j + 1 ] == A [ i ] [ j ] ) B [ i ] [ j + 1 ] = B [ i ] [ j ] ; } } } for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) s . add ( B [ i ] [ j ] ) ; } return s . size ; } var N = 2 , M = 3 ; var A = [ [ 2 , 1 , 3 ] , [ 1 , 1 , 2 ] ] ; document . write ( solve ( A , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function splitArray ( start , end , arr , prefix_sum ) { if ( start >= end ) return 0 ; for ( let k = start ; k < end ; ++ k ) { if ( ( prefix_sum [ k ] - prefix_sum [ start - 1 ] ) == ( prefix_sum [ end ] - prefix_sum [ k ] ) ) { return 1 + splitArray ( start , k , arr , prefix_sum ) + splitArray ( k + 1 , end , arr , prefix_sum ) ; } } return 0 ; } function solve ( arr , n ) { let prefix_sum = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; prefix_sum [ 0 ] = 0 ; for ( let i = 1 ; i <= n ; ++ i ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i - 1 ] ; } document . write ( splitArray ( 1 , n , arr , prefix_sum ) ) ; } let arr = [ 12 , 3 , 3 , 0 , 3 , 3 ] ; let N = arr . length ; solve ( arr , N ) ;

Index/key variables: end, i, k
Iterator variables: i, k
Javascript program:
function minDays ( arr , n , k ) { let l = arr . length , left = 1 , right = 1000000000 ; if ( n * k > l ) return - 1 ; while ( left < right ) { let mid = parseInt ( ( left + right ) / 2 ) , cnt = 0 , product = 0 ; for ( let j = 0 ; j < l ; ++ j ) { if ( arr [ j ] > mid ) { cnt = 0 ; } else if ( ++ cnt >= k ) { product ++ ; cnt = 0 ; } } if ( product < n ) { left = mid + 1 ; } else { right = mid ; } } return left ; } let arr = [ 1 , 10 , 3 , 10 , 2 ] ; let n = 3 , k = 1 ; document . write ( minDays ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: product
Iterator variables: j
Javascript program:
function countFac ( n ) { var m = n ; var count = 0 ; for ( var i = 2 ; ( i * i ) <= m ; ++ i ) { var total = 0 ; while ( n % i == 0 ) { n /= i ; ++ total ; } var temp = 0 ; for ( var j = 1 ; ( temp + j ) <= total ; ++ j ) { temp += j ; ++ count ; } } if ( n != 1 ) ++ count ; return count ; } var N = 24 ; document . write ( countFac ( N ) ) ;

Accumulator variables: n, temp
Iterator variables: i, j
Javascript program:
function minimumSum ( a , b , c , n ) { let dp = new Array ( n ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = 1e6 ; } } dp [ 0 ] [ 0 ] = a [ 0 ] ; dp [ 0 ] [ 1 ] = b [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = Math . min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 0 ] + a [ i ] ) ; dp [ i ] [ 0 ] = Math . min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 1 ] + a [ i ] + c ) ; dp [ i ] [ 1 ] = Math . min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 0 ] + b [ i ] + c ) ; dp [ i ] [ 1 ] = Math . min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + b [ i ] ) ; } document . write ( Math . min ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) + " " ) ; } let arr1 = [ 7 , 6 , 18 , 6 , 16 , 18 , 1 , 17 , 17 ] ; let arr2 = [ 6 , 9 , 3 , 10 , 9 , 1 , 10 , 1 , 5 ] ; let C = 2 ; let N = arr1 . length ; minimumSum ( arr1 , arr2 , C , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minimumMoves ( S , K ) { var N = S . length ; var ops = 0 ; var last_idx = - 1 ; for ( var i = 0 ; i < K ; i ++ ) { if ( S [ i ] == ' ' ) last_idx = i ; } if ( last_idx == - 1 ) { ++ ops ; S [ K - 1 ] = ' ' ; last_idx = K - 1 ; } for ( var i = 1 ; i < N - K + 1 ; i ++ ) { if ( last_idx < i ) last_idx = - 1 ; if ( S [ i + K - 1 ] == ' ' ) last_idx = i + K - 1 ; if ( last_idx == - 1 ) { ++ ops ; S [ i + K - 1 ] = ' ' ; last_idx = i + K - 1 ; } } return ops ; } var S = " " ; var K = 3 ; document . write ( minimumMoves ( S , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var arr = [ ' ' , ' ' , ' ' ] ; function findString ( n , k , s1 , s2 ) { var s3 = s2 ; var d = 0 ; for ( i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) d ++ ; } if ( ( d + 1 ) / 2 > k ) { document . write ( " " + " " ) ; return ; } else { if ( k <= d ) { var X = d - k ; var T = 2 * k - d ; for ( i = 0 ; i < s3 . length ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( T > 0 ) { for ( j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s2 [ i ] ) { s3 [ i ] = arr [ j ] ; T -- ; break ; } } } else if ( X > 0 ) { s3 [ i ] = s1 [ i ] ; X -- ; } } } document . write ( s3 . join ( ' ' ) + " " ) ; } else { for ( i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] != s3 [ i ] ) { for ( j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } for ( i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] == s3 [ i ] && k > 0 ) { for ( j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } document . write ( s3 . join ( ' ' ) + " " ) ; } } } var N = 4 , k = 2 ; var S1 = " " ; var S2 = " " ; findString ( N , k , S1 . split ( ' ' ) , S2 . split ( ' ' ) ) ;

Index/key variables: i, j
Accumulator variables: T, X, d, i, j, k
Iterator variables: i, j
Javascript program:
function findSolutions ( N ) { let count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( ( i + parseInt ( N / i ) ) % 2 == 0 ) { count ++ ; } } } document . write ( 4 * count + " " ) ; } let N = 80 ; findSolutions ( N ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countTriplets ( color ) { var result = 0 , Blue_Count = 0 ; var Red_Count = 0 ; var data = color . split ( ' ' ) ; for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] == ' ' ) Blue_Count ++ ; } for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] == ' ' ) Blue_Count -- ; if ( data [ i ] == ' ' ) Red_Count ++ ; if ( data [ i ] == ' ' ) result += Red_Count * Blue_Count ; } return result ; } var color = " " ; document . write ( countTriplets ( color ) ) ;

Index/key variables: i
Accumulator variables: Blue_Count, Red_Count, i, result
Iterator variables: i
Javascript program:
function naive_find_x ( N ) { var c = 0 , i ; for ( i = 1 ; i < N ; i ++ ) { c += i * i * i ; if ( c >= N ) break ; } return i ; } var N = 100 ; document . write ( naive_find_x ( N ) ) ;

Accumulator variables: c, i
Iterator variables: i