dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function number_of_tower ( house , range , n ) { house . sort ( function ( a , b ) { return a - b ; } ) ; let numOfTower = 0 ; let i = 0 ; while ( i < n ) { numOfTower ++ ; let loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; -- i ; loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; } return numOfTower ; } let house = [ 7 , 2 , 4 , 6 , 5 , 9 , 12 , 11 ] ; let range = 2 ; let n = house . length ; document . write ( number_of_tower ( house , range , n ) ) ;

Index/key variables: i
Accumulator variables: i, numOfTower
Javascript program:
function isAlphabaticOrder ( s ) { var n = s . length ; var c = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { c [ i ] = s [ i ] ; } c . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) if ( c [ i ] != s [ i ] ) return false ; return true ; } s = " " ; if ( isAlphabaticOrder ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lexicographicSubConcat ( s ) { var n = s . length ; var sub_count = n * parseInt ( ( n + 1 ) / 2 ) ; var arr = Array ( sub_count ) ; var index = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var len = 1 ; len <= n - i ; len ++ ) arr [ index ++ ] = s . substring ( i , i + len ) ; arr . sort ( ) ; var res = " " ; for ( var i = 0 ; i < sub_count ; i ++ ) res += arr [ i ] ; return res ; } var s = " " ; document . write ( lexicographicSubConcat ( s ) ) ;

Index/key variables: i
Accumulator variables: i, index, len, res
Iterator variables: i, len
Javascript program:
function printVector ( V ) { for ( let e of V ) { document . write ( e + " " ) ; } document . write ( " " ) ; } function insertionSort ( V ) { let N = V . length ; let i , j , key ; for ( i = 1 ; i < N ; i ++ ) { j = i ; while ( j > 0 && V [ j ] < V [ j - 1 ] ) { let temp = V [ j ] ; V [ j ] = V [ j - 1 ] ; V [ j - 1 ] = temp ; j -= 1 ; } } } let A = [ 9 , 8 , 7 , 5 , 2 , 1 , 2 , 3 ] ; document . write ( " " + " " ) ; printVector ( A ) ; document . write ( " " + " " ) ; insertionSort ( A ) ; printVector ( A ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: e, i
Javascript program:
let MAX_CHAR = 26 ; function sortString ( str ) { let letters = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { letters [ i ] = 0 ; } for ( let x = 0 ; x < str . length ; x ++ ) { letters [ str [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { for ( let j = 0 ; j < letters [ i ] ; j ++ ) { document . write ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) ; } } } sortString ( " " ) ;

Index/key variables: i, x
Accumulator variables: i, j, x
Iterator variables: i, j, x
Javascript program:
var MAX = 1000 ; function findDuplicate ( arr , n , k ) { var freq = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 1 && arr [ i ] > MAX ) { document . write ( " " ) ; return - 1 ; } freq [ arr [ i ] ] += 1 ; } for ( var i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == k ) return i ; } return - 1 ; } var arr = [ 2 , 2 , 1 , 3 , 1 ] ; var k = 2 ; var n = arr . length ; document . write ( findDuplicate ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Prefix { constructor ( ) { this . sum = 0 ; this . index = 0 ; } } class Pair { constructor ( a , b ) { this . first = a ; this . second = b ; } } function findSubArray ( arr , n ) { let start = - 1 , end = - 1 , min_diff = Number . MAX_VALUE ; let pre_sum = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) pre_sum [ i ] = new Prefix ( ) ; pre_sum [ 0 ] . sum = 0 ; pre_sum [ 0 ] . index = - 1 ; for ( let i = 1 ; i <= n ; i ++ ) { pre_sum [ i ] . sum = pre_sum [ i - 1 ] . sum + arr [ i - 1 ] ; pre_sum [ i ] . index = i - 1 ; } pre_sum . sort ( function ( a , b ) { return a . sum - b . sum } ) ; for ( let i = 1 ; i <= n ; i ++ ) { let diff = pre_sum [ i ] . sum - pre_sum [ i - 1 ] . sum ; if ( min_diff > diff ) { min_diff = diff ; start = pre_sum [ i - 1 ] . index ; end = pre_sum [ i ] . index ; } } let p = new Pair ( start + 1 , end ) ; return p ; } let arr = [ 2 , 3 , - 4 , - 1 , 6 ] ; let n = arr . length ; let point = findSubArray ( arr , n ) ; document . write ( " " ) ; document . write ( point . first + " " + point . second ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Pair, Prefix
Javascript program:
function binarySearch ( arr , low , high , x ) { while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] > x ) high = mid - 1 ; else low = mid + 1 ; } } function isKSortedArray ( arr , n , k ) { var aux = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) aux [ i ] = arr [ i ] ; aux . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < n ; i ++ ) { var j = binarySearch ( aux , 0 , n - 1 , arr [ i ] ) ; if ( Math . abs ( i - j ) > k ) return " " ; } return " " ; } var arr = [ 3 , 2 , 1 , 5 , 6 , 4 ] ; var n = arr . length ; var k = 2 ; document . write ( " " + isKSortedArray ( arr , n , k ) ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
let MIN_MERGE = 32 ; function minRunLength ( n ) { let r = 0 ; while ( n >= MIN_MERGE ) { r |= ( n & 1 ) ; n >>= 1 ; } return n + r ; } function insertionSort ( arr , left , right ) { for ( let i = left + 1 ; i <= right ; i ++ ) { let temp = arr [ i ] ; let j = i - 1 ; while ( j >= left && arr [ j ] > temp ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } function merge ( arr , l , m , r ) { let len1 = m - l + 1 , len2 = r - m ; let left = new Array ( len1 ) ; let right = new Array ( len2 ) ; for ( let x = 0 ; x < len1 ; x ++ ) { left [ x ] = arr [ l + x ] ; } for ( let x = 0 ; x < len2 ; x ++ ) { right [ x ] = arr [ m + 1 + x ] ; } let i = 0 ; let j = 0 ; let k = l ; while ( i < len1 && j < len2 ) { if ( left [ i ] <= right [ j ] ) { arr [ k ] = left [ i ] ; i ++ ; } else { arr [ k ] = right [ j ] ; j ++ ; } k ++ ; } while ( i < len1 ) { arr [ k ] = left [ i ] ; k ++ ; i ++ ; } while ( j < len2 ) { arr [ k ] = right [ j ] ; k ++ ; j ++ ; } } function timSort ( arr , n ) { let minRun = minRunLength ( MIN_MERGE ) ; for ( let i = 0 ; i < n ; i += minRun ) { insertionSort ( arr , i , Math . min ( ( i + MIN_MERGE - 1 ) , ( n - 1 ) ) ) ; } for ( let size = minRun ; size < n ; size = 2 * size ) { for ( let left = 0 ; left < n ; left += 2 * size ) { let mid = left + size - 1 ; let right = Math . min ( ( left + 2 * size - 1 ) , ( n - 1 ) ) ; if ( mid < right ) merge ( arr , left , mid , right ) ; } } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let arr = [ - 2 , 7 , 15 , - 14 , 0 , 15 , 0 , 7 , - 7 , - 4 , - 13 , 5 , 8 , - 14 , 12 ] ; let n = arr . length ; document . write ( " " ) ; printArray ( arr , n ) ; timSort ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i, j, k, x
Accumulator variables: i, j, k, left, r, x
Iterator variables: i, left, size, x
Javascript program:
function pendulumArrangement ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; var op = [ ... Array ( n ) ] ; var mid = parseInt ( ( n - 1 ) / 2 ) ; var j = 1 , i = 1 ; op [ mid ] = arr [ 0 ] ; for ( i = 1 ; i <= mid ; i ++ ) { op [ mid + i ] = arr [ j ++ ] ; op [ mid - i ] = arr [ j ++ ] ; } if ( n % 2 == 0 ) op [ mid + i ] = arr [ j ] ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( op [ i ] + " " ) ; document . write ( " " ) ; } var arr = [ 14 , 6 , 19 , 21 , 12 ] ; var n = arr . length ; pendulumArrangement ( arr , n ) ;

Index/key variables: i, j, mid
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function minValue ( A , B , n ) { A . sort ( ) ; B . sort ( ) ; let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ; return result ; } let A = [ 3 , 1 , 1 ] ; let B = [ 6 , 5 , 4 ] ; let n = A . length ; document . write ( minValue ( A , B , n ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function TotalPerfectPowerSum ( L , R ) { let pows = [ ] ; pows . push ( 0 ) ; pows . push ( 1 ) ; for ( let p = 2 ; p < 25 ; p ++ ) { let num = 2 ; while ( Math . floor ( Math . pow ( num , p ) + 0.5 ) <= R ) { pows . push ( Math . floor ( Math . pow ( num , p ) + 0.5 ) ) ; num ++ ; } } let ok = new Array ( R + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < pows . length ; i ++ ) { for ( let j = 0 ; j < pows . length ; j ++ ) { if ( pows [ i ] + pows [ j ] <= R && pows [ i ] + pows [ j ] >= L ) { ok [ pows [ i ] + pows [ j ] ] = 1 ; } } } for ( let i = 1 ; i <= R ; i ++ ) { ok [ i ] += ok [ i - 1 ] ; } return ok [ R ] - ok [ L - 1 ] ; } let L = 5 , R = 8 ; document . write ( TotalPerfectPowerSum ( L , R ) ) ;

Index/key variables: R, i, j
Accumulator variables: i, j, num, p
Iterator variables: i, j, p
Javascript program:
class Node { constructor ( val ) { this . left = null ; this . right = null ; this . val = val ; } } function minAbsDiff ( root ) { let minDiff = new Array ( 1 ) ; minDiff [ 0 ] = Number . MAX_VALUE ; postOrder ( root ) ; preOrder ( root , minDiff ) ; return minDiff [ 0 ] ; } function postOrder ( root ) { if ( root == null ) return 0 ; root . val += postOrder ( root . left ) + postOrder ( root . right ) ; return root . val ; } function preOrder ( root , minDiff ) { if ( root == null ) return ; let leftDiff = Math . abs ( root . left . val - ( root . val - root . left . val ) ) ; let rightDiff = Math . abs ( root . right . val - ( root . val - root . right . val ) ) ; minDiff [ 0 ] = Math . min ( minDiff [ 0 ] , Math . min ( leftDiff , rightDiff ) ) ; return ; } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; document . write ( minAbsDiff ( root ) ) ;

Accumulator variables: val
Class/struct names: Node
Javascript program:
function findMaximumSumWithMflips ( arr , N , M ) { let pq = [ ] let sum = 0 for ( let i = 0 ; i < N ; i ++ ) { pq . push ( arr [ i ] ) sum += arr [ i ] pq . sort ( ( a , b ) => a - b ) } while ( M > 0 ) { sum -= pq [ 0 ] temp = - 1 * pq [ 0 ] pq . shift ( ) sum += temp pq . push ( temp ) pq . sort ( ( a , b ) => a - b ) M -= 1 } document . write ( sum ) } let arr = [ - 3 , 7 , - 1 , - 5 , - 3 ] let N = arr . length let M = 4 findMaximumSumWithMflips ( arr , N , M )

Index/key variables: i
Accumulator variables: M, i, sum
Iterator variables: i
Javascript program:
function miniOperToMakeAllEleEqual ( arr , n , k ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } if ( sum % n ) { document . write ( - 1 ) ; return ; } let valueAfterDivision = sum / n ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( Math . abs ( valueAfterDivision - arr [ i ] ) % k != 0 ) { document . write ( - 1 ) ; return ; } count += Math . abs ( valueAfterDivision - arr [ i ] ) / k ; } document . write ( Math . floor ( count / 2 ) ) ; } let n = 3 , k = 3 ; let arr = [ 5 , 8 , 11 ] ; miniOperToMakeAllEleEqual ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function minOperations ( a ) { let res = Number . MAX_VALUE ; let N = a . length ; for ( let r = 0 ; r < 2 ; r ++ ) { let sum = 0 , ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( ( i + r ) % 2 ) { if ( sum <= 0 ) { ans += - sum + 1 ; sum = 1 ; } } else { if ( sum >= 0 ) { ans += sum + 1 ; sum = - 1 ; } } } res = Math . min ( res , ans ) ; } document . write ( res ) ; } let a = [ 1 , - 3 , 1 , 0 ] ; minOperations ( a ) ;

Index/key variables: i
Accumulator variables: ans, i, r, sum
Iterator variables: i, r
Javascript program:
function print1 ( a , b ) { let minProd = 0 ; for ( let i = 0 ; i < a . length ; ++ i ) { document . write ( a [ i ] + " " ) ; } document . write ( " " ) ; for ( let i = 0 ; i < b . length ; ++ i ) { document . write ( b [ i ] + " " ) ; minProd += a [ i ] * b [ i ] ; } document . write ( " " ) ; document . write ( minProd ) ; } function reverse1 ( left , right , arr ) { while ( left < right ) { let temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; ++ left ; -- right ; } } function minimumProdArray ( a , b , l ) { let total = 0 ; for ( let i = 0 ; i < a . length ; ++ i ) { total += a [ i ] * b [ i ] ; } let min = Number . MAX_SAFE_INTEGER ; let first = 0 ; let second = 0 ; for ( let i = 0 ; i < a . length ; ++ i ) { let left = i - 1 ; let right = i + 1 ; let total1 = total ; while ( left >= 0 && right < a . length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } for ( let i = 0 ; i < a . length ; ++ i ) { let left = i ; let right = i + 1 ; let total1 = total ; while ( left >= 0 && right < a . length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } if ( min < total ) { reverse1 ( first , second , a ) ; print1 ( a , b ) ; } else { print1 ( a , b ) ; } } let n = 4 ; let a = [ 2 , 3 , 1 , 5 ] ; let b = [ 8 , 2 , 4 , 3 ] ; minimumProdArray ( a , b , n ) ;

Index/key variables: i, left, right
Accumulator variables: minProd, total, total1
Iterator variables: i
Javascript program:
function MaxCollection ( S , P , Q ) { let maxstr = ( P >= Q ? " " : " " ) . split ( " " ) ; let minstr = ( P >= Q ? " " : " " ) . split ( " " ) ; let maxp = Math . max ( P , Q ) ; let minp = Math . min ( P , Q ) ; let cost = 0 ; let stack1 = [ ] ; let s = S . split ( " " ) ; for ( let ch = 0 ; ch < s . length ; ch ++ ) { if ( stack1 . length != 0 && ( stack1 [ stack1 . length - 1 ] == maxstr [ 0 ] && s [ ch ] == maxstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += maxp ; } else { stack1 . push ( s [ ch ] ) ; } } let sb = [ ] ; while ( stack1 . length != 0 ) sb . push ( stack1 . pop ( ) ) ; sb = sb . reverse ( ) ; let remstr = sb . join ( " " ) ; for ( let ch = 0 ; ch < remstr . length ; ch ++ ) { if ( stack1 . length != 0 && ( stack1 [ stack1 . length - 1 ] == minstr [ 0 ] && remstr [ ch ] == minstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += minp ; } else { stack1 . push ( remstr [ ch ] ) ; } } return cost ; } let S = " " ; let P = 6 ; let Q = 4 ; document . write ( MaxCollection ( S , P , Q ) ) ;

Index/key variables: ch
Accumulator variables: ch, cost
Iterator variables: ch
Javascript program:
function minKBitFlips ( A , K ) { let flip = [ ] ; let count = 0 ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( flip . length != 0 && ( i - flip [ 0 ] >= K ) ) { flip . shift ( ) ; } if ( A [ i ] % 2 == flip . length % 2 ) { if ( i + K - 1 >= A . length ) { return - 1 ; } count ++ ; } } return count ; } let A = [ 0 , 1 , 0 ] ; let K = 1 ; let ans = minKBitFlips ( A , K ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minKBitFlips ( A , K ) { let temp = new Array ( A . length ) ; let count = 0 ; let flip = 0 ; for ( let i = 0 ; i < A . length ; ++ i ) { flip ^= temp [ i ] ; if ( A [ i ] == flip ) { count ++ ; if ( i + K > A . length ) { return - 1 ; } flip ^= 1 ; if ( i + K < A . length ) { temp [ i + K ] ^= 1 ; } } } return count ; } let A = [ 0 , 1 , 0 ] ; let K = 1 ; let ans = minKBitFlips ( A , K ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: count, flip
Iterator variables: i
Javascript program:
function findKthElement ( N , K ) { var v = [ ] ; for ( i = 1 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) { v . push ( i ) ; } } for ( i = 1 ; i <= N ; i ++ ) { if ( i % 2 != 0 ) { v . push ( i ) ; } } document . write ( v [ K - 1 ] ) ; } var N = 10 , K = 3 ; findKthElement ( N , K ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minimize ( n ) { let optEle = n ; let strEle = ( n ) . toString ( ) ; for ( let idx = 0 ; idx < strEle . length ; idx ++ ) { let temp = parseInt ( strEle . substring ( idx ) + strEle . substring ( 0 , idx ) ) ; optEle = Math . min ( optEle , temp ) ; } return optEle ; } function maximize ( n ) { let optEle = n ; let strEle = n . toString ( ) ; for ( let idx = 0 ; idx < strEle . length ; idx ++ ) { let temp = parseInt ( strEle . substring ( idx ) + strEle . substring ( 0 , idx ) ) ; optEle = Math . max ( optEle , temp ) ; } return optEle ; } function minimumDifference ( arr ) { let caseOne = 0 ; let minVal = 0 ; let maxVal = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 == 0 ) minVal += minimize ( arr [ i ] ) ; else maxVal += maximize ( arr [ i ] ) ; } caseOne = Math . abs ( maxVal - minVal ) ; let caseTwo = 0 ; minVal = 0 ; maxVal = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 == 0 ) maxVal += maximize ( arr [ i ] ) ; else minVal += minimize ( arr [ i ] ) ; caseTwo = Math . abs ( maxVal - minVal ) ; } document . write ( Math . max ( caseOne , caseTwo ) + " " ) ; } let arr = [ 332 , 421 , 215 , 584 , 232 ] ; minimumDifference ( arr ) ;

Index/key variables: i
Accumulator variables: i, idx, maxVal, minVal
Iterator variables: i, idx
Javascript program:
function minimumStepReqArr ( arr , N ) { let cntStep = 0 ; N += 1 ; for ( let i = 31 ; i >= 0 ; i -- ) { if ( ( N & ( 1 << i ) ) != 0 ) { cntStep += 1 ; } } return cntStep ; } let arr = [ 1 , 2 , 3 ] ; let N = arr . length ; document . write ( minimumStepReqArr ( arr , N ) ) ;

Accumulator variables: N, cntStep, i
Iterator variables: i
Javascript program:
function minOpsToEmptyString ( S , N ) { let one = 0 , zero = 0 ; let x0 = 0 , x1 = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { x0 ++ ; x1 = 0 ; } else { x1 ++ ; x0 = 0 ; } zero = Math . max ( x0 , zero ) ; one = Math . max ( x1 , one ) ; } document . write ( Math . max ( one , zero ) ) ; } let S = " " ; let N = S . length ; minOpsToEmptyString ( S , N ) ;

Index/key variables: i
Accumulator variables: i, x0, x1
Iterator variables: i
Javascript program:
function ReverseSwap ( mat , n ) { let lowerEle = new Array ( n ) ; let upperEle = new Array ( n ) ; let index ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { index = Math . abs ( i - j ) ; if ( i == j ) { continue ; } else if ( j < i ) { lowerEle [ index ] = mat [ i ] [ j ] ; } else { upperEle [ index ] = mat [ i ] [ j ] ; } } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { index = Math . abs ( i - j ) ; if ( i == j ) { continue ; } else if ( j < i ) { mat [ i ] [ j ] = upperEle [ index ] ; } else { mat [ i ] [ j ] = lowerEle [ index -- ] ; } } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 1 , 2 ] , [ 4 , 5 ] ] ; let N = mat . length ; ReverseSwap ( mat , N ) ;

Index/key variables: i, index, j
Accumulator variables: i, index, j
Iterator variables: i, j
Javascript program:
function primePower ( X ) { let primePow = [ ] ; for ( let i = 2 ; i * i <= X ; i ++ ) { if ( X % i == 0 ) { let p = 1 ; while ( X % i == 0 ) { X /= i ; p *= i ; } primePow . push ( p ) ; } } if ( X > 1 ) { primePow . push ( X ) ; } return primePow ; } function getSum ( ar ) { let sum = 0 ; for ( let i = 0 ; i < ar . length ; i ++ ) { sum += ar [ i ] ; } return sum ; } function getMinSum ( pos , arr , primePow ) { if ( pos == primePow . length ) { return getSum ( arr ) ; } let res = Number . MAX_VALUE ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] *= primePow [ pos ] ; res = Math . min ( res , getMinSum ( pos + 1 , arr , primePow ) ) ; arr [ i ] /= primePow [ pos ] ; } return res ; } function minimumSumWithGivenLCM ( k , x ) { let primePow = primePower ( x ) ; let n = primePow . length ; let sum = 0 ; if ( n <= k ) { for ( let i = 0 ; i < primePow . length ; i ++ ) { sum += primePow [ i ] ; } sum += k - n ; } else { let arr = new Array ( k ) ; for ( let i = 0 ; i < k ; i ++ ) { arr [ i ] = 1 ; } sum = getMinSum ( 0 , arr , primePow ) ; } return sum ; } let k = 3 , x = 210 ; document . write ( minimumSumWithGivenLCM ( k , x ) ) ;

Index/key variables: i, pos
Accumulator variables: X, i, p, sum
Iterator variables: i
Javascript program:
function findMinOperationsReqEmpStr ( str ) { let cntOne = 0 ; let cntZero = 0 ; let N = str . length ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { if ( cntOne != 0 ) { cntOne -- ; } cntZero ++ ; } else { if ( cntZero != 0 ) { cntZero -- ; } cntOne ++ ; } } return ( cntOne + cntZero ) ; } let str = " " ; document . write ( findMinOperationsReqEmpStr ( str ) ) ;

Index/key variables: i
Accumulator variables: cntOne, cntZero, i
Iterator variables: i
Javascript program:
function countChanges ( mat ) { let n = mat . length ; let m = mat [ 0 ] . length ; let ans = 0 ; for ( let j = 0 ; j < m - 1 ; j ++ ) { if ( mat [ n - 1 ] [ j ] != ' ' ) ans ++ ; } for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( mat [ i ] [ m - 1 ] != ' ' ) ans ++ ; } return ans ; } let arr = [ [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] ] ; let cnt = countChanges ( arr ) ; document . write ( cnt ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function printSmallSub ( arr , N ) { let gcdArr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { gcdArr = gcd ( gcdArr , arr [ i ] ) ; } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == gcdArr ) { document . write ( arr [ i ] + " " ) ; return ; } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( gcd ( arr [ i ] , arr [ j ] ) == gcdArr ) { document . write ( arr [ i ] + " " + arr [ j ] ) ; return ; } } } } let arr = [ 4 , 6 , 12 ] ; let N = arr . length ; printSmallSub ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let X = 1000000 ; function getPrimeNum ( ) { let prime = [ ] ; for ( let i = 0 ; i < X ; i ++ ) { prime . push ( true ) ; } prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= prime . length ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= prime . length ; i += p ) prime [ i ] = false ; } } return prime ; } function cntPairs ( arr , N ) { let isPrime = getPrimeNum ( ) ; let cntOne = 0 ; let cntPrime = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { cntOne += 1 ; } else if ( isPrime [ i ] ) { cntPrime += 1 ; } } let cntNonComp = 0 ; cntNonComp = cntPrime * cntOne + Math . floor ( cntOne * ( cntOne - 1 ) / 2 ) ; let res = 0 ; res = N * Math . floor ( ( N - 1 ) / 2 ) - cntNonComp ; return res ; } let arr = [ 1 , 1 , 2 , 2 , 8 ] ; let N = arr . length ; document . write ( cntPairs ( arr , N ) ) ;

Index/key variables: i, p
Accumulator variables: cntOne, cntPrime, i, p
Iterator variables: i, p
Javascript program:
function RearrangeB ( A , B ) { let n = A . length ; if ( n == 1 && A [ 0 ] == B [ 0 ] ) { document . write ( " " ) ; return ; } for ( let i = 0 ; i < n / 2 ; i ++ ) { let t = B [ i ] ; B [ i ] = B [ n - i - 1 ] ; B [ n - i - 1 ] = t ; } for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] == A [ i ] ) { let t = B [ i + 1 ] ; B [ i + 1 ] = B [ i ] ; B [ i ] = t ; break ; } } for ( let k in B ) document . write ( B [ k ] + " " ) ; } let A = [ 2 , 4 , 5 , 8 ] ; let B = [ 2 , 4 , 5 , 8 ] ; RearrangeB ( A , B ) ;

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