dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxSelections ( A , n , k ) { A . sort ( ) ; let sum = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + A [ i ] ; if ( sum > k ) { break ; } count ++ ; } return count ; } let A = [ 3 , 7 , 2 , 9 , 4 ] ; let k = 15 ; let n = A . length ; document . write ( maxSelections ( A , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function ConstructBinaryString ( N , M , K ) { if ( M < ( N - 1 ) || M > K * ( N + 1 ) ) return " " ; let ans = " " ; let l = Math . min ( K , M / ( N - 1 ) ) ; let temp = N ; while ( temp != 0 ) { temp -- ; ans += ' ' ; if ( temp == 0 ) break ; for ( let i = 0 ; i < l ; i ++ ) { ans += ' ' ; } } M -= ( N - 1 ) * l ; if ( M == 0 ) return ans ; l = Math . min ( M , K ) ; for ( let i = 0 ; i < l ; i ++ ) ans += ' ' ; M -= l ; while ( M > 0 ) { ans = ' ' + ans ; M -- ; } return ans ; } let N = 5 , M = 9 , K = 2 ; document . write ( ConstructBinaryString ( N , M , K ) ) ;

Accumulator variables: M, ans, i, temp
Iterator variables: i
Javascript program:
function number ( num ) { let a = new Array ( 20 ) ; let r , j ; let i = 0 ; while ( num > 0 ) { r = num % 10 ; if ( 9 - r > r ) a [ i ] = r ; else a [ i ] = 9 - r ; i ++ ; num = parseInt ( num / 10 , 10 ) ; } if ( a [ i - 1 ] == 0 ) { document . write ( 9 ) ; i -- ; } for ( j = i - 1 ; j >= 0 ; j -- ) document . write ( a [ j ] ) ; } let num = 4545 ; number ( num ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function countDigitSum ( N , K ) { let l = parseInt ( Math . pow ( 10 , N - 1 ) ) , r = parseInt ( Math . pow ( 10 , N ) - 1 ) ; let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { let num = i ; let digits = new Array ( N ) ; for ( let j = N - 1 ; j >= 0 ; j -- ) { digits [ j ] = num % 10 ; num = parseInt ( num / 10 ) ; } let sum = 0 , flag = 0 ; for ( let j = 0 ; j < K ; j ++ ) sum += digits [ j ] ; for ( let j = 1 ; j < N - K + 1 ; j ++ ) { let curr_sum = 0 ; for ( let m = j ; m < j + K ; m ++ ) curr_sum += digits [ m ] ; if ( sum != curr_sum ) { flag = 1 ; break ; } } if ( flag == 0 ) { count ++ ; } } return count ; } let N = 2 , K = 1 ; document . write ( countDigitSum ( N , K ) ) ;

Index/key variables: j, m
Accumulator variables: count, curr_sum, i, j, m, sum
Iterator variables: i, j, m
Javascript program:
function noOfFactors ( N ) { if ( N == 1 ) return 1 ; let count = 0 ; let ans = 1 ; while ( N % 2 == 0 ) { count ++ ; N = N / 2 ; } ans *= ( count / 2 + 1 ) ; for ( let i = 3 ; i * i <= N ; i = i + 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } ans *= ( count / 2 + 1 ) ; } return ans ; } let N = 100 ; document . write ( noOfFactors ( N ) ) ;

Accumulator variables: ans, count
Iterator variables: i
Javascript program:
function DFS ( U , vis , adj ) { vis [ U ] = 1 ; for ( var V of adj [ U ] ) { if ( vis [ V ] == 0 ) DFS ( V , vis , adj ) ; } } function minCost ( N , M , vCost , eCost , sorc , colored , destination ) { var adj = [ ] ; for ( var i = 0 ; i < N + 1 ; i ++ ) adj . push ( new Array ( ) ) ; for ( var i = 0 ; i < M ; i ++ ) { ( adj [ sorc [ i ] ] ) . push ( destination [ i ] ) ; ( adj [ destination [ i ] ] ) . push ( sorc [ i ] ) ; } var vis = Array ( N + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < colored . length ; i ++ ) { DFS ( colored [ i ] , vis , adj ) ; } var X = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( vis [ i ] == 0 ) { X ++ ; DFS ( i , vis , adj ) ; } } var mincost = X * Math . min ( vCost , eCost ) ; document . write ( mincost ) ; } var N = 3 , M = 1 ; var sorc = [ 1 ] ; var destination = [ 2 ] ; var vCost = 3 , eCost = 2 ; var colored = [ ] ; colored . push ( 1 ) ; minCost ( N , M , vCost , eCost , sorc , colored , destination ) ;

Index/key variables: U, V, i
Accumulator variables: X, i
Iterator variables: V, i
Javascript program:
function min_cost ( n , x , p , q ) { if ( x == 1 ) { document . write ( ( n - 1 ) * p + " " ) ; return 0 ; } let ans = ( n - 1 ) * p ; let pre = 0 ; while ( n > 1 ) { let tmp = Math . floor ( n / x ) ; if ( tmp < 0 ) break ; pre += ( n - tmp * x ) * p ; n = Math . floor ( n / x ) pre += q ; ans = Math . min ( ans , pre + ( n - 1 ) * p ) ; } return ans ; } let n = 5 , x = 2 , p = 2 , q = 3 ; document . write ( min_cost ( n , x , p , q ) ) ;

Accumulator variables: pre
Javascript program:
function calculateWays ( arr1 , arr2 , N ) { let A = arr2 [ 0 ] , B = arr2 [ 1 ] ; let C = arr2 [ 2 ] , D = arr2 [ 3 ] ; let ans = 0 ; for ( let b = 0 ; b <= B && b * 5 <= ( N ) ; b ++ ) for ( let c = 0 ; c <= C && b * 5 + c * 10 <= ( N ) ; c ++ ) for ( let d = 0 ; d <= D && b * 5 + c * 10 + d * 20 <= ( N ) ; d ++ ) if ( ( b * 5 ) + ( c * 10 ) + ( d * 20 ) >= ( N - A ) ) ans ++ ; return ans ; } let N = 123 ; let arr1 = [ 1 , 5 , 10 , 20 ] ; let arr2 = [ 6 , 4 , 3 , 5 ] ; document . write ( calculateWays ( arr1 , arr2 , N ) ) ;

Accumulator variables: ans, b, c, d
Iterator variables: b, c, d
Javascript program:
var ways = Array ( 1010 ) . fill ( 0 ) ; function calculateWays ( arr1 , arr2 , N ) { var A = arr2 [ 0 ] , B = arr2 [ 1 ] ; var C = arr2 [ 2 ] , D = arr2 [ 3 ] ; var ans = 0 ; for ( var b = 0 ; b <= B && b * 5 <= N ; b ++ ) { for ( var a = 0 ; a <= A && a * 1 + b * 5 <= N ; a ++ ) { ways [ a + b * 5 ] ++ ; } } for ( var c = 0 ; c <= C && c * 10 <= ( N ) ; c ++ ) { for ( var d = 0 ; d <= D && c * 10 + d * 20 <= ( N ) ; d ++ ) { ans += ways [ N - c * 10 - d * 20 ] ; } } return ans ; } var N = 123 ; var arr1 = [ 1 , 5 , 10 , 20 ] ; var arr2 = [ 6 , 4 , 3 , 5 ] ; document . write ( calculateWays ( arr1 , arr2 , N ) ) ;

Accumulator variables: a, ans, b, c, d
Iterator variables: a, b, c, d
Javascript program:
function maxXORSubsequence ( arr , n ) { let odd = 0 , even = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; else even ++ ; } let maxlen ; if ( odd == n ) { if ( odd % 2 == 0 ) maxlen = n - 1 ; else maxlen = n ; } else if ( even == n ) { maxlen = 0 ; } else { if ( odd % 2 == 0 ) maxlen = even + odd - 1 ; else maxlen = even + odd ; } return maxlen ; } let arr = [ 2 , 3 , 4 , 5 , 6 , 7 ] ; let n = arr . length ; document . write ( maxXORSubsequence ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function good_pair ( str , N ) { let countStr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { let res = str [ i ] + str [ j ] ; let vowel = new Array ( 5 ) ; vowel . fill ( 0 ) ; for ( let k = 0 ; k < res . length ; k ++ ) { if ( res [ k ] == ' ' ) vowel [ 0 ] = 1 ; else if ( res [ k ] == ' ' ) vowel [ 1 ] = 1 ; else if ( res [ k ] == ' ' ) vowel [ 2 ] = 1 ; else if ( res [ k ] == ' ' ) vowel [ 3 ] = 1 ; else if ( res [ k ] == ' ' ) vowel [ 4 ] = 1 ; } let temp = 0 ; for ( let ind = 0 ; ind < 5 ; ind ++ ) { if ( vowel [ ind ] == 1 ) temp ++ ; } if ( temp == 5 ) countStr ++ ; } } return countStr ; } let arr = [ " " , " " ] ; let N = arr . length ; document . write ( good_pair ( arr , N ) ) ;

Index/key variables: i, ind, j, k
Accumulator variables: countStr, i, ind, j, k, temp
Iterator variables: i, ind, j, k
Javascript program:
function sieveOfEratosthenes ( N , s ) { let prime = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; for ( let i = 2 ; i <= N ; i += 2 ) s [ i ] = 2 ; for ( let i = 3 ; i <= N ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( let j = i ; j * i <= N ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } function generatePrimeFactors ( N ) { let s = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; let sum = 0 ; sieveOfEratosthenes ( N , s ) ; let curr = s [ N ] ; let cnt = 1 ; while ( N > 1 ) { N /= s [ N ] ; if ( curr == s [ N ] ) { cnt ++ ; continue ; } sum = sum + cnt ; curr = s [ N ] ; cnt = 1 ; } return sum ; } function findSum ( N ) { let sum = 0 ; for ( let i = 2 ; i <= N ; i ++ ) { sum += generatePrimeFactors ( i ) ; } document . write ( sum + " " ) ; } let N = 4 ; findSum ( N ) ;

Index/key variables: N, i
Accumulator variables: N, cnt, i, j, sum
Iterator variables: i, j
Javascript program:
function LCM ( a , b ) { let lcm = a > b ? a : b ; while ( true ) { if ( lcm % a == 0 && lcm % b == 0 ) break ; else lcm ++ ; } return lcm ; } function findMinLCM ( arr , n ) { let minLCM = Number . MAX_VALUE ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let val = LCM ( arr [ i ] , arr [ i + 1 ] ) ; if ( val < minLCM ) { minLCM = val ; } } document . write ( minLCM + " " ) ; } let arr = [ 4 , 8 , 12 , 16 , 20 , 24 ] ; let n = arr . length ; findMinLCM ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, lcm
Iterator variables: i
Javascript program:
function find_max ( n , k ) { var X = Array . from ( { length : 32 } , ( _ , i ) => 0 ) ; var cnt = 0 ; for ( i = 31 ; i >= 0 && cnt != k ; i -- ) { if ( ( n & ( 1 << i ) ) != 0 ) { X [ i ] = 1 ; cnt ++ ; } } var s = " " ; for ( i = 31 ; i >= 0 ; i -- ) s += X [ i ] == 0 ? ' ' : ' ' ; return parseInt ( s , 2 ) ; } var n = 10 , k = 2 ; document . write ( find_max ( n , k ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, s
Iterator variables: i
Javascript program:
function countUniqueDigits ( N ) { let res = 0 ; let cnt = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ; while ( N > 0 ) { let rem = N % 10 ; cnt [ rem ] ++ ; N = Math . floor ( N / 10 ) ; } for ( let i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] == 1 ) { res ++ ; } } return res ; } let N = 2234262 ; document . write ( countUniqueDigits ( N ) ) ;

Index/key variables: i, rem
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function checkUniqueFrequency ( arr , n ) { let freq = new Map ( ) ; for ( let 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 ) ; } } let uniqueFreq = new Set ( ) ; for ( let [ key , value ] of freq . entries ( ) ) { if ( uniqueFreq . has ( value ) ) return false ; else uniqueFreq . add ( value ) ; } return true ; } let arr = [ 1 , 1 , 2 , 5 , 5 ] ; let n = arr . length ; let res = checkUniqueFrequency ( arr , n ) ; if ( res ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function Permute ( arr , n ) { let odd = 0 , four = 0 ; let non_four = 0 ; let ODD = [ ] ; let FOUR = [ ] ; let NON_FOUR = [ ] ; for ( let x = 0 ; x < arr . length ; x ++ ) { if ( arr [ x ] % 2 != 0 ) { odd ++ ; ODD . push ( arr [ x ] ) ; } else if ( arr [ x ] % 4 == 0 ) { four ++ ; FOUR . push ( arr [ x ] ) ; } else { non_four ++ ; NON_FOUR . push ( arr [ x ] ) ; } } if ( non_four == 0 && four >= odd - 1 ) { let x = ODD . length ; let y = FOUR . length ; let i ; for ( i = 0 ; i < x ; i ++ ) { document . write ( ODD [ i ] + " " ) ; if ( i < y ) document . write ( FOUR [ i ] + " " ) ; } while ( i < y ) document . write ( FOUR [ i ] + " " ) ; document . write ( " " ) ; } else if ( non_four > 0 && four >= odd ) { let x = ODD . length ; let y = FOUR . length ; let i ; for ( i = 0 ; i < x ; i ++ ) { document . write ( ODD [ i ] + " " ) ; if ( i < y ) document . write ( FOUR [ i ] + " " ) ; } while ( i < y ) document . write ( FOUR [ i ] + " " ) ; for ( let j = 0 ; j < NON_FOUR . length ; j ++ ) document . write ( NON_FOUR [ j ] + " " ) ; document . write ( " " ) ; } else document . write ( " " ) ; } let arr = [ 2 , 7 , 1 , 8 , 2 , 8 ] Permute ( arr , arr . length ) ;

Index/key variables: i, j, x
Accumulator variables: four, i, j, non_four, odd, x
Iterator variables: i, j, x
Javascript program:
function Kperiodicinteger ( X , N , K ) { var temp = X for ( var i = 0 ; i < K ; i ++ ) { var j = i ; while ( j < N ) { X [ j ] = X [ i ] ; j += K ; } } if ( parseInt ( X . join ( ' ' ) ) < parseInt ( temp . join ( ' ' ) ) ) { return X . join ( ' ' ) ; } var POS ; for ( var i = K - 1 ; i >= 0 ; i -- ) { if ( X [ i ] != ' ' ) { X [ i ] = String . fromCharCode ( X [ i ] . charCodeAt ( 0 ) + 1 ) ; POS = i ; break ; } } for ( var i = POS + 1 ; i < K ; i ++ ) { X [ i ] = ' ' ; } for ( var i = 0 ; i < K ; i ++ ) { var j = i ; while ( j < N ) { X [ j ] = X [ i ] ; j += K ; } } return X . join ( ' ' ) ; } var N = 4 , K = 2 ; var X = " " ; document . write ( Kperiodicinteger ( X . split ( ' ' ) , N , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
var N = 100000 ; var canTake = 0 ; var best = 0 ; var dp = Array ( N ) . fill ( 0 ) ; var vis = Array ( N ) . fill ( false ) ; function dfs ( g , cost , u , pre ) { vis [ u ] = true ; dp [ u ] = cost [ u ] ; var check = true ; var cur = cost [ u ] ; for ( var x of g [ u ] ) { if ( vis [ x ] && x != pre ) { check = false ; } else if ( ! vis [ x ] ) { check = dfs ( g , cost , x , u ) ? false : true ; cur = Math . max ( cur , cost [ u ] + dp [ x ] ) ; } } dp [ u ] = cur ; if ( ! check ) { canTake += cost [ u ] ; } else { best = Math . max ( best , dp [ u ] ) ; } return check ; } function FindMaxCost ( g , cost , source ) { dfs ( g , cost , source , - 1 ) ; document . write ( canTake + best ) ; } var n = 5 , m = 5 ; var cost = [ 2 , 2 , 8 , 6 , 9 ] ; var g = Array . from ( Array ( n ) , ( ) => Array ( ) ) ; g [ 0 ] . push ( 1 ) ; g [ 1 ] . push ( 0 ) ; g [ 0 ] . push ( 2 ) ; g [ 2 ] . push ( 0 ) ; g [ 0 ] . push ( 3 ) ; g [ 3 ] . push ( 0 ) ; g [ 1 ] . push ( 2 ) ; g [ 2 ] . push ( 1 ) ; g [ 1 ] . push ( 4 ) ; g [ 4 ] . push ( 1 ) ; var source = 1 ; FindMaxCost ( g , cost , source ) ;

Index/key variables: u, x
Accumulator variables: canTake
Iterator variables: x
Boolean variables: check
Javascript program:
var N = 3 ; function after_rev ( v ) { var mini = 0 , count = 0 ; for ( var i = 0 ; i < v . length ; i ++ ) { count += v [ i ] ; if ( count > 0 ) count = 0 ; if ( mini > count ) mini = count ; } return mini ; } function print ( arr ) { var sum = 0 ; for ( var i = 0 ; i < N ; i += 2 ) sum += arr [ i ] ; var v1 = [ ] , v2 = [ ] ; for ( var i = 0 ; i + 1 < N ; i += 2 ) v1 . push ( arr [ i + 1 ] - arr [ i ] ) ; for ( var i = 1 ; i + 1 < N ; i += 2 ) v2 . push ( arr [ i ] - arr [ i + 1 ] ) ; var change = Math . min ( after_rev ( v1 ) , after_rev ( v2 ) ) ; if ( change < 0 ) sum += change ; document . write ( sum ) ; } var arr = [ 0 , 1 , 4 , 3 ] ; print ( arr ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function moduloEquality ( A , B , n , m ) { var mapA = new Map ( ) , mapB = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mapA . has ( A [ i ] ) ) mapA . set ( A [ i ] , mapA . get ( A [ i ] ) + 1 ) else mapA . set ( A [ i ] , 1 ) if ( mapB . has ( B [ i ] ) ) mapB . set ( B [ i ] , mapB . get ( B [ i ] ) + 1 ) else mapB . set ( B [ i ] , 1 ) } var possibleValues = new Set ( ) ; var FirstElement = B [ 0 ] ; for ( var i = 0 ; i < n ; i ++ ) { var cur = A [ i ] ; possibleValues . add ( cur > FirstElement ? m - cur + FirstElement : FirstElement - cur ) ; } var ans = 1000000000 ; possibleValues . forEach ( it => { var possible = true ; mapA . forEach ( ( value , key ) => { if ( value != mapB . get ( ( key + it ) % m ) ) { possible = false ; } } ) ; if ( possible ) { ans = Math . min ( ans , it ) ; } } ) ; return ans ; } var n = 4 ; var m = 3 ; var A = [ 0 , 0 , 2 , 1 ] ; var B = [ 2 , 0 , 1 , 1 ] ; document . write ( moduloEquality ( A , B , n , m ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: possible
Javascript program:
function countCyclicShifts ( S , n ) { let aux = [ ] ; for ( let i = 0 ; i < n ; ++ i ) { if ( S [ i ] == ' ' ) aux [ i ] = 1 ; else aux [ i ] = - 1 ; } let mn = aux [ 0 ] ; for ( let i = 1 ; i < n ; ++ i ) { aux [ i ] += aux [ i - 1 ] ; mn = Math . min ( mn , aux [ i ] ) ; } if ( aux [ n - 1 ] != 0 ) return 0 ; let count = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( aux [ i ] == mn ) count ++ ; } return count ; } let S = " " ; let N = S . length ; document . write ( countCyclicShifts ( S , N ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Javascript program:
function maxProfit ( prices , n ) { let profit = 0 , currentDay = n - 1 ; while ( currentDay > 0 ) { let day = currentDay - 1 ; while ( day >= 0 && ( prices [ currentDay ] > prices [ day ] ) ) { profit += ( prices [ currentDay ] - prices [ day ] ) ; day -- ; } currentDay = day ; } return profit ; } let prices = [ 2 , 3 , 5 ] ; let N = prices . length ; document . write ( maxProfit ( prices , N ) ) ;

Index/key variables: currentDay, day
Accumulator variables: day, profit
Javascript program:
function isOddStringPalindrome ( str , n ) { var oddStringSize = parseInt ( n / 2 ) ; var lengthOdd = ( ( oddStringSize % 2 == 1 ) ? true : false ) ; var s = [ ] ; var i = 1 ; var c = 0 ; while ( i < n && c < parseInt ( oddStringSize / 2 ) ) { s . push ( str [ i ] ) ; i += 2 ; c ++ ; } if ( lengthOdd ) i = i + 2 ; while ( i < n && s . length > 0 ) { if ( s [ s . length - 1 ] == str [ i ] ) s . pop ( ) ; else break ; i = i + 2 ; } if ( s . length == 0 ) return true ; return false ; } var N = 10 ; var s = " " ; if ( isOddStringPalindrome ( s , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: c, i
Javascript program:
function isOddStringPalindrome ( str , n ) { var left , right ; if ( n % 2 == 0 ) { left = 1 ; right = n - 1 ; } else { left = 1 ; right = n - 2 ; } while ( left < n && right >= 0 && left < right ) { if ( str [ left ] != str [ right ] ) return false ; left += 2 ; right -= 2 ; } return true ; } var n = 10 ; var s = " " ; if ( isOddStringPalindrome ( s , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: left, right
Accumulator variables: left, right
Javascript program:
function min_remove ( str ) { let N = str . length ; let prefix_a = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; let prefix_b = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; let prefix_c = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; prefix_a [ 0 ] = 0 ; prefix_b [ 0 ] = 0 ; prefix_c [ 0 ] = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { prefix_a [ i ] = prefix_a [ i - 1 ] + ( ( str [ i - 1 ] == ' ' ) ? 1 : 0 ) ; prefix_b [ i ] = prefix_b [ i - 1 ] + ( ( str [ i - 1 ] == ' ' ) ? 1 : 0 ) ; prefix_c [ i ] = prefix_c [ i - 1 ] + ( ( str [ i - 1 ] == ' ' ) ? 1 : 0 ) ; } let maxi = Number . MIN_VALUE ; for ( let i = 0 ; i <= N ; i ++ ) { for ( let j = i ; j <= N ; j ++ ) { maxi = Math . max ( maxi , ( prefix_a [ i ] + ( prefix_b [ j ] - prefix_b [ i ] ) + ( prefix_c [ N ] - prefix_c [ j ] ) ) ) ; } } document . write ( ( N - maxi ) ) ; } let str = " " ; min_remove ( str ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function createArray ( n , s ) { if ( 2 * n <= s ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { document . write ( 2 + " " ) ; s -= 2 ; } document . write ( s + " " ) ; document . write ( 1 ) ; } else document . write ( " " ) ; } let N = 1 ; let S = 4 ; createArray ( N , S ) ;

Accumulator variables: i, s
Iterator variables: i
Javascript program:
function maximum_partition ( str ) { var i = 0 , j = 0 , k = 0 ; var c = 0 , r = 0 ; var m = new Map ( ) ; for ( i = str . length - 1 ; i >= 0 ; i -- ) { if ( ! m . has ( str [ i ] ) ) { m . set ( str [ i ] , i ) ; } } i = 0 ; k = m . get ( str [ i ] ) ; for ( i = 0 ; i < str . length ; i ++ ) { if ( i <= k ) { c = c + 1 ; k = Math . max ( k , m . get ( str [ i ] ) ) ; } else { r = r + 1 ; c = 1 ; k = Math . max ( k , m . get ( str [ i ] ) ) ; } } if ( c != 0 ) { r = r + 1 ; } return r ; } var str = " " ; document . write ( maximum_partition ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findAns ( mat , x , y , n , m ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { ans += Math . abs ( x - i ) + Math . abs ( y - j ) ; } } } return ans ; } let mat = [ [ 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 ] , [ 1 , 0 , 1 , 1 ] ] ; let x = 0 , y = 2 ; document . write ( findAns ( mat , x , y , mat . length , mat [ 0 ] . length ) + " " ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countReversebitonic ( arr , n ) { let c = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let temp = arr [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } let k = i + 1 ; while ( temp > arr [ k ] && k <= j ) { temp = arr [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = 2 ; } while ( k <= j && temp < arr [ k ] && f != 2 ) { temp = arr [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } document . write ( c + " " ) ; } let arr = [ 2 , 3 , 1 , 4 ] ; let N = arr . length ; countReversebitonic ( arr , N ) ;

Index/key variables: i, k
Accumulator variables: c, i, j, k
Iterator variables: i, j
Javascript program:
function longestSequence ( n , arr ) { var l = 0 , r = n - 1 ; var prev = - 1000000000 ; var ans = 0 ; while ( l <= r ) { if ( arr [ l ] > prev && arr [ r ] > prev ) { if ( arr [ l ] < arr [ r ] ) { ans += 1 ; prev = arr [ l ] ; l += 1 ; } else { ans += 1 ; prev = arr [ r ] ; r -= 1 ; } } else if ( arr [ l ] > prev ) { ans += 1 ; prev = arr [ l ] ; l += 1 ; } else if ( arr [ r ] > prev ) { ans += 1 ; prev = arr [ r ] ; r -= 1 ; } else { break ; } } return ans ; } var arr = [ 3 , 5 , 1 , 4 , 2 ] ; var n = arr . length ; document . write ( longestSequence ( n , arr ) ) ;

Index/key variables: l, r
Accumulator variables: ans, l, r
Javascript program:
function solve ( n , m , x , y , d ) { let top = Math . min ( d , x - 1 ) ; let down = Math . min ( d , n - x ) ; let left = Math . min ( d , y - 1 ) ; let right = Math . min ( d , m - y ) ; let quad1 = top * left ; let quad2 = left * down ; let quad3 = down * right ; let quad4 = right * top ; let totalsq = quad1 + quad2 + quad3 + quad4 ; let singleBlocks = top + down + left + right + 1 ; return totalsq + singleBlocks ; } let n = 10 , m = 10 ; let x = 7 , y = 8 ; let d = 4 ; d -- ; document . write ( solve ( n , m , x , y , d ) ) ;

Accumulator variables: d
Javascript program:
var M = 3 var N = 3 ; function minchanges ( mat ) { var count = 0 ; var left = 0 , right = N + M - 2 ; while ( left < right ) { var mp = new Map ( ) ; var totalsize = 0 ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { if ( i + j == left i + j == right ) { if ( mp . has ( mat [ i ] [ j ] ) ) mp . set ( mat [ i ] [ j ] , mp . get ( mat [ i ] [ j ] ) + 1 ) else mp . set ( mat [ i ] [ j ] , 1 ) totalsize ++ ; } } } var changes = 0 ; mp . forEach ( ( value , key ) => { changes = Math . max ( changes , value ) ; } ) ; count += totalsize - changes ; left ++ ; right -- ; } return count ; } var mat = [ [ 1 , 4 , 1 ] , [ 2 , 5 , 3 ] , [ 1 , 3 , 1 ] ] ; document . write ( minchanges ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, left, right, totalsize
Iterator variables: i, j
Javascript program:
function CountLongestSubarrays ( arr , n , k ) { let i , s = 0 ; for ( i = 0 ; i < n ; ++ i ) { s += arr [ i ] ; } if ( ( s % k ) != 0 ) { return 1 ; } else { let ini = 0 ; while ( ini < n && arr [ ini ] % k == 0 ) { ++ ini ; } let fin = n - 1 ; while ( fin >= 0 && arr [ fin ] % k == 0 ) { -- fin ; } let len , sum = 0 , count = 0 ; if ( ini == n ) { return - 1 ; } else { len = Math . max ( n - 1 - ini , fin ) ; } for ( i = 0 ; i < len ; i ++ ) { sum += arr [ i ] ; } if ( sum % k != 0 ) { count ++ ; } for ( i = len ; i < n ; i ++ ) { sum = sum + arr [ i ] ; sum = sum - arr [ i - len ] ; if ( sum % k != 0 ) { count ++ ; } } return count ; } } let arr = [ 3 , 2 , 2 , 2 , 3 ] ; let n = arr . length ; let k = 3 ; document . write ( CountLongestSubarrays ( arr , n , k ) ) ;

Index/key variables: fin, i, ini
Accumulator variables: count, i, s, sum
Iterator variables: i