dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxProfit ( value , N , K ) { value . sort ( ) ; let maxval = value [ N - 1 ] ; let maxProfit = 0 ; let curr_val ; do { curr_val = 0 ; for ( let i = 0 ; i < N ; i ++ ) { curr_val += value [ i ] ; if ( curr_val <= K ) { maxProfit = Math . max ( curr_val + maxval * ( i + 1 ) , maxProfit ) ; } } } while ( next_permutation ( value ) ) ; return maxProfit ; } function next_permutation ( p ) { for ( let a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( let b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { let t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } let N = 4 , K = 6 ; let values = [ 5 , 2 , 7 , 3 ] ; document . write ( maxProfit ( values , N , K ) ) ;

Index/key variables: a, b, i
Accumulator variables: curr_val, i
Iterator variables: a, b, i
Javascript program:
function minValue ( n ) { while ( parseInt ( Math . sqrt ( n ) ) == Math . sqrt ( n ) && n > 1 ) { n = parseInt ( Math . sqrt ( n ) ) ; } for ( var i = parseInt ( Math . sqrt ( n ) ) ; i > 1 ; i -- ) { while ( n % ( i * i ) == 0 ) n /= i ; } document . write ( n ) ; } var N = 20 ; minValue ( N ) ;

Accumulator variables: i, n
Iterator variables: i
Javascript program:
function isPalindrome ( l , r , s ) { while ( l <= r ) { if ( s [ l ] != s [ r ] ) return false ; l ++ ; r -- ; } return true ; } function numWays ( s ) { let n = s . length ; let ans = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( isPalindrome ( 0 , i , s ) && isPalindrome ( i + 1 , n - 1 , s ) ) { ans ++ ; } } return ans ; } let S = " " ; document . write ( numWays ( S ) ) ;

Index/key variables: l, r
Accumulator variables: ans, i, l, r
Iterator variables: i
Javascript program:
function maxModulosum ( a , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } return sum - n ; } let a = [ 3 , 4 , 6 ] ; let n = a . length ; document . write ( maxModulosum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function getMinJumps ( s ) { let ones = [ ] ; let jumps = 0 , median = 0 , ind = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) ones . push ( i ) ; } if ( ones . length == 0 ) return jumps ; median = ones [ parseInt ( ones . length / 2 , 10 ) ] ; ind = median ; for ( let i = ind ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' ) { jumps += ind - i ; ind -- ; } } ind = median ; for ( let i = ind ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { jumps += i - ind ; ind ++ ; } } return jumps ; } let S = " " ; document . write ( getMinJumps ( S ) ) ;

Index/key variables: i
Accumulator variables: i, ind, jumps
Iterator variables: i
Javascript program:
var N = 100005 ; var v = Array . from ( Array ( N ) , ( ) => Array ( ) ) ; var val = Array ( N ) ; var answer = Array ( N ) ; var n ; function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function DFS ( node , parent ) { answer [ node ] = val [ node ] ; v [ node ] . forEach ( child => { if ( child != parent ) { DFS ( child , node ) ; answer [ node ] = gcd ( answer [ node ] , answer [ child ] ) ; } } ) ; } function preprocess ( ) { DFS ( 1 , - 1 ) ; } function findGCD ( queries , q ) { preprocess ( ) ; for ( var i = 0 ; i < q ; i ++ ) { var GCD = answer [ queries [ i ] ] ; document . write ( " " + queries [ i ] + " " + GCD + " " ) ; } } n = 5 ; v [ 1 ] . push ( 2 ) ; v [ 2 ] . push ( 1 ) ; v [ 1 ] . push ( 3 ) ; v [ 3 ] . push ( 1 ) ; v [ 3 ] . push ( 4 ) ; v [ 4 ] . push ( 3 ) ; v [ 3 ] . push ( 5 ) ; v [ 5 ] . push ( 3 ) ; val [ 1 ] = 2 ; val [ 2 ] = 3 ; val [ 3 ] = 4 ; val [ 4 ] = 8 ; val [ 5 ] = 16 ; var queries = [ 2 , 3 , 1 ] ; var q = queries . length ; findGCD ( queries , q ) ;

Index/key variables: child, i, node
Accumulator variables: i
Iterator variables: i
Javascript program:
function makeZero ( x , y , a , b ) { if ( x > y ) { let temp = x ; x = y ; y = temp ; } let tot_cost = ( y - x ) * a ; let cost1 = 2 * x * a ; let cost2 = x * b ; tot_cost += Math . min ( cost1 , cost2 ) ; document . write ( tot_cost ) ; } let X = 1 , Y = 3 ; let cost1 = 391 , cost2 = 555 ; makeZero ( X , Y , cost1 , cost2 ) ;

Accumulator variables: tot_cost
Javascript program:
function splitFraction ( n , d ) { var ar = new Array ( n ) ; var first = d + n - 1 ; ar [ 0 ] = first ; for ( var i = 1 ; i < n ; i ++ ) { ar [ i ] = first * -- first ; } for ( var i = 0 ; i < n ; i ++ ) { if ( ar [ i ] % n === 0 ) { document . write ( " " + ar [ i ] / n + " " ) ; } else { document . write ( n + " " + ar [ i ] + " " ) ; } } } var N = 4 ; var D = 2 ; splitFraction ( N , D ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function numPairs ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) ans ++ ; } } return ans ; } let arr = [ 1 , 1 , 2 , 2 , 3 , 3 ] ; let n = arr . length ; document . write ( numPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function check ( arr , n ) { var flag = true ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < n - i ) { flag = false ; } } if ( flag ) { return true ; } else { return false ; } } let arr1 = [ 11 , 11 , 11 , 11 ] ; let n1 = arr1 . length ; if ( check ( arr1 , n1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function BalancedPartition ( str , n ) { if ( n == 0 ) return 0 ; let r = 0 , l = 0 ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { r ++ ; } else if ( str [ i ] == ' ' ) { l ++ ; } if ( r == l ) { ans ++ ; } } return ans ; } let str = " " ; let n = str . length ; document . write ( BalancedPartition ( str , n ) + " " ) ;

Index/key variables: i
Accumulator variables: ans, i, l, r
Iterator variables: i
Javascript program:
function minOccupiedPosition ( A , n ) { var minPos = 0 ; for ( var i = 0 ; i < n ; ++ i ) { if ( A [ i ] > 0 ) { ++ minPos ; i += 2 ; } } return minPos ; } var A = [ 8 , 0 , 7 , 0 , 0 , 6 ] ; var n = A . length ; document . write ( minOccupiedPosition ( A , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinimumK ( a , n , S ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } return Math . ceil ( ( ( S + 1 ) * 1.0 ) / ( sum * 1.0 ) ) ; } let a = [ 10 , 7 , 8 , 10 , 12 , 19 ] ; let n = a . length ; let S = 200 ; document . write ( findMinimumK ( a , n , S ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function largestNum ( n ) { let num = 0 ; for ( let i = 0 ; i <= 32 ; i ++ ) { let x = ( 1 << i ) ; if ( ( x - 1 ) <= n ) num = ( 1 << i ) - 1 ; else break ; } return num ; } let N = 345 ; document . write ( largestNum ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findString ( N , K ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( String . fromCharCode ( ' ' . charCodeAt ( ) + i % K ) ) ; } } let N = 10 ; let K = 3 ; findString ( N , K ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( s ) { let N , i , cnt = 0 , ans = 0 ; N = s . length ; for ( i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' ' ) cnt ++ ; if ( s [ i ] == ' ' ) ans += cnt ; } return ans ; } let s = " " ; document . write ( count ( s ) ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function findMinimumSubsequences ( A , B ) { let numberOfSubsequences = 1 ; let sizeOfB = B . length ; let sizeOfA = A . length ; let inf = 1000000 ; let next = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { next [ i ] = new Array ( sizeOfB ) ; for ( let j = 0 ; j < sizeOfB ; j ++ ) { next [ i ] [ j ] = inf ; } } for ( let i = 0 ; i < sizeOfB ; i ++ ) { next [ B [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ i ] = i ; } for ( let i = 0 ; i < 26 ; i ++ ) { for ( let j = sizeOfB - 2 ; j >= 0 ; j -- ) { if ( next [ i ] [ j ] == inf ) { next [ i ] [ j ] = next [ i ] [ j + 1 ] ; } } } let pos = 0 ; let i = 0 ; while ( i < sizeOfA ) { if ( pos == 0 && next [ A [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ pos ] == inf ) { numberOfSubsequences = - 1 ; break ; } else if ( pos < sizeOfB && next [ A [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ pos ] < inf ) { let nextIndex = next [ A [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ pos ] + 1 ; pos = nextIndex ; i ++ ; } else { numberOfSubsequences ++ ; pos = 0 ; } } return numberOfSubsequences ; } let A = " " ; let B = " " ; document . write ( findMinimumSubsequences ( A , B ) ) ;

Index/key variables: i, j, pos
Accumulator variables: i, j, numberOfSubsequences
Iterator variables: i, j
Javascript program:
function horizontalFill ( records , tape , nt ) { let sum = 0 ; let Retrieval_Time = 0 ; let Mrt ; let current = 0 ; let v = [ ] ; for ( let i = 0 ; i < nt ; i ++ ) { v = [ ] ; Retrieval_Time = 0 ; sum = 0 ; document . write ( " " + ( i + 1 ) + " " ) ; sum += records [ current ] ; while ( sum <= tape [ i ] ) { document . write ( records [ current ] + " " ) ; v . push ( records [ current ] ) ; current ++ ; sum += records [ current ] ; } document . write ( " " ) ; for ( let j = 0 ; j < v . length ; j ++ ) { Retrieval_Time += v [ j ] * ( v . length - j ) ; } Mrt = Retrieval_Time / v . length ; if ( i == 0 ) { document . write ( " " + Mrt . toFixed ( 4 ) + " " ) ; } else { document . write ( " " + Mrt + " " ) ; } } } let records = [ 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 ] ; let tape = [ 25 , 80 , 160 ] ; let n = records . length ; let m = tape . length ; records . sort ( function ( a , b ) { return a - b } ) ; horizontalFill ( records , tape , m ) ;

Index/key variables: current, i, j
Accumulator variables: Retrieval_Time, current, i, j, sum
Iterator variables: i, j
Javascript program:
let MAX_SIZE = 10 ; function convolution ( x , h , n , m ) { let row_vec = new Array ( MAX_SIZE ) ; row_vec . fill ( 0 ) ; let col_vec = new Array ( MAX_SIZE ) ; col_vec . fill ( 0 ) ; let out = new Array ( MAX_SIZE ) ; out . fill ( 0 ) ; let circular_shift_mat = new Array ( MAX_SIZE ) ; circular_shift_mat . fill ( 0 ) ; for ( let i = 0 ; i < MAX_SIZE ; i ++ ) { circular_shift_mat [ i ] = new Array ( MAX_SIZE ) ; for ( let j = 0 ; j < MAX_SIZE ; j ++ ) { circular_shift_mat [ i ] [ j ] = 0 ; } } let maxSize = n > m ? n : m ; for ( let i = 0 ; i < maxSize ; i ++ ) { if ( i >= n ) { row_vec [ i ] = 0 ; } else { row_vec [ i ] = x [ i ] ; } } for ( let i = 0 ; i < maxSize ; i ++ ) { if ( i >= m ) { col_vec [ i ] = 0 ; } else { col_vec [ i ] = h [ i ] ; } } let k = 0 , d = 0 ; for ( let i = 0 ; i < maxSize ; i ++ ) { let curIndex = k - d ; for ( let j = 0 ; j < maxSize ; j ++ ) { circular_shift_mat [ j ] [ i ] = row_vec [ curIndex % maxSize ] ; curIndex ++ ; } k = maxSize ; d ++ ; } for ( let i = 0 ; i < maxSize ; i ++ ) { for ( let j = 0 ; j < maxSize ; j ++ ) { out [ i ] += circular_shift_mat [ i ] [ j ] * col_vec [ j ] ; } document . write ( out [ i ] + " " ) ; } } let x = [ 5 , 7 , 3 , 2 ] ; let n = x . length ; let h = [ 1 , 5 ] ; let m = h . length ; convolution ( x , h , n , m ) ;

Index/key variables: i, j
Accumulator variables: curIndex, d, i, j
Iterator variables: i, j
Javascript program:
function max_palindrome ( s , n ) { let flag = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] . length % 2 != 0 ) { flag = 1 ; } } if ( flag == 1 ) { return n ; } let z = 0 ; let o = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < s [ i ] . length ; j ++ ) { if ( s [ i ] [ j ] == ' ' ) z += 1 ; else o += 1 ; } } if ( o % 2 == 0 && z % 2 == 0 ) { return n ; } else { return n - 1 ; } } let n = 3 ; let s = [ " " , " " , " " ] ; document . write ( max_palindrome ( s , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, o, z
Iterator variables: i, j
Javascript program:
function minCost ( cost , n ) { var totalCost = 0 ; var boardingBus = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( cost [ boardingBus ] > cost [ i ] ) { totalCost += ( ( i - boardingBus ) * cost [ boardingBus ] ) ; boardingBus = i ; } } totalCost += ( ( n - boardingBus ) * cost [ boardingBus ] ) ; return totalCost ; } var cost = [ 4 , 7 , 8 , 3 , 4 ] ; var n = cost . length ; document . write ( minCost ( cost , n ) ) ;

Index/key variables: boardingBus, i
Accumulator variables: i, totalCost
Iterator variables: i
Javascript program:
function minFlipsSub ( mat , i , j ) { var cnt0 = 0 , cnt1 = 0 ; if ( mat [ i ] . charAt ( j ) == ' ' ) cnt1 ++ ; else cnt0 ++ ; if ( mat [ i ] . charAt ( j + 1 ) == ' ' ) cnt1 ++ ; else cnt0 ++ ; if ( mat [ i + 1 ] . charAt ( j ) == ' ' ) cnt1 ++ ; else cnt0 ++ ; if ( mat [ i + 1 ] . charAt ( j + 1 ) == ' ' ) cnt1 ++ ; else cnt0 ++ ; return Math . min ( cnt0 , cnt1 ) ; } function minFlips ( mat , r , c ) { var res = Number . MAX_VALUE ; for ( i = 0 ; i < r - 1 ; i ++ ) { for ( j = 0 ; j < c - 1 ; j ++ ) { res = Math . min ( res , minFlipsSub ( mat , i , j ) ) ; } } return res ; } var mat = [ " " , " " , " " ] ; var r = mat . length ; var c = mat [ 0 ] . length ; document . write ( minFlips ( mat , r , c ) ) ;

Index/key variables: i
Accumulator variables: cnt0, cnt1, i, j
Iterator variables: i, j
Javascript program:
function findK ( n , k ) { let pos ; if ( n % 2 == 0 ) { pos = parseInt ( n / 2 , 10 ) ; } else { pos = parseInt ( n / 2 , 10 ) + 1 ; } if ( k <= pos ) { return ( k * 2 - 1 ) ; } else { return ( ( k - pos ) * 2 ) ; } } function countSetBits ( n , k ) { let kth = findK ( n , k ) ; let count = 0 ; while ( kth > 0 ) { count += kth & 1 ; kth >>= 1 ; } return count ; } let n = 18 , k = 12 ; document . write ( countSetBits ( n , k ) ) ;

Accumulator variables: count
Javascript program:
function minCost ( str1 , str2 , n ) { let cost = 0 ; let array = str1 . split ( ' ' ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( str1 [ i ] != str2 [ i ] ) { if ( i < n - 1 && str1 [ i + 1 ] != str2 [ i + 1 ] ) { let temp = array [ i ] ; array [ i ] = array [ i + 1 ] ; array [ i + 1 ] = temp ; cost ++ ; } else { cost ++ ; } } } return cost ; } let str1 = " " , str2 = " " ; let n = str1 . length ; document . write ( minCost ( str1 , str2 , n ) ) ;

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Javascript program:
function CheckForSequence ( arr , n , k ) { for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( k >= arr [ i ] ) k -= arr [ i ] ; } if ( k != 0 ) return false ; else return true ; } var A = [ 1 , 3 , 7 , 15 , 31 ] ; var n = A . length ; document . write ( ( CheckForSequence ( A , n , 18 ) ? " " : " " ) + " " ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function generateArray ( n , k ) { var array = Array ( k ) . fill ( 0 ) ; var remaining = n - parseInt ( k * ( k + 1 ) / 2 ) ; if ( remaining < 0 ) document . write ( " " ) ; var right_most = remaining % k ; var high = parseInt ( Math . ceil ( remaining / ( k * 1.0 ) ) ) ; var low = parseInt ( Math . floor ( remaining / ( k * 1.0 ) ) ) ; for ( i = k - right_most ; i < k ; i ++ ) array [ i ] = high ; for ( i = 0 ; i < ( k - right_most ) ; i ++ ) array [ i ] = low ; for ( i = 0 ; i < k ; i ++ ) array [ i ] += i + 1 ; if ( k - 1 != remaining k == 1 ) { for ( var u = 0 ; u < array . length ; u ++ ) document . write ( array [ u ] + " " ) ; } else if ( k == 2 k == 3 ) document . write ( " " ) ; else { array [ 1 ] -= 1 ; array [ k - 1 ] += 1 ; for ( var f = 0 ; f < array . length ; f ++ ) document . write ( array [ f ] + " " ) ; } } var n = 26 , k = 6 ; generateArray ( n , k ) ;

Index/key variables: f, i, u
Accumulator variables: f, i, u
Iterator variables: f, i, u
Javascript program:
function get_maximum ( s , a ) { let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) < a [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ) { let j = i ; while ( j < n && ( s [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) <= a [ s [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ) ) { s [ j ] = String . fromCharCode ( ' ' . charCodeAt ( ) + a [ s [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ) ; j ++ ; } return s . join ( " " ) ; } } return s . join ( " " ) ; } let s = " " ; let a = [ 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 ] ; document . write ( get_maximum ( s . split ( ' ' ) , a ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function countSteps ( n ) { let steps = 0 ; while ( n ) { let largest = Math . floor ( Math . sqrt ( n ) ) ; n -= ( largest * largest ) ; steps ++ ; } return steps ; } let n = 85 ; document . write ( countSteps ( n ) ) ;

Accumulator variables: n, steps
Javascript program:
function sumArr ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } function maxSum ( arr , n , k ) { arr . sort ( function ( a , b ) { return a - b } ) ; let i = 0 ; while ( i < n && k > 0 && arr [ i ] < 0 ) { arr [ i ] *= - 1 ; k -- ; i ++ ; } if ( k % 2 == 1 ) { let min = 0 ; for ( i = 1 ; i < n ; i ++ ) if ( arr [ min ] > arr [ i ] ) min = i ; arr [ min ] *= - 1 ; } return sumArr ( arr , n ) ; } let arr = [ - 5 , 4 , 1 , 3 , 2 ] ; let n = arr . length ; let k = 4 ; document . write ( maxSum ( arr , n , k ) ) ;

Index/key variables: i, min
Accumulator variables: i, k, sum
Iterator variables: i
Javascript program:
let par , rank ; function find ( x ) { if ( par [ x ] != x ) par [ x ] = find ( par [ x ] ) ; return par [ x ] ; } function union ( u , v ) { let x = find ( u ) ; let y = find ( v ) ; if ( x == y ) return ; if ( rank [ x ] > rank [ y ] ) par [ y ] = x ; else if ( rank [ x ] < rank [ y ] ) par [ x ] = y ; else { par [ x ] = y ; rank [ y ] ++ ; } } function findSpanningTree ( deg , n , m , g ) { par = new Array ( n + 1 ) ; rank = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) par [ i ] = i ; let max = 1 ; for ( let i = 2 ; i <= n ; i ++ ) if ( deg [ i ] > deg [ max ] ) max = i ; for ( let v = 0 ; v < g [ max ] . length ; v ++ ) { document . write ( max + " " + g [ max ] [ v ] + " " ) ; union ( max , g [ max ] [ v ] ) ; } for ( let u = 1 ; u <= n ; u ++ ) { for ( let v = 0 ; v < g [ u ] . length ; v ++ ) { let x = find ( u ) ; let y = find ( g [ u ] [ v ] ) ; if ( x == y ) continue ; union ( x , y ) ; document . write ( u + " " + g [ u ] [ v ] + " " ) ; } } } let n = 5 ; let m = 5 ; let g = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) g [ i ] = [ ] ; let deg = new Array ( n + 1 ) ; deg . fill ( 0 ) ; g [ 1 ] . push ( 2 ) ; g [ 2 ] . push ( 1 ) ; deg [ 1 ] ++ ; deg [ 2 ] ++ ; g [ 1 ] . push ( 5 ) ; g [ 5 ] . push ( 1 ) ; deg [ 1 ] ++ ; deg [ 5 ] ++ ; g [ 2 ] . push ( 3 ) ; g [ 3 ] . push ( 2 ) ; deg [ 2 ] ++ ; deg [ 3 ] ++ ; g [ 5 ] . push ( 3 ) ; g [ 3 ] . push ( 5 ) ; deg [ 3 ] ++ ; deg [ 5 ] ++ ; g [ 3 ] . push ( 4 ) ; g [ 4 ] . push ( 3 ) ; deg [ 3 ] ++ ; deg [ 4 ] ++ ; findSpanningTree ( deg , n , m , g ) ;

Index/key variables: i, max, u, v, x, y
Accumulator variables: i, u, v
Iterator variables: i, u, v
Javascript program:
function Maxsum ( c1 , c2 , c3 , c4 ) { let sum = 0 ; let two34 = Math . min ( c2 , Math . min ( c3 , c4 ) ) ; sum = two34 * 234 ; c2 -= two34 ; sum += Math . min ( c2 , c1 ) * 12 ; return sum ; } let c1 = 5 , c2 = 2 , c3 = 3 , c4 = 4 ; document . write ( Maxsum ( c1 , c2 , c3 , c4 ) ) ;

Accumulator variables: c2, sum
Javascript program:
function printArray ( N , arr ) { for ( var i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } function replacedArray ( N , arr ) { var pos_sum , neg_sum , i , j , diff ; pos_sum = 0 ; neg_sum = 0 ; for ( i = N - 1 ; i >= 0 ; i -- ) { diff = Math . abs ( pos_sum ) - Math . abs ( neg_sum ) ; if ( arr [ i ] > 0 ) pos_sum += arr [ i ] ; else neg_sum += arr [ i ] ; arr [ i ] = Math . abs ( diff ) ; } } var N = 5 ; var arr = [ 1 , - 1 , 2 , 3 , - 2 ] ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; var arr1 = [ - 3 , - 4 , - 2 , 5 , 1 , - 2 ] ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ;

Index/key variables: i
Accumulator variables: i, neg_sum, pos_sum
Iterator variables: i
Javascript program:
function findCountOfPairs ( a , b , n ) { let ans = 0 ; ans += n * parseInt ( a / n , 10 ) * parseInt ( b / n , 10 ) ans += parseInt ( a / n , 10 ) * parseInt ( b % n , 10 ) ; ans += parseInt ( a % n , 10 ) * parseInt ( b / n , 10 ) ; ans += parseInt ( ( ( a % n ) + ( b % n ) ) / n , 10 ) ; return ans ; } let a = 5 , b = 13 , n = 3 ; document . write ( findCountOfPairs ( a , b , n ) ) ;

Accumulator variables: ans
Javascript program:
function findArray ( N , P ) { let ans = parseInt ( ( P * ( P + 1 ) ) / 2 , 10 ) + ( N - P ) ; let arr = new Array ( N + 1 ) ; for ( let i = 1 ; i <= P ; i ++ ) { arr [ i ] = i ; } for ( let i = P + 1 ; i <= N ; i ++ ) { arr [ i ] = 1 ; } document . write ( " " + ans + " " ) ; document . write ( " " + " " ) ; for ( let i = 1 ; i <= N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let N = 5 , P = 3 ; findArray ( N , P ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findIntersection ( intervals , N ) { let l = intervals [ 0 ] [ 0 ] ; let r = intervals [ 0 ] [ 1 ] ; for ( let i = 1 ; i < N ; i ++ ) { if ( intervals [ i ] [ 0 ] > r intervals [ i ] [ 1 ] < l ) { document . write ( - 1 + " " ) ; return ; } else { l = Math . max ( l , intervals [ i ] [ 0 ] ) ; r = Math . min ( r , intervals [ i ] [ 1 ] ) ; } } document . write ( " " + l + " " + r + " " + " " ) ; } let intervals = [ [ 1 , 6 ] , [ 2 , 8 ] , [ 3 , 10 ] , [ 5 , 8 ] ] ; let N = intervals . length ; findIntersection ( intervals , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function cmp ( a , b ) { if ( a > b ) return 1 ; else if ( a == b ) return 0 ; else return - 1 ; } function maxSubarraySize ( arr , n ) { var ans = 1 ; var anchor = 0 ; for ( i = 1 ; i < n ; i ++ ) { var c = cmp ( arr [ i - 1 ] , arr [ i ] ) ; if ( c == 0 ) anchor = i ; else if ( i == n - 1 || c * cmp ( arr [ i ] , arr [ i + 1 ] ) != - 1 ) { ans = Math . max ( ans , i - anchor + 1 ) ; anchor = i ; } } return ans ; } var arr = [ 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 ] ; var n = arr . length ; document . write ( maxSubarraySize ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubStrings ( s , k ) { var maxSubStr = 0 , n = s . length ; for ( var c = 0 ; c < 26 ; c ++ ) { var ch = String . fromCharCode ( " " . charCodeAt ( 0 ) + c ) ; var curr = 0 ; for ( var i = 0 ; i <= n - k ; i ++ ) { if ( s [ i ] !== ch ) continue ; var cnt = 0 ; while ( i < n && s [ i ] === ch && cnt !== k ) { i ++ ; cnt ++ ; } i -- ; if ( cnt === k ) curr ++ ; } maxSubStr = Math . max ( maxSubStr , curr ) ; } return maxSubStr ; } var s = " " ; var k = 2 ; document . write ( maxSubStrings ( s , k ) ) ;

Index/key variables: i
Accumulator variables: c, cnt, curr, i
Iterator variables: c, i
Javascript program:
function ValidPairs ( arr , n ) { var count = Array ( 121 ) . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] += 1 ; var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) continue ; if ( Math . abs ( arr [ i ] - arr [ j ] ) % 2 == 1 ) continue ; ans += count [ arr [ i ] ] * count [ arr [ j ] ] ; if ( arr [ i ] == arr [ j ] ) ans -= count [ arr [ i ] ] ; } return ans ; } var arr = [ 16 , 17 , 18 ] ; var n = arr . length ; document . write ( ValidPairs ( arr , n ) ) ;

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