dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Printksubstring ( str , n , k ) { let total = parseInt ( ( n * ( n + 1 ) ) / 2 , 10 ) ; if ( k > total ) { document . write ( " " + " " ) ; return ; } let substring = new Array ( n + 1 ) ; substring [ 0 ] = 0 ; let temp = n ; for ( let i = 1 ; i <= n ; i ++ ) { substring [ i ] = substring [ i - 1 ] + temp ; temp -- ; } let l = 1 ; let h = n ; let start = 0 ; while ( l <= h ) { let m = parseInt ( ( l + h ) / 2 , 10 ) ; if ( substring [ m ] > k ) { start = m ; h = m - 1 ; } else if ( substring [ m ] < k ) { l = m + 1 ; } else { start = m ; break ; } } let end = n - ( substring [ start ] - k ) ; for ( let i = start - 1 ; i < end ; i ++ ) { document . write ( str [ i ] ) ; } } let str = " " ; let k = 4 ; let n = str . length ; Printksubstring ( str , n , k ) ;

Index/key variables: i, m, start
Accumulator variables: i, temp
Iterator variables: i
Javascript program:
function LowerInsertionPoint ( arr , n , X ) { if ( X < arr [ 0 ] ) return 0 ; else if ( X > arr [ n - 1 ] ) return n ; let lowerPnt = 0 ; let i = 1 ; while ( i < n && arr [ i ] < X ) { lowerPnt = i ; i = i * 2 ; } while ( lowerPnt < n && arr [ lowerPnt ] < X ) lowerPnt ++ ; return lowerPnt ; } let arr = [ 2 , 3 , 4 , 4 , 5 , 6 , 7 , 9 ] ; let n = arr . length ; let X = 4 ; document . write ( LowerInsertionPoint ( arr , n , X ) ) ;

Index/key variables: i, lowerPnt
Accumulator variables: lowerPnt
Javascript program:
function getCount ( M , N ) { let count = 0 ; if ( M == 1 ) return N ; if ( N == 1 ) return M ; if ( N > M ) { for ( let i = 1 ; i <= M ; i ++ ) { let numerator = N * i - N + M - i ; let denominator = M - 1 ; if ( numerator % denominator == 0 ) { let j = parseInt ( numerator / denominator , 10 ) ; if ( j >= 1 && j <= N ) count ++ ; } } } else { for ( let j = 1 ; j <= N ; j ++ ) { let numerator = M * j - M + N - j ; let denominator = N - 1 ; if ( numerator % denominator == 0 ) { let i = parseInt ( numerator / denominator , 10 ) ; if ( i >= 1 && i <= M ) count ++ ; } } } return count ; } let M = 3 , N = 5 ; document . write ( getCount ( M , N ) ) ;

Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function swapElement ( arr1 , arr2 , n ) { let wrongIdx = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr1 [ i ] < arr1 [ i - 1 ] ) { wrongIdx = i ; } } let maximum = Number . MIN_VALUE ; let maxIdx = - 1 ; let res = false ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr2 [ i ] > maximum && arr2 [ i ] >= arr1 [ wrongIdx - 1 ] ) { if ( wrongIdx + 1 <= n - 1 && arr2 [ i ] <= arr1 [ wrongIdx + 1 ] ) { maximum = arr2 [ i ] ; maxIdx = i ; res = true ; } } } if ( res ) { swap ( arr1 , wrongIdx , arr2 , maxIdx ) ; } return res ; } function swap ( a , wrongIdx , b , maxIdx ) { let c = a [ wrongIdx ] ; a [ wrongIdx ] = b [ maxIdx ] ; b [ maxIdx ] = c ; } function getSortedArray ( arr1 , arr2 , n ) { if ( swapElement ( arr1 , arr2 , n ) ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr1 [ i ] + " " ) ; } } else { document . write ( " " ) ; } } let arr1 = [ 1 , 3 , 7 , 4 , 10 ] ; let arr2 = [ 2 , 1 , 6 , 8 , 9 ] ; let n = arr1 . length ; getSortedArray ( arr1 , arr2 , n ) ;

Index/key variables: i, maxIdx, wrongIdx
Accumulator variables: i
Iterator variables: i
Boolean variables: res
Javascript program:
function transpose ( mat , row , col ) { let tr = new Array ( col ) ; for ( let i = 0 ; i < col ; i ++ ) { tr [ i ] = new Array ( row ) ; } for ( let i = 0 ; i < row ; i ++ ) { for ( let j = 0 ; j < col ; j ++ ) { tr [ j ] [ i ] = mat [ i ] [ j ] ; } } return tr ; } function RowWiseSort ( B ) { for ( let i = 0 ; i < B . length ; i ++ ) { ( B [ i ] ) . sort ( function ( a , b ) { return a - b ; } ) ; } } function sortCol ( mat , n , M ) { let B = transpose ( mat , N , M ) ; RowWiseSort ( B ) ; mat = transpose ( B , M , N ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 1 , 6 , 10 ] , [ 8 , 5 , 9 ] , [ 9 , 4 , 15 ] , [ 7 , 3 , 60 ] ] ; let N = mat . length ; let M = mat [ 0 ] . length ; sortCol ( mat , N , M ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function largestArea ( N , M , H , V , h , v ) { var s1 = new Set ( ) ; var s2 = new Set ( ) ; for ( var i = 1 ; i <= N + 1 ; i ++ ) s1 . add ( i ) ; for ( var i = 1 ; i <= M + 1 ; i ++ ) s2 . add ( i ) ; for ( var i = 0 ; i < h ; i ++ ) { s1 . delete ( H [ i ] ) ; } for ( var i = 0 ; i < v ; i ++ ) { s2 . delete ( V [ i ] ) ; } var list1 = Array ( s1 . size ) ; var list2 = Array ( s2 . size ) ; var i = 0 ; s1 . forEach ( element => { list1 [ i ++ ] = element ; } ) ; i = 0 ; s2 . forEach ( element => { list2 [ i ++ ] = element ; } ) ; list1 . sort ( ( a , b ) => a - b ) list2 . sort ( ( a , b ) => a - b ) var maxH = 0 , p1 = 0 , maxV = 0 , p2 = 0 ; for ( var j = 0 ; j < s1 . size ; j ++ ) { maxH = Math . max ( maxH , list1 [ j ] - p1 ) ; p1 = list1 [ j ] ; } for ( var j = 0 ; j < s2 . size ; j ++ ) { maxV = Math . max ( maxV , list2 [ j ] - p2 ) ; p2 = list2 [ j ] ; } document . write ( maxV * maxH ) ; } var N = 3 , M = 3 ; var H = [ 2 ] ; var V = [ 2 ] ; var h = H . length ; var v = V . length ; largestArea ( N , M , H , V , h , v ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkifSorted ( A , B , N ) { var flag = false ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { flag = true ; break ; } } if ( ! flag ) { return true ; } var count = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( B [ i ] == 0 ) { count ++ ; break ; } } for ( i = 0 ; i < N ; i ++ ) { if ( B [ i ] == 1 ) { count ++ ; break ; } } if ( count == 2 ) { return true ; } return false ; } var A = [ 3 , 1 , 2 ] ; var B = [ 0 , 1 , 1 ] ; var N = A . length ; var check = checkifSorted ( A , B , N ) ; if ( check ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function minSteps ( A , B , M , N ) { if ( A [ 0 ] > B [ 0 ] ) return 0 ; if ( B [ 0 ] > A [ 0 ] ) { return 1 ; } if ( M <= N && A [ 0 ] == B [ 0 ] && count ( A , A [ 0 ] ) == M && count ( B , B [ 0 ] ) == N ) return - 1 ; for ( var i = 1 ; i < N ; i ++ ) { if ( B [ i ] > B [ 0 ] ) return 1 ; } for ( var i = 1 ; i < M ; i ++ ) { if ( A [ i ] < A [ 0 ] ) return 1 ; } for ( var i = 1 ; i < M ; i ++ ) { if ( A [ i ] > A [ 0 ] ) { swap ( A , i , B , 0 ) ; swap ( A , 0 , B , 0 ) ; return 2 ; } } for ( var i = 1 ; i < N ; i ++ ) { if ( B [ i ] < B [ 0 ] ) { swap ( A , 0 , B , i ) ; swap ( A , 0 , B , 0 ) ; return 2 ; } } return 0 ; } function count ( a , c ) { count = 0 ; for ( var i = 0 ; i < a . length ; i ++ ) if ( a [ i ] == c ) count ++ ; return count ; } function swap ( s1 , index1 , s2 , index2 ) { var c = s1 [ index1 ] ; s1 [ index1 ] = s2 [ index2 ] ; s2 [ index2 ] = c ; } var A = " " ; var B = " " ; var M = A . length ; var N = B . length ; document . write ( minSteps ( A , B , M , N ) ) ;

Index/key variables: i, index1, index2
Accumulator variables: count, i
Iterator variables: i
Javascript program:
var maxN = 201 ; var n1 , n2 , n3 ; var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxN ) ) ; for ( var i = 0 ; i < maxN ; i ++ ) for ( var j = 0 ; j < maxN ; j ++ ) dp [ i ] [ j ] = new Array ( maxN ) . fill ( - 1 ) ; function getMaxSum ( i , j , k , arr1 , arr2 , arr3 ) { var cnt = 0 ; if ( i >= n1 ) cnt ++ ; if ( j >= n2 ) cnt ++ ; if ( k >= n3 ) cnt ++ ; if ( cnt >= 2 ) return 0 ; if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ; var ans = 0 ; if ( i < n1 && j < n2 ) ans = Math . max ( ans , getMaxSum ( i + 1 , j + 1 , k , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr2 [ j ] ) ; if ( i < n1 && k < n3 ) ans = Math . max ( ans , getMaxSum ( i + 1 , j , k + 1 , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr3 [ k ] ) ; if ( j < n2 && k < n3 ) ans = Math . max ( ans , getMaxSum ( i , j + 1 , k + 1 , arr1 , arr2 , arr3 ) + arr2 [ j ] * arr3 [ k ] ) ; dp [ i ] [ j ] [ k ] = ans ; return dp [ i ] [ j ] [ k ] ; } function maxProductSum ( arr1 , arr2 , arr3 ) { arr1 . sort ( ) ; arr1 . reverse ( ) ; arr2 . sort ( ) ; arr2 . reverse ( ) ; arr3 . sort ( ) ; arr3 . reverse ( ) ; return getMaxSum ( 0 , 0 , 0 , arr1 , arr2 , arr3 ) ; } n1 = 2 ; var arr1 = [ 3 , 5 ] ; n2 = 2 ; var arr2 = [ 2 , 1 ] ; n3 = 3 ; var arr3 = [ 4 , 3 , 5 ] ; document . write ( maxProductSum ( arr1 , arr2 , arr3 ) ) ;

Index/key variables: i, j, k
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function findTriplet ( arr , N ) { arr . sort ( ( a , b ) => a - b ) ; var flag = 0 , i ; for ( i = N - 1 ; i - 2 >= 0 ; i -- ) { if ( arr [ i - 2 ] + arr [ i - 1 ] > arr [ i ] ) { flag = 1 ; break ; } } if ( flag ) { document . write ( arr [ i - 2 ] + " " + arr [ i - 1 ] + " " + arr [ i ] + " " ) ; } else { document . write ( - 1 + " " ) ; } } var arr = [ 4 , 2 , 10 , 3 , 5 ] ; var N = arr . length ; findTriplet ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function numberofpairs ( arr , N ) { let answer = 0 ; arr . sort ( ) ; let minDiff = Number . MAX_VALUE ; for ( let i = 0 ; i < N - 1 ; i ++ ) minDiff = Math . min ( minDiff , arr [ i + 1 ] - arr [ i ] ) ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i + 1 ] - arr [ i ] == minDiff ) answer ++ ; } return answer ; } let arr = [ 4 , 2 , 1 , 3 ] ; let N = arr . length ; document . write ( numberofpairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
let max_length = 0 ; let store = [ ] ; let ans = [ ] ; function find_max_length ( arr , index , sum , k ) { sum = sum + arr [ index ] ; store . push ( arr [ index ] ) ; if ( sum == k ) { if ( max_length < store . length ) { max_length = store . length ; ans = store ; } } for ( let i = index + 1 ; i < arr . length ; i ++ ) { if ( sum + arr [ i ] <= k ) { find_max_length ( arr , i , sum , k ) ; store . pop ( ) ; } else return ; } return ; } function longestSubsequence ( arr , n , k ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( max_length >= n - i ) break ; store = [ ] ; find_max_length ( arr , i , 0 , k ) ; } return max_length ; } let arr = [ - 3 , 0 , 1 , 1 , 2 ] ; let n = arr . length ; let k = 1 ; document . write ( longestSubsequence ( arr , n , k ) ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortArray ( A , N ) { let x = 0 , y = 0 , z = 0 ; if ( N % 4 == 0 N % 4 == 1 ) { for ( let i = 0 ; i < N / 2 ; i ++ ) { x = i ; if ( i % 2 == 0 ) { y = N - i - 2 ; z = N - i - 1 ; } A [ z ] = A [ y ] ; A [ y ] = A [ x ] ; A [ x ] = x + 1 ; } document . write ( " " ) ; for ( let i = 0 ; i < N ; i ++ ) document . write ( A [ i ] + " " ) ; } else { document . write ( " " ) ; } } let A = [ 5 , 4 , 3 , 2 , 1 ] ; let N = A . length ; sortArray ( A , N ) ;

Index/key variables: i, x, y, z
Accumulator variables: i
Iterator variables: i
Javascript program:
function findK ( arr , size , N ) { arr . sort ( function ( a , b ) { return a - b } ) ; let temp_sum = 0 ; for ( let i = 0 ; i < size ; i ++ ) { temp_sum += arr [ i ] ; if ( N - temp_sum == arr [ i ] * ( size - i - 1 ) ) { return arr [ i ] ; } } return - 1 ; } let arr = [ 3 , 1 , 10 , 4 , 8 ] ; let size = arr . length ; let N = 16 ; document . write ( findK ( arr , size , N ) ) ;

Index/key variables: i
Accumulator variables: i, temp_sum
Iterator variables: i
Javascript program:
function existsTriplet ( a , b , c , x , l1 , l2 , l3 ) { if ( l2 <= l1 && l2 <= l3 ) { temp = l1 ; l1 = l2 ; l2 = temp ; temp = a ; a = b ; b = temp ; } else if ( l3 <= l1 && l3 <= l2 ) { temp = l1 ; l1 = l3 ; l3 = temp ; temp = a ; a = c ; c = temp ; } for ( var i = 0 ; i < l1 ; i ++ ) { var j = 0 , k = l3 - 1 ; while ( j < l2 && k >= 0 ) { if ( a [ i ] + b [ j ] + c [ k ] == x ) return true ; if ( a [ i ] + b [ j ] + c [ k ] < x ) j ++ ; else k -- ; } } return false ; } var a = [ 2 , 7 , 8 , 10 , 15 ] ; var b = [ 1 , 6 , 7 , 8 ] ; var c = [ 4 , 5 , 5 ] ; var l1 = a . length ; var l2 = b . length ; var l3 = c . length ; var x = 14 ; if ( existsTriplet ( a , b , c , x , l1 , l2 , l3 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] ) ; } function compare ( num1 , num2 ) { let A = num1 . toString ( ) ; let B = num2 . toString ( ) ; return ( A + B ) . localeCompare ( B + A ) ; } function printSmallest ( N , arr ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( compare ( arr [ i ] , arr [ j ] ) > 0 ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } } printArr ( arr , N ) ; } let arr = [ 5 , 6 , 2 , 9 , 21 , 1 ] ; let N = arr . length ; printSmallest ( N , arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function stableSelectionSort ( a , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { let min = i ; for ( let j = i + 1 ; j < n ; j ++ ) if ( a [ min ] > a [ j ] ) min = j ; let key = a [ min ] ; while ( min > i ) { a [ min ] = a [ min - 1 ] ; min -- ; } a [ i ] = key ; } } function prletArray ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ; document . write ( " " ) ; } let a = [ 4 , 5 , 3 , 2 , 4 , 1 ] ; let n = a . length ; stableSelectionSort ( a , n ) ; prletArray ( a , n ) ;

Index/key variables: i, j, min
Accumulator variables: i, j, min
Iterator variables: i, j
Javascript program:
function isPossible ( a , b , n , k ) { a . sort ( function ( a , b ) { return a - b } ) ; b . reverse ( ) ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] + b [ i ] < k ) return false ; return true ; } let a = [ 2 , 1 , 3 ] ; let b = [ 7 , 8 , 9 ] ; let k = 10 ; let n = a . length ; if ( isPossible ( a , b , n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const canReach = ( s , L , R ) => { let dp = new Array ( s . length ) . fill ( 1 ) ; let pre = 0 ; for ( let i = 1 ; i < s . length ; i ++ ) { if ( i >= L ) { pre += dp [ i - L ] ; } if ( i > R ) { pre -= dp [ i - R - 1 ] ; } dp [ i ] = ( pre > 0 ) && ( s [ i ] == ' ' ) ; } return dp [ s . length - 1 ] ; } let S = " " ; let L = 2 , R = 3 ; if ( canReach ( S , L , R ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, pre
Iterator variables: i
Javascript program:
let N = 100000 + 5 ; let visited = new Array ( N ) ; visited . fill ( 0 ) ; function construct_tree ( weights , n ) { let minimum = Number . MAX_VALUE ; let maximum = Number . MIN_VALUE ; for ( let i = 0 ; i < weights . length ; i ++ ) { minimum = Math . min ( minimum , weights [ i ] ) ; maximum = Math . max ( maximum , weights [ i ] ) ; } if ( minimum == maximum ) { document . write ( " " ) ; return ; } else { document . write ( " " + " " ) ; } let root = weights [ 0 ] ; visited [ 1 ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root && visited [ i + 1 ] == 0 ) { document . write ( 1 + " " + ( i + 1 ) + " " ) ; visited [ i + 1 ] = 1 ; } } let notroot = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root ) { notroot = i + 1 ; break ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] == root && visited [ i + 1 ] == 0 ) { document . write ( notroot + " " + ( i + 1 ) + " " ) ; visited [ i + 1 ] = 1 ; } } } let weights = [ 1 , 2 , 1 , 2 , 5 ] ; let n = weights . length ; construct_tree ( weights , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( s , k ) { var n = s . length ; var ans = 0 ; for ( var i = 0 ; i < k ; i ++ ) { var a = new Array ( 26 ) . fill ( 0 ) ; for ( var j = i ; j < n ; j += k ) { a [ s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } var min_cost = 1000000000 ; for ( var ch = 0 ; ch < 26 ; ch ++ ) { var cost = 0 ; for ( var tr = 0 ; tr < 26 ; tr ++ ) cost += Math . abs ( ch - tr ) * a [ tr ] ; min_cost = Math . min ( min_cost , cost ) ; } ans += min_cost ; } document . write ( ans ) ; } var S = " " ; var K = 3 ; minCost ( S , K ) ;

Index/key variables: j, tr
Accumulator variables: ans, ch, cost, i, j, tr
Iterator variables: ch, i, j, tr
Javascript program:
let N = 10000 ; let adj = new Array ( N ) ; let used = new Array ( N ) ; used . fill ( 0 ) ; let max_matching = 0 ; function AddEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function Matching_dfs ( u , p ) { for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { Matching_dfs ( adj [ u ] [ i ] , u ) ; } } if ( used [ u ] == 0 && used [ p ] == 0 && p != 0 ) { max_matching ++ ; used [ u ] = used [ p ] = 1 ; } } function maxMatching ( ) { Matching_dfs ( 1 , 0 ) ; document . write ( max_matching + " " ) ; } for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; AddEdge ( 1 , 2 ) ; AddEdge ( 1 , 3 ) ; AddEdge ( 3 , 4 ) ; AddEdge ( 3 , 5 ) ; maxMatching ( ) ;

Index/key variables: i, p, u, v
Accumulator variables: i, max_matching
Iterator variables: i
Javascript program:
function getMinCost ( A , B , N ) { let mini = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { mini = Math . min ( mini , Math . min ( A [ i ] , B [ i ] ) ) ; } return mini * ( 2 * N - 1 ) ; } let N = 3 ; let A = [ 1 , 4 , 2 ] ; let B = [ 10 , 6 , 12 ] ; document . write ( getMinCost ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printVector ( arr ) { if ( arr . length != 1 ) { for ( var i = 0 ; i < arr . length ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } } function findWays ( arr , i , n ) { if ( n == 0 ) printVector ( arr ) ; for ( var j = i ; j <= n ; j ++ ) { arr . push ( j ) ; findWays ( arr , j , n - j ) ; arr . pop ( ) ; } } var n = 4 ; var arr = [ ] ; findWays ( arr , 1 , n ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function Maximum_subsequence ( A , N ) { var frequency = new Map ( ) ; var max_freq = 0 ; 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 ) ; } frequency . forEach ( ( value , key ) => { if ( value > max_freq ) { max_freq = value ; } } ) ; document . write ( max_freq ) ; } var arr = [ 5 , 2 , 6 , 5 , 2 , 4 , 5 , 2 ] ; var N = arr . length ; Maximum_subsequence ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function DivideString ( s , n , k ) { var i , c = 0 , no = 1 ; var c1 = 0 , c2 = 0 ; var fr = new Array ( 26 ) . fill ( 0 ) ; var ans = [ ] ; for ( i = 0 ; i < n ; i ++ ) { fr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var ch = " " , ch1 = " " ; for ( i = 0 ; i < 26 ; i ++ ) { if ( fr [ i ] === k ) { c ++ ; } if ( fr [ i ] > k && fr [ i ] !== 2 * k ) { c1 ++ ; ch = String . fromCharCode ( i + " " . charCodeAt ( 0 ) ) ; } if ( fr [ i ] === 2 * k ) { c2 ++ ; ch1 = String . fromCharCode ( i + " " . charCodeAt ( 0 ) ) ; } } for ( i = 0 ; i < n ; i ++ ) ans . push ( " " ) ; var mp = { } ; if ( c % 2 === 0 c1 > 0 c2 > 0 ) { for ( i = 0 ; i < n ; i ++ ) { if ( fr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] === k ) { if ( mp . hasOwnProperty ( s [ i ] ) ) { ans [ i ] = " " ; } else { if ( no <= parseInt ( c / 2 ) ) { ans [ i ] = " " ; no ++ ; mp [ s [ i ] ] = 1 ; } } } } if ( c % 2 === 1 && c1 > 0 ) { no = 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] === ch && no <= k ) { ans [ i ] = " " ; no ++ ; } } } if ( c % 2 === 1 && c1 === 0 ) { no = 1 ; var flag = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] === ch1 && no <= k ) { ans [ i ] = " " ; no ++ ; } if ( fr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] === k && flag === 0 && ans [ i ] === " " ) { ans [ i ] = " " ; flag = 1 ; } } } document . write ( ans . join ( " " ) ) ; } else { document . write ( " " ) ; } } var S = " " ; var N = S . length ; var K = 1 ; DivideString ( S , N , K ) ;

Index/key variables: i
Accumulator variables: c, c1, c2, i, no
Iterator variables: i
Javascript program:
function check ( S , prices , type , n ) { for ( let j = 0 ; j < n ; j ++ ) { for ( let k = j + 1 ; k < n ; k ++ ) { if ( ( type [ j ] == 0 && type [ k ] == 1 ) || ( type [ j ] == 1 && type [ k ] == 0 ) ) { if ( prices [ j ] + prices [ k ] <= S ) { return " " ; } } } } return " " ; } let prices = [ 3 , 8 , 6 , 5 ] ; let type = [ 0 , 1 , 1 , 0 ] ; let S = 10 ; let n = 4 ; document . write ( check ( S , prices , type , n ) ) ;

Index/key variables: j, k
Accumulator variables: j, k
Iterator variables: j, k
Javascript program:
function getLargestSum ( N ) { let max_sum = 0 ; for ( let i = 1 ; i * i <= N ; i ++ ) { for ( let j = i + 1 ; j * j <= N ; j ++ ) { let k = parseInt ( N / j , 10 ) ; let a = k * i ; let b = k * j ; if ( a <= N && b <= N && a * b % ( a + b ) == 0 ) max_sum = Math . max ( max_sum , a + b ) ; } } return max_sum ; } let N = 25 ; let max_sum = getLargestSum ( N ) ; document . write ( max_sum + " " ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function encryptString ( str , n ) { let i = 0 , cnt = 0 ; let encryptedStr = " " ; while ( i < n ) { cnt = i + 1 ; while ( cnt -- > 0 ) encryptedStr += str [ i ] ; i ++ ; } return encryptedStr ; } let str = " " ; let n = str . length ; document . write ( encryptString ( str , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, encryptedStr, i
Javascript program:
function minDiff ( n , x , A ) { var mn = A [ 0 ] , mx = A [ 0 ] ; for ( var i = 0 ; i < n ; ++ i ) { mn = Math . min ( mn , A [ i ] ) ; mx = Math . max ( mx , A [ i ] ) ; } return Math . max ( 0 , mx - mn - 2 * x ) ; } var n = 3 , x = 3 ; var A = [ 1 , 3 , 6 ] ; document . write ( minDiff ( n , x , A ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function swapCount ( s ) { let chars = s . split ( ' ' ) ; let countLeft = 0 , countRight = 0 ; let swap = 0 , imbalance = 0 ; for ( let i = 0 ; i < chars . length ; i ++ ) { if ( chars [ i ] == ' ' ) { countLeft ++ ; if ( imbalance > 0 ) { swap += imbalance ; imbalance -- ; } } else if ( chars [ i ] == ' ' ) { countRight ++ ; imbalance = ( countRight - countLeft ) ; } } return swap ; } let s = " " ; document . write ( swapCount ( s ) + " " ) ; s = " " ; document . write ( swapCount ( s ) ) ;

Index/key variables: i
Accumulator variables: countLeft, countRight, i, imbalance, swap
Iterator variables: i
Javascript program:
function longestSubSequence ( A , N ) { let dp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] = 1 ; for ( let j = 0 ; j < i ; j ++ ) { if ( A [ j ] [ 0 ] < A [ i ] [ 0 ] && A [ j ] [ 1 ] > A [ i ] [ 1 ] ) { dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ; } } } document . write ( dp [ N - 1 ] + " " ) ; } let A = [ [ 1 , 2 ] , [ 2 , 2 ] , [ 3 , 1 ] ] ; let N = A . length ; longestSubSequence ( A , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findWays ( N , dp ) { if ( N == 0 ) { return 1 ; } if ( dp [ N ] != - 1 ) { return dp [ N ] ; } let cnt = 0 ; for ( let i = 1 ; i <= 6 ; i ++ ) { if ( N - i >= 0 ) { cnt = cnt + findWays ( N - i , dp ) ; } } return dp [ N ] = cnt ; } let N = 4 ; let dp = new Array ( N + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) dp [ i ] = - 1 ; document . write ( findWays ( N , dp ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findWays ( N ) { let dp = new Array ( N + 1 ) ; dp [ 0 ] = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { dp [ i ] = 0 ; for ( let j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 ) { dp [ i ] = dp [ i ] + dp [ i - j ] ; } } } document . write ( dp [ N ] ) ; } let N = 4 ; findWays ( N ) ;

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