dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function UpdateArr ( arr , n ) { let i = 0 , j = n - 1 ; while ( i < j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i += 2 ; j -= 2 ; } printArr ( arr , n ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; ; UpdateArr ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
const N = 20 ; let fact = new Array ( N ) ; function pre ( ) { fact [ 0 ] = 1 ; for ( let i = 1 ; i < N ; i ++ ) { fact [ i ] = i * fact [ i - 1 ] ; } } function CountPermutation ( a , n ) { let ways = 1 ; a . sort ( ) ; let size = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] == a [ i - 1 ] ) { size ++ ; } else { ways *= fact [ size ] ; size = 1 ; } } ways *= fact [ size ] ; return ways ; } let a = [ 1 , 2 , 4 , 4 , 2 , 4 ] ; let n = a . length ; pre ( ) ; document . write ( CountPermutation ( a , n ) ) ;

Index/key variables: i, size
Accumulator variables: i, size, ways
Iterator variables: i
Javascript program:
function Next_greater ( a , n , x ) { a . sort ( function ( aa , bb ) { return aa - bb } ) ; let low = 0 , high = n - 1 , ans = x + 1 ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( a [ mid ] <= ans ) { if ( a [ mid ] == ans ) { ans ++ ; high = n - 1 ; } low = mid + 1 ; } else high = mid - 1 ; } return ans ; } let a = [ 1 , 5 , 10 , 4 , 7 ] let x = 4 ; let n = a . length ; document . write ( Next_greater ( a , n , x ) ) ;

Index/key variables: mid
Accumulator variables: ans
Javascript program:
const MAX = 100000 ; function xorOnSortedArray ( arr , n , k , x ) { let arr1 = new Array ( MAX + 1 ) . fill ( 0 ) ; let arr2 = new Array ( MAX + 1 ) . fill ( 0 ) ; let xor_val = new Array ( MAX + 1 ) ; for ( let i = 0 ; i < n ; i ++ ) arr1 [ arr [ i ] ] ++ ; for ( let i = 0 ; i <= MAX ; i ++ ) xor_val [ i ] = i ^ x ; while ( k -- ) { let count = 0 ; for ( let i = 0 ; i <= MAX ; i ++ ) { let store = arr1 [ i ] ; if ( arr1 [ i ] > 0 ) { if ( count % 2 == 0 ) { let div = Math . ceil ( arr1 [ i ] / 2 ) ; arr1 [ i ] = arr1 [ i ] - div ; arr2 [ xor_val [ i ] ] += div ; } else if ( count % 2 != 0 ) { let div = parseInt ( arr1 [ i ] / 2 ) ; arr1 [ i ] = arr1 [ i ] - div ; arr2 [ xor_val [ i ] ] += div ; } } count = count + store ; } for ( let i = 0 ; i <= MAX ; i ++ ) { arr1 [ i ] = arr1 [ i ] + arr2 [ i ] ; arr2 [ i ] = 0 ; } } let min = Number . MAX_VALUE ; let max = Number . MIN_VALUE ; for ( let i = 0 ; i <= MAX ; i ++ ) { if ( arr1 [ i ] > 0 ) { if ( min > i ) min = i ; if ( max < i ) max = i ; } } document . write ( min + " " + max ) ; } let arr = [ 605 , 986 ] ; let n = arr . length ; let k = 548 , x = 569 ; xorOnSortedArray ( arr , n , k , x ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function printArrangement ( a , n ) { a . sort ( ) ; var b = Array ( n ) . fill ( 0 ) ; var low = 0 , high = n - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) b [ low ++ ] = a [ i ] ; else b [ high -- ] = a [ i ] ; } for ( i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { if ( b [ n - 1 ] + b [ 1 ] <= b [ i ] ) { document . write ( - 1 ) ; return ; } } else if ( i == ( n - 1 ) ) { if ( b [ n - 2 ] + b [ 0 ] <= b [ i ] ) { document . write ( - 1 ) ; return ; } } else { if ( b [ i - 1 ] + b [ i + 1 ] <= b [ i ] ) { document . write ( - 1 ) ; return ; } } } for ( i = 0 ; i < n ; i ++ ) document . write ( b [ i ] + " " ) ; } var a = [ 1 , 4 , 4 , 3 , 2 ] ; var n = a . length ; printArrangement ( a , n ) ;

Index/key variables: i
Accumulator variables: high, i, low
Iterator variables: i
Javascript program:
function findSubarray ( a , k , n ) { var vec = [ ] ; for ( var i = 0 ; i < n - k + 1 ; i ++ ) { var temp = [ ] ; for ( var j = i ; j < i + k ; j ++ ) { temp . push ( a [ j ] ) ; } vec . push ( temp ) ; } vec . sort ( ) return vec [ vec . length - 1 ] ; } var a = [ 1 , 4 , 3 , 2 , 5 ] ; var k = 4 ; var n = a . length ; var ans = findSubarray ( a , k , n ) ; ans . forEach ( it => { document . write ( it + " " ) } ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function knapSack ( W , wt , val , n ) { var maxratio = - 1000000000 ; var maxindex = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( parseInt ( val [ i ] / wt [ i ] ) > maxratio ) { maxratio = ( val [ i ] / wt [ i ] ) ; maxindex = i ; } } return ( W * maxratio ) ; } var val = [ 14 , 27 , 44 , 19 ] ; var wt = [ 6 , 7 , 9 , 8 ] ; var n = val . length ; var W = 50 ; document . write ( knapSack ( W , wt , val , n ) . toFixed ( 3 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortArray ( a , n ) { var ans = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) ans . push ( a [ i ] ) ; } ans . sort ( ( a , b ) => a - b ) ; var j = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) { a [ i ] = ans [ j ] ; j ++ ; } } for ( var i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ; } var arr = [ 2 , - 6 , - 3 , 8 , 4 , 1 ] ; var n = arr . length ; sortArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function solution ( arr , x ) { arr . sort ( ( a , b ) => a - b ) ; let closestSum = 1000000000 ; for ( let i = 0 ; i < arr . length - 2 ; i ++ ) { let ptr1 = i + 1 , ptr2 = arr . length - 1 ; while ( ptr1 < ptr2 ) { let sum = arr [ i ] + arr [ ptr1 ] + arr [ ptr2 ] ; if ( Math . abs ( 1 * x - sum ) < Math . abs ( 1 * x - closestSum ) ) { closestSum = sum ; } if ( sum > x ) { ptr2 -- ; } else { ptr1 ++ ; } } } return closestSum ; } let arr = [ - 1 , 2 , 1 , - 4 ] ; let x = 1 ; document . write ( solution ( arr , x ) ) ;

Index/key variables: i, ptr1, ptr2
Accumulator variables: i, ptr1, ptr2
Iterator variables: i
Javascript program:
class Node { constructor ( num ) { this . data = num ; this . left = this . right = null ; } } function inorder ( root ) { if ( root != null ) { inorder ( root . left ) ; document . write ( root . data + " " ) ; inorder ( root . right ) ; } } function merge ( root1 , root2 ) { if ( root1 == null && root2 == null ) return ; if ( root1 == null ) { inorder ( root2 ) ; return ; } if ( root2 == null ) { inorder ( root1 ) ; return ; } let temp1 = root1 ; let prev1 = null ; while ( temp1 . left != null ) { prev1 = temp1 ; temp1 = temp1 . left ; } let temp2 = root2 ; let prev2 = null ; while ( temp2 . left != null ) { prev2 = temp2 ; temp2 = temp2 . left ; } if ( temp1 . data <= temp2 . data ) { document . write ( temp1 . data + " " ) ; if ( prev1 == null ) { merge ( root1 . right , root2 ) ; } else { prev1 . left = temp1 . right ; merge ( root1 , root2 ) ; } } else { document . write ( temp2 . data + " " ) ; if ( prev2 == null ) { merge ( root1 , root2 . right ) ; } else { prev2 . left = temp2 . right ; merge ( root1 , root2 ) ; } } } let root1 = null , root2 = null ; root1 = new Node ( 3 ) ; root1 . left = new Node ( 1 ) ; root1 . right = new Node ( 5 ) ; root2 = new Node ( 4 ) ; root2 . left = new Node ( 2 ) ; root2 . right = new Node ( 6 ) ; merge ( root1 , root2 ) ;

Class/struct names: Node
Javascript program:
function IsSorted ( A , B , n ) { for ( var i = 0 ; i < n ; i ++ ) { var x , y ; x = Math . max ( A [ i ] , B [ i ] ) ; y = Math . min ( A [ i ] , B [ i ] ) ; A [ i ] = x ; B [ i ] = y ; } for ( var i = 1 ; i < n ; i ++ ) { if ( A [ i ] <= A [ i - 1 ] B [ i ] <= B [ i - 1 ] ) return false ; } return true ; } var A = [ 1 , 4 , 3 , 5 , 7 ] ; var B = [ 2 , 2 , 5 , 8 , 9 ] ; var n = A . length ; document . write ( IsSorted ( A , B , n ) ? " " : " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function K_multiple ( a , n , k ) { a . sort ( ( a , b ) => a - b ) ; let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] % k == 0 && ! s . has ( a [ i ] / k ) ) a [ i ] % k != 0 ) s . add ( a [ i ] ) ; } for ( let i of s ) { document . write ( i + " " ) ; } } let a = [ 2 , 3 , 4 , 5 , 6 , 10 ] ; let k = 2 ; let n = a . length ; K_multiple ( a , n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxWater ( height , n ) { var maximum = 0 ; var i = 0 , j = n - 1 ; while ( i < j ) { if ( height [ i ] < height [ j ] ) { maximum = Math . max ( maximum , ( j - i - 1 ) * height [ i ] ) ; i ++ ; } else if ( height [ j ] < height [ i ] ) { maximum = Math . max ( maximum , ( j - i - 1 ) * height [ j ] ) ; j -- ; } else { maximum = Math . max ( maximum , ( j - i - 1 ) * height [ i ] ) ; i ++ ; j -- ; } } return maximum ; } var height = [ 2 , 1 , 3 , 4 , 6 , 5 ] ; var n = height . length ; document . write ( maxWater ( height , n ) )

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function maxSelectionCount ( a , n ) { var res = 0 ; a . sort ( ) ; var select = 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= select ) { res ++ ; select ++ ; } } return res ; } var arr = [ 4 , 2 , 1 , 3 , 5 , 1 , 4 ] ; var N = arr . length ; document . write ( maxSelectionCount ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, res, select
Iterator variables: i
Javascript program:
function findCombinationsUtil ( arr , index , n , red_num ) { var s = new Set ( ) ; var sum = 0 ; if ( red_num < 0 ) { return ; } if ( red_num === 0 ) { for ( var i = 0 ; i < index ; i ++ ) { s . add ( arr [ i ] ) ; } for ( const itr of s ) { sum = sum + itr ; } if ( sum === n ) { for ( const i of s ) { document . write ( i + " " ) ; } document . write ( " " ) ; return ; } } var prev = index === 0 ? 1 : arr [ index - 1 ] ; for ( var k = prev ; k <= n ; k ++ ) { if ( index < n ) { arr [ index ] = k ; findCombinationsUtil ( arr , index + 1 , n , red_num - k ) ; } } } function findCombinations ( n ) { var a = new Array ( n ) . fill ( 0 ) ; findCombinationsUtil ( a , 0 , n , n ) ; } var n = 7 ; findCombinations ( n ) ;

Index/key variables: i, index
Accumulator variables: i, k
Iterator variables: i, itr, k
Javascript program:
function check ( arr , n ) { var modify = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { arr [ 0 ] = arr [ 1 ] / 2 ; modify ++ ; } for ( var i = 1 ; i < n - 1 ; i ++ ) { if ( ( arr [ i - 1 ] < arr [ i ] && arr [ i + 1 ] < arr [ i ] ) || ( arr [ i - 1 ] > arr [ i ] && arr [ i + 1 ] > arr [ i ] ) ) { arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) / 2 ; if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i + 1 ] ) return false ; modify ++ ; } } if ( arr [ n - 1 ] < arr [ n - 2 ] ) modify ++ ; if ( modify > 1 ) return false ; return true ; } var arr = [ 2 , 4 , 8 , 6 , 9 , 12 ] ; var n = arr . length ; if ( check ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, modify
Iterator variables: i
Javascript program:
let N = 2 ; let M = 2 ; function isMatrixInc ( a ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( i - 1 >= 0 ) { if ( a [ i ] [ j ] <= a [ i - 1 ] [ j ] ) return false ; } if ( j - 1 >= 0 ) { if ( a [ i ] [ j ] <= a [ i ] [ j - 1 ] ) return false ; } } } return true ; } let a = [ [ 2 , 10 ] , [ 11 , 20 ] ] ; if ( isMatrixInc ( a ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const N = 1e7 + 5 ; let prime = new Array ( N ) ; function seive ( ) { for ( let i = 2 ; i < N ; i ++ ) { if ( ! prime [ i ] ) { for ( let j = i + i ; j < N ; j += i ) { prime [ j ] = 1 ; } } } prime [ 1 ] = 1 ; } function maxSizeArr ( arr , n , k ) { let v = new Array ( ) ; let diff = new Array ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) v . push ( i ) ; } for ( let i = 1 ; i < v . length ; i ++ ) { diff . push ( v [ i ] - v [ i - 1 ] - 1 ) ; } diff . sort ( ( a , b ) => a - b ) ; for ( let i = 1 ; i < diff . length ; i ++ ) { diff [ i ] += diff [ i - 1 ] ; } if ( k > n || ( k == 0 && v . length ) ) { return - 1 ; } else if ( v . length <= k ) { return ( n - k ) ; } else if ( v . length > k ) { let tt = v . length - k ; let sum = 0 ; sum += diff [ tt - 1 ] ; let res = n - ( v . length + sum ) ; return res ; } } seive ( ) ; let arr = [ 2 , 4 , 2 , 2 , 4 , 2 , 4 , 2 ] ; let n = arr . length ; let k = 2 ; document . write ( maxSizeArr ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function sortArr ( arr , n ) { let map = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { let count = 0 ; let k = arr [ i ] ; while ( k ) { k = k & k - 1 ; count ++ ; } map . push ( [ 32 - count , arr [ i ] ] ) ; } map . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; for ( let i = 0 ; i < map . length ; i ++ ) { document . write ( map [ i ] [ 1 ] + " " ) ; } } let arr = [ 5 , 2 , 3 , 9 , 4 , 6 , 7 , 15 , 32 ] ; let n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
const mod = 1000000007 ; function fact ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return parseInt ( fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ) ; } function powmod ( a , n ) { if ( ! n ) return 1 ; let pt = powmod ( a , parseInt ( n / 2 ) ) ; pt = ( pt * pt ) % mod ; if ( n % 2 ) return ( pt * a ) % mod ; else return pt ; } function CountSubset ( arr , n ) { let ans = powmod ( 2 , n - 1 ) ; arr . sort ( ) ; for ( let i = 0 ; i < n ; ++ i ) { let j = i + 1 ; while ( j < n && arr [ j ] == arr [ i ] ) { let r = n - 1 - j ; let l = i ; ans = ( ans + nCr ( l + r , l ) ) % mod ; j ++ ; } } return ans ; } let arr = [ 2 , 3 , 2 ] ; let n = arr . length ; document . write ( CountSubset ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
let mod = 1000000007 ; let arr = [ ] ; for ( let i = 0 ; i < 1001 ; i ++ ) { arr [ i ] = [ ] ; for ( let j = 0 ; j < 1001 ; j ++ ) { arr [ i ] [ j ] = 0 ; } } function Preprocess ( ) { arr [ 0 ] [ 0 ] = 1 ; for ( let i = 1 ; i <= 1000 ; ++ i ) { arr [ i ] [ 0 ] = 1 ; for ( let j = 1 ; j < i ; ++ j ) { arr [ i ] [ j ] = ( arr [ i - 1 ] [ j - 1 ] + arr [ i - 1 ] [ j ] ) % mod ; } arr [ i ] [ i ] = 1 ; } } function powmod ( a , n ) { if ( ! n ) return 1 ; let pt = powmod ( a , Math . floor ( n / 2 ) ) ; pt = ( pt * pt ) % mod ; if ( n % 2 ) return ( pt * a ) % mod ; else return pt ; } function CountSubset ( val , n ) { let ans = powmod ( 2 , n - 1 ) ; val . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < n ; ++ i ) { let j = i + 1 ; while ( j < n && val [ j ] == val [ i ] ) { let r = n - 1 - j ; let l = i ; ans = ( ans + arr [ l + r ] [ l ] ) % mod ; j ++ ; } } return ans ; } Preprocess ( ) ; let val = [ 2 , 3 , 2 ] ; let n = val . length ; document . write ( CountSubset ( val , n ) , ' ' ) ;

Index/key variables: i, j, l
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function reArrange ( words , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) mp . set ( words [ i ] , i + 1 ) ; words . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( mp . get ( words [ i ] ) + " " ) ; } } var words = [ " " , " " , " " , " " , " " ] ; var n = words . length ; reArrange ( words , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSumofEle ( arr1 , m , arr2 , n ) { let MAX = 100000 ; let hash = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) hash [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) hash [ arr2 [ i ] ] ++ ; for ( let i = 1 ; i < MAX ; i ++ ) hash [ i ] = hash [ i ] + hash [ i - 1 ] ; let maximumFreq = 0 ; for ( let i = 0 ; i < m ; i ++ ) { maximumFreq = Math . max ( maximumFreq , hash [ arr1 [ i ] ] ) ; } let sumOfElements = 0 ; for ( let i = 0 ; i < m ; i ++ ) { if ( maximumFreq == hash [ arr1 [ i ] ] ) sumOfElements += arr1 [ i ] ; } return sumOfElements ; } let arr1 = [ 2 , 5 , 6 , 8 ] ; let arr2 = [ 4 , 10 ] ; let m = arr1 . length ; let n = arr2 . length ; document . write ( findSumofEle ( arr1 , m , arr2 , n ) ) ;

Index/key variables: i
Accumulator variables: i, sumOfElements
Iterator variables: i
Javascript program:
function PrletBothArrays ( a , n ) { let v1 = [ ] , v2 = [ ] ; let mpp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mpp . set ( a [ i ] , ( mpp . get ( a [ i ] ) == null ? 0 : mpp . get ( a [ i ] ) ) + 1 ) ; if ( mpp . get ( a [ i ] ) == 1 ) v1 . push ( a [ i ] ) ; else if ( mpp . get ( a [ i ] ) == 2 ) v2 . push ( a [ i ] ) ; else { document . write ( " " ) ; return ; } } v1 . sort ( ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < v1 . length ; i ++ ) document . write ( v1 [ i ] + " " ) ; v2 . sort ( ) ; v2 . reverse ( ) ; document . write ( " " + " " + " " ) ; for ( let i = 0 ; i < v2 . length ; i ++ ) document . write ( v2 [ i ] + " " ) ; } let a = [ 7 , 2 , 7 , 3 , 3 , 1 , 4 ] ; let n = a . length ; PrletBothArrays ( a , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isUgly ( n ) { while ( n % 2 == 0 ) n = n / 2 ; while ( n % 3 == 0 ) n = n / 3 ; while ( n % 5 == 0 ) n = n / 5 ; if ( n == 1 ) return true ; return false ; } function sortUglyNumbers ( arr , n ) { var list = [ ] ; var i ; for ( i = 0 ; i < n ; i ++ ) { if ( isUgly ( arr [ i ] ) ) { list . push ( arr [ i ] ) ; arr [ i ] = - 1 ; } } list . sort ( ( a , b ) => a - b ) ; var j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == - 1 ) document . write ( list [ j ++ ] + " " ) ; else document . write ( arr [ i ] + " " ) ; } } var arr = [ 1 , 2 , 3 , 7 , 12 , 10 ] ; var n = arr . length ; sortUglyNumbers ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function sortArr ( arr , n , k ) { var prev = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { if ( prev != - 1 ) var tmp = arr . slice ( prev + 1 , i ) . sort ( ( a , b ) => a - b ) ; for ( var j = prev + 1 ; j < i ; j ++ ) { arr [ j ] = tmp [ j - prev - 1 ] ; } prev = i ; } } printArr ( arr , n ) ; } var arr = [ 2 , 1 , 13 , 3 , 7 , 8 , 21 , 13 , 12 ] ; var n = arr . length ; var k = 2 ; sortArr ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printNumbers ( arr , n ) { arr . sort ( ( a , b ) => { return a - b ; } ) ; var A = arr [ n - 1 ] , B = - 1 ; for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( ( A % arr [ i ] ) != 0 ) { B = arr [ i ] ; break ; } if ( i - 1 >= 0 && arr [ i ] == arr [ i - 1 ] ) { B = arr [ i ] ; break ; } } document . write ( " " + A + " " + B ) ; } var arr = [ 1 , 2 , 4 , 8 , 16 , 1 , 2 , 4 ] ; var n = arr . length ; printNumbers ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArray ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function removeMin ( arr , n ) { var i , minVal = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) minVal = Math . min ( minVal , arr [ i ] ) ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] = arr [ i ] - minVal ; } function removeFromMax ( arr , n ) { var i , maxVal = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) maxVal = Math . max ( maxVal , arr [ i ] ) ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] = maxVal - arr [ i ] ; } function modifyArray ( arr , n , k ) { if ( k % 2 == 0 ) removeMin ( arr , n ) ; else removeFromMax ( arr , n ) ; printArray ( arr , n ) ; } arr = [ 4 , 8 , 12 , 16 ] var n = arr . length ; var k = 2 ; modifyArray ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findAnswer ( n , arr ) { arr . sort ( ( a , b ) => a - b ) ; let sum = 0 ; for ( let i = 0 ; i < Math . floor ( n / 2 ) ; ++ i ) { sum += ( arr [ i ] + arr [ n - i - 1 ] ) * ( arr [ i ] + arr [ n - i - 1 ] ) ; } return sum ; } let arr = new Array ( 53 , 28 , 143 , 5 ) ; let n = arr . length ; document . write ( findAnswer ( n , arr ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Javascript program:
var n = 4 ; function merge ( l , r , output ) { var l_in = l * n , r_in = ( parseInt ( ( l + r ) / 2 ) + 1 ) * n ; var l_c = ( parseInt ( ( l + r ) / 2 ) - l + 1 ) * n ; var r_c = ( r - parseInt ( ( l + r ) / 2 ) ) * n ; var l_arr = Array ( l_c ) , r_arr = Array ( r_c ) ; for ( var i = 0 ; i < l_c ; i ++ ) l_arr [ i ] = output [ l_in + i ] ; for ( var i = 0 ; i < r_c ; i ++ ) r_arr [ i ] = output [ r_in + i ] ; var l_curr = 0 , r_curr = 0 ; var par = l_in ; while ( l_curr + r_curr < l_c + r_c ) { if ( r_curr == r_c || ( l_curr != l_c && l_arr [ l_curr ] < r_arr [ r_curr ] ) ) { output [ par ] = l_arr [ l_curr ] ; l_curr ++ , par ++ ; } else { output [ par ] = r_arr [ r_curr ] ; r_curr ++ , par ++ ; } } } function divide ( l , r , output , arr ) { if ( l == r ) { for ( var i = 0 ; i < n ; i ++ ) output [ l * n + i ] = arr [ l ] [ i ] ; return ; } divide ( l , parseInt ( ( l + r ) / 2 ) , output , arr ) ; divide ( parseInt ( ( l + r ) / 2 ) + 1 , r , output , arr ) ; merge ( l , r , output ) ; } var arr = [ [ 5 , 7 , 15 , 18 ] , [ 1 , 8 , 9 , 17 ] , [ 1 , 4 , 7 , 7 ] ] ; var k = arr . length ; var output = Array ( n * k ) ; divide ( 0 , k - 1 , output , arr ) ; for ( var i = 0 ; i < n * k ; i ++ ) document . write ( output [ i ] + " " ) ;

Index/key variables: i, l, l_curr, par, r_curr
Accumulator variables: i, l_curr, par, r_curr
Iterator variables: i
Javascript program:
function findNonPalinString ( s ) { var freq = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; var flag = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] != s [ 0 ] ) flag = 1 ; freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } if ( flag == 0 ) document . write ( " " ) ; else { for ( var i = 0 ; i < 26 ; i ++ ) for ( var j = 0 ; j < freq [ i ] ; j ++ ) document . write ( String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ) ; } } var s = " " ; findNonPalinString ( s . split ( ' ' ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minOperations ( n , m , k , matrix ) { let arr = new Array ( n * m ) ; arr . fill ( 0 ) ; let mod = matrix [ 0 ] [ 0 ] % k ; for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < m ; ++ j ) { arr [ i * m + j ] = matrix [ i ] [ j ] ; if ( matrix [ i ] [ j ] % k != mod ) { return - 1 ; } } } arr . sort ( function ( a , b ) { return a - b } ) ; let median = arr [ parseInt ( ( n * m ) / 2 , 10 ) ] ; let minOperations = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations += parseInt ( Math . abs ( arr [ i ] - median ) / k , 10 ) ; if ( ( n * m ) % 2 == 0 ) { let median2 = arr [ parseInt ( ( n * m ) / 2 , 10 ) ] ; let minOperations2 = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations2 += parseInt ( Math . abs ( arr [ i ] - median2 ) / k , 10 ) ; minOperations = Math . min ( minOperations , minOperations2 ) ; } return minOperations ; } let matrix = [ [ 2 , 4 , 6 ] , [ 8 , 10 , 12 ] , [ 14 , 16 , 18 ] , [ 20 , 22 , 24 ] ] ; let n = 4 ; let m = 3 ; let k = 2 ; document . write ( minOperations ( n , m , k , matrix ) ) ;

Index/key variables: i, j
Accumulator variables: minOperations, minOperations2
Iterator variables: i, j
Javascript program:
function countDistinct ( arr , n ) { let res = 1 ; for ( let i = 1 ; i < n ; i ++ ) { let j = 0 ; for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] === arr [ j ] ) break ; if ( i === j ) res ++ ; } return res ; } let arr = [ 12 , 10 , 9 , 45 , 2 , 10 , 10 , 45 ] ; let n = arr . length ; document . write ( countDistinct ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function countDistinct ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) { i ++ ; } res ++ ; } return res ; } let arr = [ 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 ] ; let n = arr . length ; document . write ( countDistinct ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i