dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Minimum_Cells ( v ) { let col = new Array ( 3 ) ; let i , j ; for ( i = 0 ; i < 3 ; i ++ ) { let column_number = v [ i ] [ 1 ] ; col [ i ] = column_number ; } col . sort ( function ( a , b ) { return a - b } ) ; v . sort ( ) ; let MidRow = v [ 1 ] [ 0 ] ; let s = new Set ( ) ; let Maxcol = col [ 2 ] , MinCol = col [ 0 ] ; for ( i = MinCol ; i <= Maxcol ; i ++ ) { s . add ( [ MidRow , i ] ) ; } for ( i = 0 ; i < 3 ; i ++ ) { if ( v [ i ] [ 0 ] == MidRow ) continue ; for ( j = Math . min ( v [ i ] [ 0 ] , MidRow ) ; j <= Math . max ( v [ i ] [ 0 ] , MidRow ) ; j ++ ) { s . add ( [ j , v [ i ] [ 0 ] ] ) ; } } return s . size - 2 ; } let v = [ ] ; v . push ( [ 0 , 0 ] ) ; v . push ( [ 1 , 1 ] ) ; v . push ( [ 2 , 2 ] ) ; document . write ( Minimum_Cells ( v ) ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function items ( n , a ) { a . sort ( function ( a , b ) { return a - b } ) ; let z = a [ n - 1 ] ; let x = 1 ; let s = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; if ( s <= z ) x += 1 ; else break ; } return x ; } let n = 5 ; let a = [ 5 , 3 , 1 , 5 , 6 ] ; document . write ( items ( n , a ) ) ;

Index/key variables: i
Accumulator variables: i, s, x
Iterator variables: i
Javascript program:
function bitCount ( x ) { var setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } function sortWithSetbits ( arr , n , k ) { var v1 = [ ] , v2 = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( bitCount ( arr [ i ] ) == k ) { v1 . push ( i ) ; v2 . push ( arr [ i ] ) ; } } v2 . sort ( ( a , b ) => a - b ) ; for ( var i = 0 ; i < v1 . length ; i ++ ) arr [ v1 [ i ] ] = v2 [ i ] ; for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } var arr = [ 14 , 255 , 1 , 7 , 13 ] ; var n = arr . length ; var k = 3 ; sortWithSetbits ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i, setBits
Iterator variables: i
Javascript program:
function numBoxes ( A , n , K ) { A . sort ( function ( a , b ) { return a - b } ) ; let i = 0 , j = ( n - 1 ) ; let ans = 0 ; while ( i <= j ) { ans ++ ; if ( A [ i ] + A [ j ] <= K ) i ++ ; j -- ; } return ans ; } let A = [ 3 , 2 , 2 , 1 ] ; let K = 3 ; let n = A . length ; document . write ( numBoxes ( A , n , K ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . next = this . prev = null ; } } class Node { constructor ( data ) { this . data = data ; this . next = this . prev = null ; } } function countTriplets ( head , x ) { let ptr , ptr1 , ptr2 ; let count = 0 ; let um = new Map ( ) ; for ( ptr = head ; ptr != null ; ptr = ptr . next ) { um . set ( ptr . data , ptr ) ; } for ( ptr1 = head ; ptr1 != null ; ptr1 = ptr1 . next ) { for ( ptr2 = ptr1 . next ; ptr2 != null ; ptr2 = ptr2 . next ) { let p_product = ( ptr1 . data * ptr2 . data ) ; if ( um . has ( x / p_product ) && um . get ( x / p_product ) != ptr1 && um . get ( x / p_product ) != ptr2 ) { count ++ ; } } } return ( count / 3 ) ; } function insert ( head , data ) { let temp = new Node ( ) ; temp . data = data ; temp . next = temp . prev = null ; if ( head == null ) { head = temp ; } else { temp . next = head ; head . prev = temp ; head = temp ; } return head ; } let head = null ; head = insert ( head , 9 ) ; head = insert ( head , 8 ) ; head = insert ( head , 6 ) ; head = insert ( head , 5 ) ; head = insert ( head , 4 ) ; head = insert ( head , 2 ) ; head = insert ( head , 1 ) ; let x = 8 ; document . write ( " " + countTriplets ( head , x ) ) ;

Accumulator variables: count
Iterator variables: ptr, ptr1, ptr2
Class/struct names: Node
Javascript program:
function solve ( N , M , cp , sp ) { let profit = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) profit [ i ] = sp [ i ] - cp [ i ] ; profit . sort ( function ( a , b ) { return b - a ; } ) ; let sum = 0 ; for ( let i = 0 ; i < M ; i ++ ) { if ( profit [ i ] > 0 ) sum += profit [ i ] ; else break ; } return sum ; } let N = 5 , M = 3 ; let CP = [ 5 , 10 , 35 , 7 , 23 ] ; let SP = [ 11 , 10 , 0 , 9 , 19 ] ; document . write ( solve ( N , M , CP , SP ) ) ;

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

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

Index/key variables: i, j
Accumulator variables: j
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; this . prev = null ; } } function insertAtTheBegin ( start_ref , data ) { var ptr1 = new Node ( ) ; ptr1 . data = data ; ptr1 . next = start_ref ; if ( start_ref != null ) start_ref . prev = ptr1 ; start_ref = ptr1 ; return start_ref ; } function printList ( start ) { var temp = start ; document . write ( " " ) ; while ( temp != null ) { document . write ( temp . data + " " ) ; temp = temp . next ; } } function bubbleSort ( start ) { var swapped ; var ptr1 ; var lptr = null ; if ( start == null ) return null ; do { swapped = 0 ; ptr1 = start ; while ( ptr1 . next != lptr ) { if ( ptr1 . data > ptr1 . next . data ) { var t = ptr1 . data ; ptr1 . data = ptr1 . next . data ; ptr1 . next . data = t ; swapped = 1 ; } ptr1 = ptr1 . next ; } lptr = ptr1 ; } while ( swapped != 0 ) ; return start ; } var arr = [ 12 , 56 , 2 , 11 , 1 , 90 ] ; var i ; var start = null ; for ( i = 0 ; i < 6 ; i ++ ) start = insertAtTheBegin ( start , arr [ i ] ) ; document . write ( " " ) ; printList ( start ) ; start = bubbleSort ( start ) ; document . write ( " " ) ; printList ( start ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function substringSort ( arr , n , maxLen ) { let count = new Array ( maxLen ) ; let sortedArr = new Array ( maxLen ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < maxLen ; i ++ ) { sortedArr [ i ] = " " ; } for ( let i = 0 ; i < n ; i ++ ) { let s = arr [ i ] ; let len = s . length ; if ( count [ len - 1 ] == 0 ) { sortedArr [ len - 1 ] = s ; count [ len - 1 ] = 1 ; } else if ( sortedArr [ len - 1 ] == s ) { count [ len - 1 ] ++ ; } else { document . write ( " " + " " ) ; return ; } } let index = 0 ; while ( count [ index ] == 0 ) index ++ ; let prev = index ; let prevString = sortedArr [ prev ] ; index ++ ; for ( ; index < maxLen ; index ++ ) { if ( count [ index ] != 0 ) { let current = sortedArr [ index ] ; if ( current . includes ( prevString ) ) { prev = index ; prevString = current ; } else { document . write ( " " ) ; return ; } } } for ( let i = 0 ; i < maxLen ; i ++ ) { let s = sortedArr [ i ] ; for ( let j = 0 ; j < count [ i ] ; j ++ ) { document . write ( s + " " ) ; } } } let maxLen = 100 ; let arr1 = [ " " , " " , " " , " " , " " , " " ] ; substringSort ( arr1 , arr1 . length , maxLen ) ; let arr2 = [ " " , " " ] ; substringSort ( arr2 , arr2 . length , maxLen ) ;

Index/key variables: i, index, prev
Accumulator variables: i, index, j
Iterator variables: i, j
Javascript program:
function printPairs ( arr , n ) { let pair_exists = false ; arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) { if ( arr . includes ( - arr [ i ] ) ) { document . write ( arr [ i ] + " " + - arr [ i ] + " " ) ; pair_exists = true ; } } else break ; } if ( pair_exists == false ) document . write ( " " ) ; } let arr = [ 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 ] ; let n = arr . length ; printPairs ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: pair_exists
Javascript program:
function findMinimumSwaps ( arr , n , k ) { let pos , num_min , num_max , need_minimum , need_maximum , swaps ; num_min = num_max = need_minimum = 0 ; need_maximum = swaps = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < k ) num_min ++ ; else if ( arr [ i ] > k ) num_max ++ ; } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == k ) { pos = i ; break ; } } let left , right , mid ; left = 0 ; right = n - 1 ; while ( left <= right ) { mid = parseInt ( ( left + right ) / 2 , 10 ) ; if ( arr [ mid ] == k ) { break ; } else if ( arr [ mid ] > k ) { if ( pos > mid ) need_minimum ++ ; else num_min -- ; left = mid + 1 ; } else { if ( pos < mid ) need_maximum ++ ; else num_max -- ; right = mid - 1 ; } } if ( need_minimum > need_maximum ) { swaps = swaps + need_maximum ; num_min = num_min - need_maximum ; need_minimum = need_minimum - need_maximum ; need_maximum = 0 ; } else { swaps = swaps + need_minimum ; num_max = num_max - need_minimum ; need_maximum = need_maximum - need_minimum ; need_minimum = 0 ; } if ( need_maximum > num_max need_minimum > num_min ) return - 1 ; else return ( swaps + need_maximum + need_minimum ) ; } let arr = [ 3 , 10 , 6 , 7 , 2 , 5 , 4 ] , k = 4 ; let n = arr . length ; document . write ( findMinimumSwaps ( arr , n , k ) ) ;

Index/key variables: i, mid
Accumulator variables: i, need_maximum, need_minimum, num_max, num_min
Iterator variables: i
Javascript program:
function reverse ( a ) { var i , k , n = a . length ; var t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } var arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] ; var n = arr . length ; arr . sort ( ) ; reverse ( arr ) ; document . write ( " " + " " ) ; for ( var i = 0 ; i < n ; ++ i ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function Function ( str ) { let l = str . length ; str = ( str . slice ( 0 , Math . floor ( l / 2 ) ) . sort ( ) ) . concat ( str . slice ( Math . floor ( l / 2 ) , l ) . sort ( ) ) ; for ( let i = 0 ; i < Math . floor ( l / 2 ) ; i ++ ) if ( str [ i ] != str [ Math . floor ( l / 2 ) + i ] ) return true ; return false ; } let str = " " . split ( " " ) ; if ( Function ( str ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let inputArray = [ 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 ] ; let outputArray = [ ] ; let indexOfOne = 0 ; function print ( ) { for ( let item of inputArray . values ( ) ) if ( item == 2 ) outputArray . push ( item ) ; else if ( item == 1 ) { outputArray . splice ( indexOfOne , 0 , item ) ; indexOfOne += 1 ; } else if ( item == 0 ) { outputArray . splice ( 0 , 0 , item ) ; indexOfOne += 1 ; } else { document . write ( " " ) ; continue ; } } print ( ) ; for ( let item of outputArray . values ( ) ) document . write ( item + " " ) ;

Accumulator variables: indexOfOne
Iterator variables: item
Javascript program:
function minimumBox ( arr , n ) { var q = [ ] ; arr . sort ( ( a , b ) => a - b ) q . push ( arr [ 0 ] ) ; for ( var i = 1 ; i < n ; i ++ ) { var now = q [ 0 ] ; if ( arr [ i ] >= 2 * now ) q . pop ( 0 ) ; q . push ( arr [ i ] ) ; } return q . length ; } var arr = [ 4 , 1 , 2 , 8 ] ; var n = arr . length ; document . write ( minimumBox ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortBinaryArray ( a , n ) { let j = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] < 1 ) { j ++ ; let temp = a [ j ] ; a [ j ] = a [ i ] ; a [ i ] = temp ; } } } let a = [ 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 ] ; let n = a . length ; sortBinaryArray ( a , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function findDuplicate ( arr , n , k ) { arr . sort ( ) ; let i = 0 ; while ( i < n ) { let j , count = 1 ; for ( j = i + 1 ; j < n && arr [ j ] == arr [ i ] ; j ++ ) count ++ ; if ( count == k ) return arr [ i ] ; i = j ; } return - 1 ; } let arr = [ 2 , 2 , 1 , 3 , 1 ] ; let k = 2 ; let n = arr . length ; document . write ( findDuplicate ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, j
Iterator variables: j
Javascript program:
function longestCommonPrefix ( a ) { let size = a . length ; if ( size == 0 ) return " " ; if ( size == 1 ) return a [ 0 ] ; a . sort ( ) ; let end = Math . min ( a [ 0 ] . length , a [ size - 1 ] . length ) ; let i = 0 ; while ( i < end && a [ 0 ] [ i ] == a [ size - 1 ] [ i ] ) i ++ ; let pre = a [ 0 ] . substring ( 0 , i ) ; return pre ; } let input = [ " " , " " , " " , " " ] ; document . write ( " " + longestCommonPrefix ( input ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function find ( arr , n , k ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; let b = Math . floor ( Math . ceil ( n / k ) ) ; let min_sum = 0 , max_sum = 0 ; for ( let i = 0 ; i < b ; i ++ ) min_sum += arr [ i ] ; for ( let i = 2 ; i < arr . length ; i ++ ) max_sum += arr [ i ] ; document . write ( " " + min_sum + " " ) ; document . write ( " " + max_sum + " " ) ; } let arr = [ 3 , 2 , 1 , 4 ] ; let n = arr . length ; let k = 2 ; find ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: i, max_sum, min_sum
Iterator variables: i
Javascript program:
function checkForSorting ( arr , n ) { let temp = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { if ( arr [ i ] - arr [ i + 1 ] == 1 ) { temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } else return false ; } } return true ; } let arr = new Array ( 1 , 0 , 3 , 2 ) ; let n = arr . length ; if ( checkForSorting ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sort ( s , n ) { for ( let i = 1 ; i < n ; i ++ ) { let temp = s [ i ] ; let j = i - 1 ; while ( j >= 0 && temp . length < s [ j ] . length ) { s [ j + 1 ] = s [ j ] ; j -- ; } s [ j + 1 ] = temp ; } } function printArraystring ( str , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( str [ i ] + " " ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; sort ( arr , n ) ; printArraystring ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function partition ( arr , low , high ) { let pivot = arr [ low ] ; let i = low - 1 , j = high + 1 ; while ( true ) { do { i ++ ; } while ( arr [ i ] < pivot ) ; do { j -- ; } while ( arr [ j ] > pivot ) ; if ( i >= j ) return j ; let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } function quickSort ( arr , low , high ) { if ( low < high ) { let pi = partition ( arr , low , high ) ; quickSort ( arr , low , pi ) ; quickSort ( arr , pi + 1 , high ) ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( " " + arr [ i ] ) ; document . write ( " " ) ; } let arr = [ 10 , 7 , 8 , 9 , 1 , 5 ] ; let n = arr . length ; quickSort ( arr , 0 , n - 1 ) ; document . write ( " " + " " ) ; printArray ( arr , n ) ;

Index/key variables: i, j, low
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function ksmallest ( arr , n , k ) { arr . sort ( function ( a , b ) { return a - b } ) ; if ( k < arr [ 0 ] ) return k ; if ( k == arr [ 0 ] ) return arr [ 0 ] + 1 ; if ( k > arr [ n - 1 ] ) return k + n ; if ( arr [ 0 ] == 1 ) k -- ; else k -= ( arr [ 0 ] - 1 ) ; for ( let i = 1 ; i < n ; i ++ ) { let c = arr [ i ] - arr [ i - 1 ] - 1 ; if ( k <= c ) return arr [ i - 1 ] + k ; else k -= c ; } return arr [ n - 1 ] + k ; } let k = 1 ; let arr = [ 1 ] ; let n = arr . length ; document . write ( ksmallest ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function findSubsequenceCount ( S , T ) { let m = T . length ; let n = S . length ; if ( m > n ) return 0 ; let mat = new Array ( m + 1 ) ; for ( let i = 0 ; i <= m ; i ++ ) { mat [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j <= n ; j ++ ) { mat [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= m ; i ++ ) mat [ i ] [ 0 ] = 0 ; for ( let j = 0 ; j <= n ; j ++ ) mat [ 0 ] [ j ] = 1 ; for ( let i = 1 ; i <= m ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ; else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ; } } return mat [ m ] [ n ] ; } let T = " " ; let S = " " ; document . write ( findSubsequenceCount ( S , T ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var i , j ; function partition ( a , l , r ) { i = l - 1 ; j = r ; var p = l - 1 , q = r ; var v = a [ r ] ; while ( true ) { while ( a [ ++ i ] < v ) ; while ( v < a [ -- j ] ) if ( j == l ) break ; if ( i >= j ) break ; var temp = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = temp ; if ( a [ i ] == v ) { p ++ ; temp = a [ i ] ; a [ i ] = a [ p ] ; a [ p ] = temp ; } if ( a [ j ] == v ) { q -- ; temp = a [ q ] ; a [ q ] = a [ j ] ; a [ j ] = temp ; } } var temp = a [ i ] ; a [ i ] = a [ r ] ; a [ r ] = temp ; j = i - 1 ; for ( k = l ; k < p ; k ++ , j -- ) { temp = a [ k ] ; a [ k ] = a [ j ] ; a [ j ] = temp ; } i = i + 1 ; for ( k = r - 1 ; k > q ; k -- , i ++ ) { temp = a [ i ] ; a [ i ] = a [ k ] ; a [ k ] = temp ; } } function quicksort ( a , l , r ) { if ( r <= l ) return ; i = 0 ; j = 0 ; partition ( a , l , r ) ; quicksort ( a , l , j ) ; quicksort ( a , i , r ) ; } function printarr ( a , n ) { for ( i = 0 ; i < n ; ++ i ) document . write ( " " + a [ i ] ) ; document . write ( " " ) ; } var a = [ 4 , 9 , 4 , 4 , 1 , 9 , 4 , 4 , 9 , 4 , 4 , 1 , 4 ] ; var size = a . length ; printarr ( a , size ) ; quicksort ( a , 0 , size - 1 ) ; printarr ( a , size ) ;

Index/key variables: i, j, k, p, q, r
Accumulator variables: i, j, k, p, q
Iterator variables: i, k
Javascript program:
function checkRBS ( S ) { let N = S . length ; let v = new Array ( N ) ; for ( let i = 0 ; i < N ; ++ i ) { let s = S [ i ] ; let sum = 0 ; let pre = 0 ; for ( let c of s ) { if ( c == " " ) { ++ sum ; } else { -- sum ; } pre = Math . min ( sum , pre ) ; } v [ i ] = [ sum , pre ] ; } let pos = [ ] ; let neg = [ ] ; for ( let i = 0 ; i < N ; ++ i ) { if ( v [ i ] [ 0 ] >= 0 ) { pos . push ( [ - v [ i ] [ 1 ] , v [ i ] [ 0 ] ] ) ; } else { neg . push ( [ v [ i ] [ 0 ] - v [ i ] [ 1 ] , - v [ i ] [ 0 ] ] ) ; } } pos . sort ( ( a , b ) => a - b ) ; let open = 0 ; for ( let p of pos ) { if ( open - p [ 0 ] >= 0 ) { open += p [ 1 ] ; } else { document . write ( " " + " " ) ; return 0 ; } } neg . sort ( ( a , b ) => a - b ) ; let negative = 0 ; for ( let p of neg ) { if ( negative - p [ 0 ] >= 0 ) { negative += p [ 1 ] ; } else { document . write ( " " ) ; return 0 ; } } if ( open != negative ) { document . write ( " " ) ; return 0 ; } document . write ( " " ) ; return 0 ; } let arr = [ " " , " " ] ; checkRBS ( arr ) ;

Index/key variables: i
Accumulator variables: negative, open
Iterator variables: c, i, p
Javascript program:
function maximumUniqueSquares ( N ) { var ans = 0 ; var i ; if ( N < 4 ) { return 0 ; } var len = Math . sqrt ( N ) ; N -= len * len ; for ( i = 1 ; i < len ; i ++ ) { ans += i * i ; } if ( N >= len ) { N -= len ; for ( i = 1 ; i < len ; i ++ ) { ans += i ; } } for ( i = 1 ; i < N ; i ++ ) { ans += i ; } return ans ; } var N = 9 ; document . write ( maximumUniqueSquares ( N ) ) ;

Accumulator variables: N, ans, i
Iterator variables: i
Javascript program:
const findPermutation = ( K , arr ) => { let missing = [ ] ; let visited = new Array ( K + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { visited [ arr [ i ] ] = 1 ; } for ( let i = 1 ; i <= K ; i ++ ) { if ( ! visited [ i ] ) { missing . push ( i ) ; } } const INT_MAX = 2147483647 ; arr . push ( INT_MAX ) ; missing . push ( INT_MAX ) ; let p1 = 0 ; let p2 = 0 ; let ans = [ ] ; while ( ans . length < K ) { if ( arr [ p1 ] < missing [ p2 ] ) { ans . push ( arr [ p1 ] ) ; p1 ++ ; } else { ans . push ( missing [ p2 ] ) ; p2 ++ ; } } for ( let i = 0 ; i < K ; i ++ ) { document . write ( ` ${ ans [ i ] } ` ) ; } } let K = 7 ; let arr = [ 6 , 4 , 2 , 1 ] ; findPermutation ( K , arr ) ;

Index/key variables: i, p1, p2
Accumulator variables: i, p1, p2
Iterator variables: i
Javascript program:
function findRemainingIndex ( N ) { let ans = N ; while ( N > 1 ) { let discard = Math . floor ( Math . sqrt ( N ) ) ; if ( discard * discard == N ) { ans -- ; } N -= discard ; } return ans ; } function findRemainingElement ( arr , N ) { let remainingIndex = findRemainingIndex ( N ) ; document . write ( arr [ remainingIndex - 1 ] ) ; } let arr = [ 2 , 3 , 4 , 4 , 2 , 4 , - 3 , 1 , 1 ] ; let N = arr . length ; findRemainingElement ( arr , N ) ;

Accumulator variables: N, ans
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function checkDistinctPrime ( n ) { let original = n ; let product = 1 ; if ( n % 2 == 0 ) { product *= 2 ; while ( n % 2 == 0 ) { n = parseInt ( n / 2 , 10 ) ; } } for ( let i = 3 ; i < parseInt ( Math . sqrt ( n ) , 10 ) ; i += 2 ) { if ( n % i == 0 ) { product = product * i ; while ( n % i == 0 ) { n = parseInt ( n / i , 10 ) ; } } } if ( n > 2 ) { product = product * n ; } return product == original ; } function check ( pos , subset , unique ) { for ( let num = 0 ; num < subset . length ; num ++ ) { if ( gcd ( subset [ num ] , unique [ pos ] ) != 1 ) { return false ; } } return true ; } function countPrime ( pos , currSubset , unique , frequency ) { if ( pos == unique . length ) { if ( currSubset . length == 0 ) return 0 ; count = 1 ; for ( let element = 0 ; element < currSubset . length ; element ++ ) { count *= frequency [ currSubset [ element ] ] ; } return count ; } if ( check ( pos , currSubset , unique ) ) { return countPrime ( pos + 1 , currSubset , unique , frequency ) + countPrime ( pos + 1 , currSubset + [ unique [ pos ] ] , unique , frequency ) ; } else { return countPrime ( pos + 1 , currSubset , unique , frequency ) ; } } function countSubsets ( arr , N ) { let unique = new Set ( ) ; for ( let element = 0 ; element < arr . length ; element ++ ) { return 5 ; if ( checkDistinctPrime ( element ) ) { unique . add ( element ) ; } } unique = Array . from ( unique ) ; let frequency = new Map ( ) ; for ( let element = 0 ; element < unique . length ; element ++ ) { let freq = 0 ; for ( let i = 0 ; i < unique . length ; i ++ ) { if ( unique [ element ] == unique [ i ] ) { freq ++ ; } } frequency [ element ] = freq ; } let ans = countPrime ( 0 , [ ] , unique , frequency ) ; return ans ; } let arr = [ 2 , 4 , 7 , 10 ] ; let N = arr . length ; let ans = countSubsets ( arr , N ) ; document . write ( ans ) ;

Index/key variables: element, i, num, pos
Accumulator variables: count, element, freq, i, num, product
Iterator variables: element, i, num
Javascript program:
function shortestDistance ( S , N ) { var dic = new Map ( ) ; var dis = new Array ( ) ; var var1 ; for ( i = 0 ; i < N ; i ++ ) { if ( dic [ S [ i ] ] != null ) { var1 = i - dic [ S [ i ] ] ; dic [ S [ i ] ] = i ; dis . push ( var1 ) ; } else { dic [ S [ i ] ] = i ; } } if ( dis . length == 0 ) return - 1 ; else return dis . reduce ( function ( previous , current ) { return previous < current ? previous : current } ) - 1 ; } var S = " " ; var N = 13 ; document . write ( shortestDistance ( S , N ) ) ;

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