dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function number ( a , n , p , k ) { a . sort ( ) ; var pre = Array ( n ) . fill ( 0 ) , val , i , j , ans = 0 ; pre [ 0 ] = a [ 0 ] ; if ( pre [ 0 ] <= p ) ans = 1 ; for ( i = 1 ; i < k - 1 ; i ++ ) { pre [ i ] = pre [ i - 1 ] + a [ i ] ; if ( pre [ i ] <= p ) ans = i + 1 ; } pre [ k - 1 ] = a [ k - 1 ] ; for ( i = k - 1 ; i < n ; i ++ ) { if ( i >= k ) { pre [ i ] += pre [ i - k ] + a [ i ] ; } if ( pre [ i ] <= p ) ans = i + 1 ; } return ans ; } var n = 5 ; var arr = [ 2 , 4 , 3 , 5 , 7 ] ; var p = 11 ; var k = 2 ; document . write ( number ( arr , n , p , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sieveOfEratosthenes ( prime , n ) { prime [ 0 ] = prime [ 1 ] = false ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function sortSpecialPrimes ( arr , n ) { let maxVal = Math . max ( ... arr ) ; let prime = Array . from ( { length : maxVal + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < prime . length ; i ++ ) prime [ i ] = true ; sieveOfEratosthenes ( prime , maxVal ) ; let list = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] && prime [ arr [ i ] - 2 ] ) { list . push ( arr [ i ] ) ; arr [ i ] = - 1 ; } } list . sort ( ( a , b ) => a - b ) ; let j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == - 1 ) document . write ( list [ j ++ ] + " " ) ; else document . write ( arr [ i ] + " " ) ; } } let arr = [ 31 , 5 , 2 , 1 , 7 ] ; let n = arr . length ; sortSpecialPrimes ( arr , n ) ;

Index/key variables: i, p
Accumulator variables: i, j, p
Iterator variables: i, p
Javascript program:
function maxProfit ( arr ) { arr . sort ( ) ; arr . reverse ( ) ; let ans = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( ( arr [ i ] - ( 1 * i ) ) > 0 ) ans += ( arr [ i ] - ( 1 * i ) ) ; if ( ( arr [ i ] - ( 1 * i ) ) == 0 ) break ; } return ans ; } let arr = [ 6 , 6 , 6 ] ; document . write ( maxProfit ( arr ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function check_vector ( A , n , p ) { var pos = A . length ; for ( var i = 0 ; i < p . length ; i ++ ) { pos [ p [ i ] - 1 ] = 1 ; } var flag = 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( pos [ i ] == 0 ) continue ; var j = i ; while ( j < n && pos [ j ] ) ++ j ; A = Array . prototype . concat ( A . slice ( 0 , i ) , A . slice ( i + 1 , j + 1 ) . sort ( ( a , b ) => a - b ) , A . slice ( j + 2 ) . sort ( ( a , b ) => a - b ) ) ; i = j ; } for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { flag = 0 ; break ; } } if ( flag == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } var A = [ 3 , 2 , 1 ] ; var p = [ 1 , 2 ] ; check_vector ( A , A . length , p ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortDiff ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; let out = [ ] ; while ( n > 0 ) { out . push ( arr [ Math . floor ( n / 2 ) ] ) ; arr . splice ( Math . floor ( n / 2 ) , 1 ) ; n = n - 1 ; } for ( let i = 0 ; i < out . length ; i ++ ) document . write ( out [ i ] + " " ) ; } let arr = [ 8 , 1 , 2 , 3 , 0 ] ; let n = 5 ; sortDiff ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumCost ( arr , N , M ) { arr . sort ( ( a , b ) => a - b ) ; let pref = Array . from ( { length : N } , ( _ , i ) => 0 ) ; pref [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { pref [ i ] = arr [ i ] + pref [ i - 1 ] ; } for ( let i = M ; i < N ; i ++ ) { pref [ i ] += pref [ i - M ] ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( pref [ i ] + " " ) ; } } let arr = [ 6 , 19 , 3 , 4 , 4 , 2 , 6 , 7 , 8 ] ; let M = 2 ; let N = arr . length ; minimumCost ( arr , N , M ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var one = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; var ten = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; function numToWords ( n , s ) { var str = " " ; if ( n > 19 ) str += ten [ Math . floor ( n / 10 ) ] + one [ n % 10 ] ; else str += one [ n ] ; if ( n ) str += s ; return str ; } function convertToWords ( n ) { var out ; out += numToWords ( Math . floor ( n / 10000000 ) , " " ) ; out += numToWords ( ( Math . floor ( n / 100000 ) % 100 ) , " " ) ; out += numToWords ( ( Math . floor ( n / 1000 ) % 100 ) , " " ) ; out += numToWords ( ( Math . floor ( n / 100 ) % 10 ) , " " ) ; if ( n > 100 && n % 100 ) out += " " ; out += numToWords ( ( n % 100 ) , " " ) ; return out ; } function sortArr ( arr , n ) { var vp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { vp [ i ] = [ convertToWords ( arr [ i ] ) , arr [ i ] ] ; } vp . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( vp [ i ] [ 1 ] + " " ) ; } var arr = [ 12 , 10 , 102 , 31 , 15 ] ; var n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i, n
Accumulator variables: i, out, str
Iterator variables: i
Javascript program:
function uniqueSum ( A , R , N , M ) { for ( let i = 0 ; i < M ; ++ i ) { let l = R [ i ] [ 0 ] , r = R [ i ] [ 1 ] + 1 ; l -- ; r -- ; A [ l ] ++ ; if ( r < N ) A [ r ] -- ; } for ( let i = 1 ; i < N ; ++ i ) { A [ i ] += A [ i - 1 ] ; } let ans = 0 ; let s = new Set ( ) ; for ( let i = 0 ; i < N ; ++ i ) { if ( ! s . has ( A [ i ] ) ) ans += A [ i ] ; s . add ( A [ i ] ) ; } return ans ; } let A = [ 0 , 0 , 0 , 0 , 0 , 0 ] ; let R = [ [ 1 , 3 ] , [ 4 , 6 ] , [ 3 , 4 ] , [ 3 , 3 ] ] ; let N = A . length ; let M = R . length ; document . write ( uniqueSum ( A , R , N , M ) ) ;

Index/key variables: i, l, r
Accumulator variables: ans, l, r
Iterator variables: i
Javascript program:
function kthpair ( n , k , arr ) { let i , t = 0 ; arr . sort ( ) ; -- k ; for ( i = 0 ; i < n ; i += t ) { for ( t = 1 ; arr [ i ] == arr [ i + t ] ; ++ t ) ; if ( t * n > k ) break ; k = k - t * n ; } document . write ( arr [ i ] + " " + arr [ k / t ] ) ; } let n = 3 , k = 2 ; let arr = [ 3 , 1 , 5 ] ; kthpair ( n , k , arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, t
Javascript program:
function minOperations ( s ) { var freq = new Array ( 26 ) . fill ( 0 ) ; var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) { freq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } freq . sort ( ( a , b ) => b - a ) ; var answer = n ; for ( var i = 1 ; i <= 26 ; i ++ ) { if ( n % i === 0 ) { var x = n / i ; var y = 0 ; for ( var j = 0 ; j < i ; j ++ ) { y += Math . min ( freq [ j ] , x ) ; } answer = Math . min ( answer , n - y ) ; } } return answer ; } var s = " " ; document . write ( minOperations ( s ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, y
Iterator variables: i, j
Javascript program:
function fun ( arr , n , k ) { let v = [ ] ; for ( let i = 0 ; i < k ; i ++ ) { for ( let j = i ; j < n ; j += k ) { v . push ( arr [ j ] ) ; } v . sort ( ) ; let x = 0 ; for ( let j = i ; j < n ; j += k ) { arr [ j ] = v [ x ] ; x ++ ; } v = [ ] ; } for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } let arr = [ 4 , 2 , 3 , 7 , 6 ] ; let K = 2 ; let n = arr . length ; if ( fun ( arr , n , K ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, x
Accumulator variables: i, j, x
Iterator variables: i, j
Javascript program:
function sortedAdjacentDifferences ( arr , n ) { let ans = new Array ( n ) ; arr . sort ( ) ; let l = 0 , r = n - 1 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( i % 2 ) { ans [ i ] = arr [ l ] ; l ++ ; } else { ans [ i ] = arr [ r ] ; r -- ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let arr = [ 5 , - 2 , 4 , 8 , 6 , 4 , 5 ] ; let n = arr . length ; sortedAdjacentDifferences ( arr , n ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r
Iterator variables: i
Javascript program:
function get_permutation ( arr , n ) { arr . sort ( ) ; var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { result += Math . abs ( arr [ i ] - ( i + 1 ) ) ; } return result ; } var arr = [ 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 ] ; var n = arr . length ; document . write ( get_permutation ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
let dp = new Array ( ) ; for ( let i = 0 ; i < 1000 ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < 1000 ; j ++ ) { temp . push ( [ ] ) } dp . push ( temp ) } function minimumIncDec ( arr , N , maxE , minE ) { if ( N == 0 ) { return 0 ; } if ( ! dp [ N ] [ maxE ] ) return dp [ N ] [ maxE ] ; let ans = Number . MAX_SAFE_INTEGER ; for ( let k = minE ; k <= maxE ; k ++ ) { let x = minimumIncDec ( arr , N - 1 , k , minE ) ; ans = Math . min ( ans , x + Math . abs ( arr [ N - 1 ] - k ) ) ; } dp [ N ] [ maxE ] = ans ; return dp [ N ] [ maxE ] ; } let arr = [ 5 , 4 , 3 , 2 , 1 ] ; let N = arr . length ; let minE = arr . sort ( ( a , b ) => a - b ) [ 0 ] ; let maxE = arr . sort ( ( a , b ) => b - a ) [ 0 ] ; document . write ( minimumIncDec ( arr , N , maxE , minE ) ) ;

Index/key variables: N, maxE
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function sortDiagonal ( a , M , N ) { for ( var i = 0 ; i < M ; i ++ ) { var sm = a [ i ] [ i ] ; var pos = i ; for ( var j = i + 1 ; j < N ; j ++ ) { if ( sm > a [ j ] [ j ] ) { sm = a [ j ] [ j ] ; pos = j ; } } temp = a [ i ] [ i ] a [ i ] [ i ] = a [ pos ] [ pos ] a [ pos ] [ pos ] = temp } for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) document . write ( a [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var a = [ [ 4 , 2 ] , [ 3 , 1 ] ] ; sortDiagonal ( a , 2 , 2 ) ;

Index/key variables: i, j, pos
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function make_permutation ( arr , n ) { arr . sort ( ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans += Math . abs ( i + 1 - arr [ i ] ) ; return ans ; } let arr = [ 5 , 3 , 8 , 1 , 1 ] ; let n = arr . length ; document . write ( make_permutation ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function maxSum ( V , n , m ) { let ans = 0 ; for ( let i = n - 2 ; i >= 0 ; -- i ) { let aux = new Array ( ) ; for ( let j = 0 ; j < m ; ++ j ) { aux . push ( [ V [ i + 1 ] [ j ] , j ] ) ; } aux . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ; aux . reverse ( ) ; for ( let j = 0 ; j < m ; ++ j ) { for ( let k = 0 ; k < m ; ++ k ) { if ( aux [ k ] [ 1 ] - j == 0 || Math . abs ( aux [ k ] [ 1 ] - j ) > 1 ) { V [ i ] [ j ] += aux [ k ] [ 0 ] ; break ; } } } } for ( let i = 0 ; i < m ; ++ i ) { ans = Math . max ( ans , V [ 0 ] [ i ] ) ; } return ans ; } let V = [ [ 1 , 2 , 3 , 4 ] , [ 8 , 7 , 6 , 5 ] , [ 10 , 11 , 12 , 13 ] ] ; let n = V . length ; let m = V [ 0 ] . length ; document . write ( maxSum ( V , n , m ) ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function SumofDigits ( digit ) { let sum = 0 ; while ( digit != 0 ) { let rem = digit % 10 ; sum += rem ; digit = Math . floor ( digit / 10 ) ; } return sum ; } function findCountofNumbers ( arr , n , M ) { let SumDigits = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { let s = SumofDigits ( arr [ i ] ) ; SumDigits . push ( s ) ; } SumDigits . sort ( function ( a , b ) { return a - b ; } ) ; let ip = Array . from ( new Set ( SumDigits ) ) ; let count = 0 ; let sum = 0 ; for ( let i = 0 ; i < SumDigits . length ; i ++ ) { if ( sum > M ) break ; sum += SumDigits [ i ] ; if ( sum <= M ) count ++ ; } return count ; } let arr = [ 1 , 45 , 16 , 17 , 219 , 32 , 22 ] ; let M = 10 ; let n = arr . length ; document . write ( findCountofNumbers ( arr , n , M ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function minimumProduct ( arr , n ) { arr . sort ( ) ; let product = 1 ; for ( let i = 0 ; i < n ; i += 2 ) { product *= ( arr [ i ] + arr [ i + 1 ] ) ; } return product ; } let arr = [ 1 , 6 , 3 , 1 , 7 , 8 ] ; let n = arr . length ; document . write ( minimumProduct ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
Javascript program:
function checkIsAP ( arr , n ) { if ( n == 1 ) return true ; arr . sort ( function ( a , b ) { return a - b ; } ) ; var d = arr [ 1 ] - arr [ 0 ] ; for ( var i = 2 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] != d ) { return false ; } } return true ; } function checkIsGP ( arr , n ) { if ( n == 1 ) return true ; arr . sort ( ) ; var r = arr [ 1 ] / arr [ 0 ] ; for ( var i = 2 ; i < n ; i ++ ) { if ( arr [ i ] / arr [ i - 1 ] != r ) return false ; } return true ; } function checkIsHP ( arr , n ) { if ( n == 1 ) { return true ; } var rec = Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { rec [ i ] = ( ( 1 / arr [ i ] ) ) ; } if ( checkIsAP ( rec , n ) ) return true ; else return false ; } var arr = [ 1.0 / 5.0 , 1.0 / 10.0 , 1.0 / 15.0 , 1.0 / 20.0 ] ; var n = arr . length ; var flag = 0 ; if ( checkIsAP ( arr , n ) ) { document . write ( " " ) ; flag = 1 ; } if ( checkIsGP ( arr , n ) ) { document . write ( " " ) ; flag = 1 ; } if ( checkIsHP ( arr , n ) ) { document . write ( " " ) ; flag = 1 ; } else if ( flag == 0 ) { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function reversDigits ( num ) { var rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = Math . floor ( num / 10 ) ; } return rev_num ; } function sortArr ( arr , n ) { var vp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { vp [ i ] = [ ] ; } for ( var i = 0 ; i < n ; i ++ ) { var pair = [ ] ; pair . push ( reversDigits ( arr [ i ] ) ) ; pair . push ( arr [ i ] ) ; vp [ i ] = pair ; } vp = vp . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( vp [ i ] [ 1 ] + " " ) ; } } var arr = [ 12 , 10 , 102 , 31 , 15 ] ; var n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 3 ; let M = 3 ; function sortMat ( data , row , col ) { let size = row * col ; for ( let i = 0 ; i < size ; i ++ ) { for ( let j = 0 ; j < size - 1 ; j ++ ) { if ( data [ Math . floor ( j / col ) ] [ j % col ] > data [ Math . floor ( ( j + 1 ) / col ) ] [ ( j + 1 ) % col ] ) { let temp = data [ Math . floor ( j / col ) ] [ j % col ] ; data [ Math . floor ( j / col ) ] [ j % col ] = data [ Math . floor ( ( j + 1 ) / col ) ] [ ( j + 1 ) % col ] ; data [ Math . floor ( ( j + 1 ) / col ) ] [ ( j + 1 ) % col ] = temp ; } } } } function printMat ( mat , row , col ) { for ( let i = 0 ; i < row ; i ++ ) { for ( let j = 0 ; j < col ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 5 , 4 , 7 ] , [ 1 , 3 , 8 ] , [ 2 , 9 , 6 ] ] ; let row = N ; let col = M ; sortMat ( mat , row , col ) ; printMat ( mat , row , col ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function overlap ( v ) { var ans = 0 ; var count = 0 ; var data = [ ] ; for ( var i = 0 ; i < v . length ; i ++ ) { data . push ( [ v [ i ] [ 0 ] , ' ' ] ) ; data . push ( [ v [ i ] [ 1 ] , ' ' ] ) ; } data . sort ( ) ; for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] [ 1 ] == ' ' ) count ++ ; if ( data [ i ] [ 1 ] == ' ' ) count -- ; ans = Math . max ( ans , count ) ; } document . write ( ans + " " ) ; } var v = [ [ 1 , 2 ] , [ 2 , 4 ] , [ 3 , 6 ] ] ; overlap ( v ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function orgazineInOrder ( vec , op , n ) { let result = [ n ] ; vec . sort ( ) ; let i = 0 , j = n - 1 , k = 0 ; while ( i <= j && k <= n - 2 ) { if ( op [ k ] == ' ' ) { result [ k ] = vec [ i ++ ] ; } else { result [ k ] = vec [ j -- ] ; } k ++ ; } result [ n - 1 ] = vec [ i ] ; return result ; } let vec = [ 8 , 2 , 7 , 1 , 5 , 9 ] ; let op = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; let result = orgazineInOrder ( vec , op , vec . length ) ; for ( let i = 0 ; i < result . length ; i ++ ) { document . write ( result [ i ] + " " ) ; }

Index/key variables: i, k, n
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function getDistance ( arr , n , a , b ) { let vp = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { vp . push ( [ arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ] ) ; } vp . sort ( function ( c , d ) { return c [ 0 ] - d [ 0 ] ; } ) ; let pos = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { pos [ i ] = 0 ; } for ( let i = 0 ; i < vp . length ; i ++ ) { let height = vp [ i ] [ 0 ] ; let k = vp [ i ] [ 1 ] ; pos [ k ] = height } let first = - 1 , second = - 1 ; for ( let i = 0 ; i < pos . length ; i ++ ) { if ( pos [ i ] == a ) first = i ; if ( pos [ i ] == b ) second = i ; } return Math . abs ( first - second ) ; } let arr = [ [ 5 , 0 ] , [ 3 , 0 ] , [ 2 , 0 ] , [ 6 , 4 ] , [ 1 , 0 ] , [ 4 , 3 ] ] ; let n = arr . length ; let a = 6 , b = 5 ; document . write ( getDistance ( arr , n , a , b ) ) ;

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSum ( arr , n , k ) { var ans = arr [ n - k - 1 ] - arr [ 0 ] ; for ( var i = 1 ; i <= k ; i ++ ) { ans = Math . min ( arr [ n - 1 - ( k - i ) ] - arr [ i ] , ans ) ; } return ans ; } var arr = [ 1 , 2 , 100 , 120 , 140 ] ; var k = 2 ; var n = arr . length ; document . write ( findSum ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMin ( arr , n ) { let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) { let j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; ans = Math . max ( ans , j - i ) ; i = j - 1 ; } return n - ans ; } let arr = [ 3 , 2 , 1 ] ; let n = arr . length ; document . write ( findMin ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function countSubSeq ( a , n , k ) { a . sort ( ) ; var arr = [ ] ; for ( var i = 0 ; i < n ; ) { var count = 1 , x = a [ i ] ; i ++ ; while ( i < n && a [ i ] == x ) { count ++ ; i ++ ; } arr . push ( count ) ; } var m = arr . length ; n = Math . min ( m , k ) ; var count = 1 ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( m + 1 ) ) ; for ( var i = 0 ; i <= m ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = m ; j >= 0 ; j -- ) { if ( j > m - i ) dp [ i ] [ j ] = 0 ; else { dp [ i ] [ j ] = dp [ i ] [ j + 1 ] + arr [ j ] * dp [ i - 1 ] [ j + 1 ] ; } } count = count + dp [ i ] [ 0 ] ; } return count ; } var a = [ 2 , 2 , 3 , 3 , 5 ] ; var n = a . length ; var k = 3 ; document . write ( countSubSeq ( a , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function partOdd ( s ) { var st = " " ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( i % 2 !== 0 ) st += s [ i ] ; } return st ; } function partEven ( str ) { var s = " " ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( i % 2 === 0 ) s += str [ i ] ; } return s ; } function canBeMadeEqual ( s1 , s2 ) { var even1 = partEven ( s1 ) . split ( " " ) ; var even2 = partEven ( s2 ) . split ( " " ) ; var odd1 = partOdd ( s1 ) . split ( " " ) ; var odd2 = partOdd ( s2 ) . split ( " " ) ; even1 . sort ( ) ; even2 . sort ( ) ; odd1 . sort ( ) ; odd2 . sort ( ) ; var even_s1 = even1 . join ( " " ) ; var even_s2 = even2 . join ( " " ) ; var odd_s1 = odd1 . join ( " " ) ; var odd_s2 = odd2 . join ( " " ) ; if ( even_s1 === even_s2 && odd_s1 === odd_s2 ) return true ; return false ; } var s1 = " " ; var s2 = " " ; if ( canBeMadeEqual ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, s, st
Iterator variables: i
Javascript program:
const MAX = 1000 ; function lineExists ( x , y , v , n ) { let size = ( 2 * MAX ) + 1 ; let arr = new Array ( size ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { arr [ x [ i ] + MAX ] += v [ i ] ; } for ( let i = 1 ; i < size ; i ++ ) arr [ i ] += arr [ i - 1 ] ; if ( arr [ size - 1 ] == 0 ) return true ; if ( arr [ size - 1 ] - arr [ 0 ] == 0 ) return true ; for ( let i = 1 ; i < size - 1 ; i ++ ) { if ( arr [ i - 1 ] == arr [ size - 1 ] - arr [ i - 1 ] ) return true ; if ( arr [ i - 1 ] == arr [ size - 1 ] - arr [ i ] ) return true ; if ( arr [ i ] == arr [ size - 1 ] - arr [ i ] ) return true ; } if ( arr [ size - 2 ] == 0 ) return true ; return false ; } let x = [ - 3 , 5 , 8 ] ; let y = [ 8 , 7 , 9 ] let v = [ 8 , 2 , 10 ] ; let n = x . length ; if ( lineExists ( x , y , v , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( a , n ) { a . sort ( ( a , b ) => a - b ) ; let sum = 0 ; for ( let i = 0 ; i < n - 1 ; i += 2 ) { sum += a [ i ] ; } return sum ; } let arr = [ 1 , 3 , 2 , 1 , 4 , 5 ] ; let n = arr . length ; document . write ( maxSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function prletArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function sortWithRemainder ( arr , n , k ) { let v = new Array ( ) ; for ( let i = 0 ; i < k ; i ++ ) { v . push ( [ ] ) } for ( let i = 0 ; i < n ; i ++ ) { v [ arr [ i ] % k ] . push ( arr [ i ] ) ; } for ( let i = 0 ; i < k ; i ++ ) v [ i ] . sort ( ( a , b ) => a - b ) ; console . log ( v ) let j = 0 ; for ( let i = 0 ; i < k ; i ++ ) { for ( let it of v [ i ] ) { arr [ j ] = it ; j ++ ; } } prletArr ( arr , n ) ; } let arr = [ 10 , 7 , 2 , 6 , 12 , 3 , 33 , 46 ] ; let n = arr . length ; let k = 4 ; sortWithRemainder ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, it
Javascript program:
function customSort ( s1 , s2 ) { let count_a1 = 0 , count_b1 = 0 ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] == ' ' ) { count_a1 ++ ; } else { count_b1 ++ ; } } let count_a2 = 0 , count_b2 = 0 ; for ( let i = 0 ; i < s2 . length ; i ++ ) { if ( s2 [ i ] == ' ' ) { count_a2 ++ ; } else { count_b2 ++ ; } } if ( count_a1 * count_b2 > count_b1 * count_a2 ) { return true ; } else { return false ; } } function concatenateStrings ( S , N ) { let str = " " ; for ( let i = 0 ; i < N ; i ++ ) { str += S [ i ] ; } return str ; } function getMaxScore ( S , N ) { S . sort ( ) ; let combined_string = concatenateStrings ( S , N ) ; let final_score = 0 , count_a = 0 ; for ( let i = 0 ; i < combined_string . length ; i ++ ) { if ( combined_string [ i ] == ' ' ) { count_a ++ ; } else { final_score += count_a ; } } return final_score ; } let S = [ " " , " " , " " , " " ] ; let N = S . length ; document . write ( getMaxScore ( S , N ) - 10 ) ;

Index/key variables: i
Accumulator variables: count_a, count_a1, count_a2, count_b1, count_b2, final_score, i, str
Iterator variables: i
Javascript program:
function minOperations ( ar , k ) { ar . sort ( function ( a , b ) { return a - b } ) ; let opsNeeded = 0 ; for ( let i = 0 ; i < k ; i ++ ) { opsNeeded += ar [ k - 1 ] - ar [ i ] ; } let ans = opsNeeded ; for ( let i = k ; i < ar . length ; i ++ ) { opsNeeded = opsNeeded - ( ar [ i - 1 ] - ar [ i - k ] ) ; opsNeeded += ( k - 1 ) * ( ar [ i ] - ar [ i - 1 ] ) ; ans = Math . min ( ans , opsNeeded ) ; } return ans ; } let arr = [ 3 , 1 , 9 , 100 ] ; let n = arr . length ; let k = 3 ; document . write ( minOperations ( arr , k ) ) ;

Index/key variables: i
Accumulator variables: i, opsNeeded
Iterator variables: i
Javascript program:
function getNumber ( n , k ) { var arr = Array ( n ) . fill ( n ) ; var i = 0 ; var odd = 1 ; while ( odd <= n ) { arr [ i ++ ] = odd ; odd += 2 ; } var even = 2 ; while ( even <= n ) { arr [ i ++ ] = even ; even += 2 ; } return arr [ k - 1 ] ; } var n = 8 , k = 5 ; document . write ( getNumber ( n , k ) ) ;

Accumulator variables: even, i, odd