dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function UniversalSubset ( A , B ) { var n1 = A . length ; var n2 = B . length ; var res = [ ] ; var A_fre = Array . from ( Array ( n1 ) , ( ) => Array ( 26 ) ) ; for ( var i = 0 ; i < n1 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) A_fre [ i ] [ j ] = 0 ; } for ( var i = 0 ; i < n1 ; i ++ ) { for ( var j = 0 ; j < A [ i ] . length ; j ++ ) { A_fre [ i ] [ A [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } var B_fre = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n2 ; i ++ ) { var arr = Array ( 26 ) . fill ( 0 ) ; for ( var j = 0 ; j < B [ i ] . length ; j ++ ) { arr [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ++ ; B_fre [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] = Math . max ( B_fre [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] , arr [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ) ; } } for ( var i = 0 ; i < n1 ; i ++ ) { var flag = 0 ; for ( var j = 0 ; j < 26 ; j ++ ) { if ( A_fre [ i ] [ j ] < B_fre [ j ] ) { flag = 1 ; break ; } } if ( flag == 0 ) res . push ( A [ i ] ) ; } if ( res . length > 0 ) { for ( var i = 0 ; i < res . length ; i ++ ) { for ( var j = 0 ; j < res [ i ] . length ; j ++ ) document . write ( res [ i ] [ j ] ) ; } document . write ( " " ) ; } else document . write ( " " ) ; } var A = [ " " , " " , " " ] ; var B = [ " " , " " ] ; UniversalSubset ( A , B ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findPair ( a , n ) { let min_dist = Number . MAX_VALUE ; let index_a = - 1 , index_b = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( j - i < min_dist ) { if ( a [ i ] % a [ j ] == 0 a [ j ] % a [ i ] == 0 ) { min_dist = j - i ; index_a = i ; index_b = j ; } } } } if ( index_a == - 1 ) { document . write ( " " ) ; } else { document . write ( " " + a [ index_a ] + " " + a [ index_b ] + " " ) ; } } let a = [ 2 , 3 , 4 , 5 , 6 ] ; let n = a . length ; findPair ( a , n ) ;

Index/key variables: i, index_a, index_b, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printNum ( L , R ) { for ( let i = L ; i <= R ; i ++ ) { let temp = i ; let c = 10 ; let flag = 0 ; while ( temp > 0 ) { if ( temp % 10 >= c ) { flag = 1 ; break ; } c = temp % 10 ; temp /= 10 ; } if ( flag == 0 ) document . write ( i + " " ) ; } } let L = 10 , R = 15 ; printNum ( L , R ) ;

Accumulator variables: i, temp
Iterator variables: i
Javascript program:
function findMissing ( arr , left , right , diff ) { if ( right <= left ) return 0 ; let mid = left + parseInt ( ( right - left ) / 2 , 10 ) ; if ( arr [ mid + 1 ] - arr [ mid ] != diff ) return ( arr [ mid ] + diff ) ; if ( mid > 0 && arr [ mid ] - arr [ mid - 1 ] != diff ) return ( arr [ mid - 1 ] + diff ) ; if ( arr [ mid ] == arr [ 0 ] + mid * diff ) return findMissing ( arr , mid + 1 , right , diff ) ; return findMissing ( arr , left , mid - 1 , diff ) ; } function missingElement ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; let diff = parseInt ( ( arr [ n - 1 ] - arr [ 0 ] ) / n , 10 ) ; return findMissing ( arr , 0 , n - 1 , diff ) ; } let arr = [ 2 , 8 , 6 , 10 ] ; let n = arr . length ; document . write ( missingElement ( arr , n ) ) ;

Index/key variables: mid
Javascript program:
function get_subset_count ( arr , K , N ) { ( arr ) . sort ( function ( a , b ) { return a - b ; } ) ; let left , right ; left = 0 ; right = N - 1 ; let ans = 0 ; while ( left <= right ) { if ( arr [ left ] + arr [ right ] < K ) { ans += 1 << ( right - left ) ; left ++ ; } else { right -- ; } } return ans ; } let arr = [ 2 , 4 , 5 , 7 ] ; let K = 8 ; let N = arr . length ; document . write ( get_subset_count ( arr , K , N ) ) ;

Index/key variables: left, right
Accumulator variables: ans, left, right
Javascript program:
function minMaxDiff ( arr , n , k ) { var max_adj_dif = - 1000000000 ; for ( var i = 0 ; i < n - 1 ; i ++ ) max_adj_dif = Math . max ( max_adj_dif , Math . abs ( arr [ i ] - arr [ i + 1 ] ) ) ; if ( max_adj_dif == 0 ) return 0 ; var best = 1 ; var worst = max_adj_dif ; var mid , required ; while ( best < worst ) { mid = ( best + worst ) / 2 ; required = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { required += parseInt ( ( Math . abs ( arr [ i ] - arr [ i + 1 ] ) - 1 ) / mid ) ; } if ( required > k ) best = mid + 1 ; else worst = mid ; } return worst ; } var arr = [ 3 , 12 , 25 , 50 ] ; var n = arr . length ; var k = 7 ; document . write ( minMaxDiff ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, required
Iterator variables: i
Javascript program:
function checkMin ( arr , len ) { var smallest = Number . INFINITY , secondSmallest = Number . INFINITY ; for ( var i = 0 ; i < len ; i ++ ) { if ( arr [ i ] < smallest ) { secondSmallest = smallest ; smallest = arr [ i ] ; } else if ( arr [ i ] < secondSmallest ) { secondSmallest = arr [ i ] ; } } if ( 2 * smallest <= secondSmallest ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 2 , 3 , 4 , 5 ] ; var len = 4 ; checkMin ( arr , len ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function fibonacci ( arr , n ) { let max_val = Math . max ( ... arr ) ; let hash = new Set ( ) ; createHash ( hash , max_val ) ; let minimum = Number . MAX_VALUE ; let maximum = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( hash . has ( arr [ i ] ) ) { minimum = Math . min ( minimum , arr [ i ] ) ; maximum = Math . max ( maximum , arr [ i ] ) ; } } document . write ( minimum + " " + maximum + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; let n = arr . length ; fibonacci ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isValidLen ( s , len , k ) { var n = s . length ; var mp = new Map ( ) ; var right = 0 ; while ( right < len ) { if ( mp . has ( s [ right ] ) ) mp . set ( s [ right ] , mp . get ( s [ right ] ) + 1 ) else mp . set ( s [ right ] , 1 ) right ++ ; } if ( mp . size <= k ) return true ; while ( right < n ) { if ( mp . has ( s [ right ] ) ) mp . set ( s [ right ] , mp . get ( s [ right ] ) + 1 ) else mp . set ( s [ right ] , 1 ) if ( mp . has ( s [ right - len ] ) ) mp . set ( s [ right - len ] , mp . get ( s [ right - len ] ) - 1 ) if ( mp . has ( s [ right - len ] ) && mp . get ( s [ right - len ] ) == 0 ) mp . delete ( s [ right - len ] ) ; if ( mp . size <= k ) return true ; right ++ ; } return mp . size <= k ; } function maxLenSubStr ( s , k ) { var uni = new Set ( ) ; s . split ( ' ' ) . forEach ( x => { uni . add ( x ) ; } ) ; if ( uni . size < k ) return - 1 ; var n = s . length ; var lo = - 1 , hi = n + 1 ; while ( hi - lo > 1 ) { var mid = lo + hi >> 1 ; if ( isValidLen ( s , mid , k ) ) lo = mid ; else hi = mid ; } return lo ; } var s = " " ; var k = 3 ; document . write ( maxLenSubStr ( s , k ) ) ;

Index/key variables: right
Accumulator variables: right
Javascript program:
function isSquarePossible ( arr , n , l ) { let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= l ) cnt ++ ; if ( cnt >= l ) return true ; } return false ; } function maxArea ( arr , n ) { let l = 0 , r = n ; let len = 0 ; while ( l <= r ) { let m = l + Math . floor ( ( r - l ) / 2 ) ; if ( isSquarePossible ( arr , n , m ) ) { len = m ; l = m + 1 ; } else r = m - 1 ; } return ( len * len ) ; } let arr = [ 1 , 3 , 4 , 5 , 5 ] ; let n = arr . length ; document . write ( maxArea ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function insertNames ( arr , n ) { let set = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! set . has ( arr [ i ] ) ) { document . write ( " " + " " ) ; set . add ( arr [ i ] ) ; } else { document . write ( " " + " " ) ; } } } let arr = [ " " , " " , " " ] ; let n = arr . length ; insertNames ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countLessThan ( arr , n , key ) { let l = 0 , r = n - 1 ; let index = - 1 ; while ( l <= r ) { let m = Math . floor ( ( l + r ) / 2 ) ; if ( arr [ m ] < key ) { l = m + 1 ; index = m ; } else { r = m - 1 ; } } return ( index + 1 ) ; } function countGreaterThan ( arr , n , key ) { let l = 0 , r = n - 1 ; let index = - 1 ; while ( l <= r ) { let m = Math . floor ( ( l + r ) / 2 ) ; if ( arr [ m ] <= key ) { l = m + 1 ; } else { r = m - 1 ; index = m ; } } if ( index == - 1 ) return 0 ; return ( n - index ) ; } function countTriplets ( n , a , b , c ) { a . sort ( function ( e , f ) { return e - f ; } ) ; b . sort ( function ( e , f ) { return e - f ; } ) ; c . sort ( function ( e , f ) { return e - f ; } ) ; let count = 0 ; for ( let i = 0 ; i < n ; ++ i ) { let current = b [ i ] ; let low = countLessThan ( a , n , current ) ; let high = countGreaterThan ( c , n , current ) ; count += ( low * high ) ; } return count ; } let a = [ 1 , 5 ] ; let b = [ 2 , 4 ] ; let c = [ 3 , 6 ] ; let size = a . length ; document . write ( countTriplets ( size , a , b , c ) ) ;

Index/key variables: i, m
Accumulator variables: count
Iterator variables: i
Javascript program:
function costToBalance ( s ) { if ( s . length == 0 ) document . write ( 0 ) ; var ans = 0 ; var o = 0 , c = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) o ++ ; if ( s [ i ] == ' ' ) c ++ ; } if ( o != c ) return - 1 ; var a = new Array ( s . Length ) ; if ( s [ 0 ] == ' ' ) a [ 0 ] = 1 ; else a [ 0 ] = - 1 ; if ( a [ 0 ] < 0 ) ans += Math . abs ( a [ 0 ] ) ; for ( var i = 1 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) a [ i ] = a [ i - 1 ] + 1 ; else a [ i ] = a [ i - 1 ] - 1 ; if ( a [ i ] < 0 ) ans += Math . abs ( a [ i ] ) ; } return ans ; } var s ; s = " " ; document . write ( costToBalance ( s ) + " " ) ; s = " " ; document . write ( costToBalance ( s ) + " " ) ;

Index/key variables: i
Accumulator variables: ans, c, i, o
Iterator variables: i
Javascript program:
function missing4 ( arr ) { let helper = [ ] ; for ( let i = 0 ; i < 4 ; i ++ ) { helper [ i ] = 0 ; } for ( let i = 0 ; i < arr . length ; i ++ ) { let temp = Math . abs ( arr [ i ] ) ; if ( temp <= arr . length ) arr [ temp - 1 ] = Math . floor ( arr [ temp - 1 ] * ( - 1 ) ) ; else if ( temp > arr . length ) { if ( temp % arr . length != 0 ) helper [ temp % arr . length - 1 ] = - 1 ; else helper [ ( temp % arr . length ) + arr . length - 1 ] = - 1 ; } } for ( let i = 0 ; i < arr . length ; i ++ ) if ( arr [ i ] > 0 ) document . write ( i + 1 + " " ) ; for ( let i = 0 ; i < helper . length ; i ++ ) if ( helper [ i ] >= 0 ) document . write ( arr . length + i + 1 + " " ) ; return ; } let arr = [ 1 , 7 , 3 , 12 , 5 , 10 , 8 , 4 , 9 ] ; missing4 ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lexiMiddleSmallest ( K , N ) { if ( K % 2 == 0 ) { document . write ( K / 2 + " " ) ; for ( let i = 0 ; i < N - 1 ; ++ i ) { document . write ( K + " " ) ; } document . write ( " " ) ; return ; } let a = [ ] ; for ( let i = 0 ; i < N / 2 ; ++ i ) { if ( a [ a . length - 1 ] == 1 ) { a . pop ( a . length - 1 ) ; } else { a [ a . length - 1 ] -= 1 ; while ( a . length < N ) { a . push ( K ) ; } } } for ( let i in a ) { document . write ( i + " " ) ; } document . write ( " " ) ; } let K = 2 , N = 4 ; lexiMiddleSmallest ( K , N ) ;

Iterator variables: i
Javascript program:
function findLastElement ( arr , N ) { arr . sort ( ) ; let i = 0 ; for ( i = 1 ; i < N ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] != 0 && arr [ i ] - arr [ i - 1 ] != 2 ) { document . write ( " " + " " ) ; return ; } } document . write ( arr [ N - 1 ] + " " ) ; } let arr = [ 2 , 4 , 6 , 8 , 0 , 8 ] ; let N = arr . length ; findLastElement ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxDivisions ( arr , N , X ) { arr . sort ( ) ; let maxSub = 0 ; let size = 0 ; for ( let i = 0 ; i < N ; i ++ ) { size ++ ; if ( arr [ i ] * size >= X ) { maxSub ++ ; size = 0 ; } } document . write ( maxSub + " " ) ; } let arr = [ 1 , 3 , 3 , 7 ] ; let N = arr . length ; let X = 3 ; maxDivisions ( arr , N , X ) ;

Index/key variables: i
Accumulator variables: i, maxSub, size
Iterator variables: i
Javascript program:
function maxPossibleSum ( arr , N ) { arr . sort ( ) ; let sum = 0 ; let j = N - 3 ; while ( j >= 0 ) { sum += arr [ j ] ; j -= 3 ; } document . write ( sum ) ; } let arr = [ 7 , 4 , 5 , 2 , 3 , 1 , 5 , 9 ] ; let N = arr . length ; maxPossibleSum ( arr , N ) ;

Index/key variables: j
Accumulator variables: j, sum
Javascript program:
function insertionSort ( arr , n ) { let i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = key ; } } function printArray ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let arr = [ 12 , 11 , 13 , 5 , 6 ] ; let N = arr . length ; insertionSort ( arr , N ) ; printArray ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function getPairs ( arr , N , K ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] > K * arr [ i + 1 ] ) count ++ ; } } document . write ( count ) ; } let arr = [ 5 , 6 , 2 , 1 ] ; let N = arr . length ; let K = 2 ; getPairs ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function merge ( arr , temp , l , m , r , K ) { let i = l ; let j = m + 1 ; let cnt = 0 ; for ( i = l ; i <= m ; i ++ ) { let found = false ; while ( j <= r ) { if ( arr [ i ] >= K * arr [ j ] ) { found = true ; } else break ; j ++ ; } if ( found == true ) { cnt += j - ( m + 1 ) ; j -- ; } } let k = l ; i = l ; j = m + 1 ; while ( i <= m && j <= r ) { if ( arr [ i ] <= arr [ j ] ) temp [ k ++ ] = arr [ i ++ ] ; else temp [ k ++ ] = arr [ j ++ ] ; } while ( i <= m ) temp [ k ++ ] = arr [ i ++ ] ; while ( j <= r ) temp [ k ++ ] = arr [ j ++ ] ; for ( i = l ; i <= r ; i ++ ) arr [ i ] = temp [ i ] ; return cnt ; } function mergeSortUtil ( arr , temp , l , r , K ) { let cnt = 0 ; if ( l < r ) { let m = parseInt ( ( l + r ) / 2 , 10 ) ; cnt += mergeSortUtil ( arr , temp , l , m , K ) ; cnt += mergeSortUtil ( arr , temp , m + 1 , r , K ) ; cnt += merge ( arr , temp , l , m , r , K ) ; } return cnt ; } function mergeSort ( arr , N , K ) { let temp = new Array ( N ) ; document . write ( mergeSortUtil ( arr , temp , 0 , N - 1 , K ) ) ; } let arr = [ 5 , 6 , 2 , 5 ] ; let N = arr . length ; let K = 2 ; mergeSort ( arr , N , K ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j, k
Iterator variables: i
Boolean variables: found
Javascript program:
function minRemovals ( A , N ) { A . sort ( ) ; let mx = A [ N - 1 ] ; let sum = 1 ; for ( let i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; } if ( sum - mx >= mx ) { document . write ( 0 ) ; } else { document . write ( 2 * mx - sum ) ; } } let A = [ 3 , 3 , 2 ] ; let N = A . length ; minRemovals ( A , N ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( arr1 , arr2 , i , j , n ) { let f = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) f = 1 ; break ; } if ( f == 0 ) return 0 ; if ( i >= n j >= n ) return 0 ; if ( arr1 [ i ] < arr2 [ j ] ) return 1 + minOperations ( arr1 , arr2 , i + 1 , j + 1 , n ) ; return Math . max ( minOperations ( arr1 , arr2 , i , j + 1 , n ) , minOperations ( arr1 , arr2 , i + 1 , j , n ) ) ; } function minOperationsUtil ( arr , n ) { let brr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; brr . sort ( ) ; let f = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != brr [ i ] ) f = 1 ; break ; } if ( f == 1 ) document . write ( minOperations ( arr , brr , 0 , 0 , n ) ) ; else cout << " " ; } let arr = [ 4 , 7 , 2 , 3 , 9 ] ; let n = arr . length ; minOperationsUtil ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function canTransform ( s , t ) { var n = s . length ; var occur = Array . from ( Array ( 26 ) , ( ) => new Array ( ) ) ; for ( var x = 0 ; x < n ; x ++ ) { var ch = s [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; occur [ ch ] . push ( x ) ; } var idx = Array ( 26 ) . fill ( 0 ) ; var poss = true ; for ( var x = 0 ; x < n ; x ++ ) { var ch = t [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( idx [ ch ] >= occur [ ch ] . length ) { poss = false ; break ; } for ( var small = 0 ; small < ch ; small ++ ) { if ( idx [ small ] < occur [ small ] . length && occur [ small ] [ idx [ small ] ] < occur [ ch ] [ idx [ ch ] ] ) { poss = false ; break ; } } idx [ ch ] ++ ; } if ( poss ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var s , t ; s = " " ; t = " " ; canTransform ( s , t ) ;

Index/key variables: ch, small, x
Accumulator variables: small, x
Iterator variables: small, x
Boolean variables: poss
Javascript program:
function inversionCount ( s ) { var freq = Array ( 26 ) . fill ( 0 ) ; var inv = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { var temp = 0 ; for ( var j = 0 ; j < String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; j ++ ) temp += freq [ j ] ; inv += ( i - temp ) ; freq [ s [ i ] - ' ' ] ++ ; } return inv ; } function haveRepeated ( S1 , S2 ) { var freq = Array ( 26 ) . fill ( 0 ) ; S1 . forEach ( i => { if ( freq [ i - ' ' ] > 0 ) return true ; freq [ i - ' ' ] ++ ; } ) ; for ( var i = 0 ; i < 26 ; i ++ ) freq [ i ] = 0 ; S2 . split ( ' ' ) . forEach ( i => { if ( freq [ i - ' ' ] > 0 ) return true ; freq [ i - ' ' ] ++ ; } ) ; return false ; } function checkToMakeEqual ( S1 , S2 ) { var freq = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < S1 . length ; i ++ ) { freq [ S1 [ i ] - ' ' ] ++ ; } var flag = 0 ; for ( var i = 0 ; i < S2 . length ; i ++ ) { if ( freq [ S2 [ i ] - ' ' ] == 0 ) { flag = true ; break ; } freq [ S2 [ i ] - ' ' ] -- ; } if ( flag == true ) { document . write ( " " ) ; return ; } var invCount1 = inversionCount ( S1 ) ; var invCount2 = inversionCount ( S2 ) ; if ( invCount1 == invCount2 || ( invCount1 & 1 ) == ( invCount2 & 1 ) || haveRepeated ( S1 , S2 ) ) { document . write ( " " ) ; } else document . write ( " " ) ; } var S1 = " " , S2 = " " ; checkToMakeEqual ( S1 , S2 ) ;

Index/key variables: i, j
Accumulator variables: i, inv, j, temp
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function sortArr ( a , n ) { let i , k ; k = parseInt ( Math . log ( n ) / Math . log ( 2 ) ) ; k = parseInt ( Math . pow ( 2 , k ) ) ; while ( k > 0 ) { for ( i = 0 ; i + k < n ; i ++ ) if ( a [ i ] > a [ i + k ] ) { let tmp = a [ i ] ; a [ i ] = a [ i + k ] ; a [ i + k ] = tmp ; } k = k / 2 ; } for ( i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let arr = [ 5 , 20 , 30 , 40 , 36 , 33 , 25 , 15 , 10 ] ; let n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumSum ( arr , n , k ) { let elt = ( n / k ) ; let sum = 0 ; arr . sort ( ( a , b ) => a - b ) ; let count = 0 ; let i = n - 1 ; while ( count < k ) { sum += arr [ i ] ; i -- ; count ++ ; } count = 0 ; i = 0 ; while ( count < k ) { sum += arr [ i ] ; i += elt - 1 ; count ++ ; } document . write ( sum ) ; } let Arr = [ 1 , 13 , 7 , 17 , 6 , 5 ] ; let K = 2 ; let size = Arr . length ; maximumSum ( Arr , size , K ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Javascript program:
function findMinSum ( arr , K , L , size ) { if ( K * L > size ) return - 1 ; let minsum = 0 ; arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < K ; i ++ ) minsum += arr [ i ] ; return minsum ; } let arr = [ 2 , 15 , 5 , 1 , 35 , 16 , 67 , 10 ] ; let K = 3 ; let L = 2 ; let length = arr . length ; document . write ( findMinSum ( arr , K , L , length ) ) ;

Index/key variables: i
Accumulator variables: i, minsum
Iterator variables: i
Javascript program:
function findKthSmallest ( arr , n , k ) { let max = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } let counter = Array . from ( { length : max + 1 } , ( _ , i ) => 0 ) ; let smallest = 0 ; for ( let i = 0 ; i < n ; i ++ ) { counter [ arr [ i ] ] ++ ; } for ( let num = 1 ; num <= max ; num ++ ) { if ( counter [ num ] > 0 ) { smallest += counter [ num ] ; } if ( smallest >= k ) { return num ; } } return - 1 ; } let arr = [ 7 , 1 , 4 , 4 , 20 , 15 , 8 ] ; let N = arr . length ; let K = 5 ; document . write ( findKthSmallest ( arr , N , K ) ) ;

Index/key variables: i, num
Accumulator variables: i, num, smallest
Iterator variables: i, num
Javascript program:
function lexNumbers ( n ) { let s = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { s . push ( i . toString ( ) ) ; } s . sort ( ) ; let ans = [ ] ; for ( let i = 0 ; i < n ; i ++ ) ans . push ( parseInt ( s [ i ] ) ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( ans [ i ] + " " ) ; } let n = 15 ; lexNumbers ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 4 ; function func ( a ) { for ( let i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { for ( let j = 0 ; j < N ; j ++ ) { for ( let k = j + 1 ; k < N ; ++ k ) { if ( a [ i ] [ j ] > a [ i ] [ k ] ) { let temp = a [ i ] [ j ] ; a [ i ] [ j ] = a [ i ] [ k ] ; a [ i ] [ k ] = temp ; } } } } else { for ( let j = 0 ; j < N ; j ++ ) { for ( let k = j + 1 ; k < N ; ++ k ) { if ( a [ i ] [ j ] < a [ i ] [ k ] ) { let temp = a [ i ] [ j ] ; a [ i ] [ j ] = a [ i ] [ k ] ; a [ i ] [ k ] = temp ; } } } } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( " " + a [ i ] [ j ] ) ; } document . write ( " " ) ; } } let a = [ [ 5 , 7 , 3 , 4 ] , [ 9 , 5 , 8 , 2 ] , [ 6 , 3 , 8 , 1 ] , [ 5 , 8 , 9 , 3 ] ] ; func ( a ) ;

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j, k
Javascript program:
let g = new Array ( 200005 ) ; for ( let i = 0 ; i < 200005 ; i ++ ) g [ i ] = new Map ( ) ; let s = new Set ( ) ; let ns = new Set ( ) ; function dfs ( x ) { let v = [ ] ; for ( let it of s . values ( ) ) { if ( g [ x ] . get ( it ) != null ) { v . push ( it ) ; } else { ns . add ( it ) ; } } s = ns ; for ( let i of v . values ( ) ) { dfs ( i ) ; } } function weightOfMST ( N ) { let cnt = 0 ; for ( let i = 1 ; i <= N ; ++ i ) { s . add ( i ) ; } let qt = [ ] for ( let t of s . values ( ) ) qt . push ( t ) ; while ( qt . length != 0 ) { ++ cnt ; let t = qt [ 0 ] ; qt . shift ( ) ; dfs ( t ) ; } document . write ( cnt - 4 ) ; } let N = 6 , M = 11 ; let edges = [ [ 1 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 1 , 6 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 2 , 6 ] , [ 3 , 4 ] , [ 3 , 5 ] , [ 3 , 6 ] ] ; for ( let i = 0 ; i < M ; ++ i ) { let u = edges [ i ] [ 0 ] ; let v = edges [ i ] [ 1 ] ; g [ u ] . set ( v , 1 ) ; g [ v ] . set ( u , 1 ) ; } weightOfMST ( N ) ;

Index/key variables: i, u, v, x
Accumulator variables: i
Iterator variables: i, it, t
Javascript program:
function countPairs ( A , B ) { let n = A . length ; let ans = 0 ; A . sort ( ) ; B . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( A [ i ] > B [ ans ] ) { ans ++ ; } } return ans ; } let A = [ 30 , 28 , 45 , 22 ] ; let B = [ 35 , 25 , 22 , 48 ] ; document . write ( countPairs ( A , B ) ) ;

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