dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findlargestAfterDel ( arr , m , del , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( mp . has ( del [ i ] ) ) { mp . set ( del [ i ] , mp . get ( del [ i ] ) + 1 ) ; } else { mp . set ( del [ i ] , 1 ) ; } } let largestElement = Number . MIN_VALUE ; for ( let i = 0 ; i < m ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) - 1 ) ; if ( mp . get ( arr [ i ] ) == 0 ) mp . delete ( arr [ i ] ) ; } else largestElement = Math . max ( largestElement , arr [ i ] ) ; } return largestElement ; } let array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ] ; let m = array . length ; let del = [ 12 , 33 , 56 , 5 ] ; let n = del . length ; document . write ( findlargestAfterDel ( array , m , del , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countAnomalies ( arr , n , k ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = 0 ; j < n ; j ++ ) if ( i != j && Math . abs ( arr [ i ] - arr [ j ] ) <= k ) break ; if ( j == n ) res ++ ; } return res ; } let arr = [ 7 , 1 , 8 ] ; let k = 5 ; let n = arr . length ; document . write ( countAnomalies ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function majorityInMatrix ( arr ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { if ( mp . has ( arr [ i ] [ j ] ) ) { mp . set ( arr [ i ] [ j ] , mp . get ( arr [ i ] [ j ] ) + 1 ) } else mp . set ( arr [ i ] [ j ] , 1 ) ; } } var countMajority = 0 ; mp . forEach ( ( value , key ) => { if ( value >= ( parseInt ( ( N * M ) / 2 ) ) ) { countMajority ++ ; } } ) ; return countMajority ; } var mat = [ [ 1 , 2 , 2 ] , [ 1 , 3 , 2 ] , [ 1 , 2 , 6 ] ] ; document . write ( majorityInMatrix ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: countMajority, i, j
Iterator variables: i, j
Javascript program:
function colMaxDiff ( mat ) { let max_diff = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let max_val = mat [ 0 ] [ i ] , min_val = mat [ 0 ] [ i ] ; for ( let j = 1 ; j < N ; j ++ ) { max_val = Math . max ( max_val , mat [ j ] [ i ] ) ; min_val = Math . min ( min_val , mat [ j ] [ i ] ) ; } max_diff = Math . max ( max_diff , max_val - min_val ) ; } return max_diff ; } let mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 5 , 3 , 5 , 4 , 0 ] , [ 5 , 6 , 7 , 8 , 9 ] , [ 0 , 6 , 3 , 4 , 12 ] , [ 9 , 7 , 12 , 4 , 3 ] ] ; document . write ( " " + colMaxDiff ( mat ) )

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function search ( ar , size ) { let a = 0 , b = size - 1 ; let mid = 0 ; while ( ( b - a ) > 1 ) { mid = ( a + b ) / 2 ; if ( ( ar [ a ] - a ) != ( ar [ mid ] - mid ) ) b = mid ; else if ( ( ar [ b ] - b ) != ( ar [ mid ] - mid ) ) a = mid ; } return ( ar [ a ] + 3 ) ; } let ar = [ 1 , 2 , 3 , 4 , 5 , 6 , 8 ] ; let size = ar . length ; document . write ( " " + search ( ar , size ) ) ;

Index/key variables: a, b, mid
Javascript program:
function deleteElement ( A , L , R , N ) { let i , j = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( i <= L i >= R ) { A [ j ] = A [ i ] ; j ++ ; } } return j ; } let A = [ 5 , 8 , 11 , 15 , 26 , 14 , 19 , 17 , 10 , 14 ] ; let L = 2 , R = 7 ; let n = A . length ; let res_size = deleteElement ( A , L , R , n ) ; for ( let i = 0 ; i < res_size ; i ++ ) document . write ( A [ i ] + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function findmissing ( ar , N ) { var l = 0 , r = N - 1 ; while ( l <= r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( ar [ mid ] != mid + 1 && ar [ mid - 1 ] == mid ) return mid + 1 ; if ( ar [ mid ] != mid + 1 ) r = mid - 1 ; else l = mid + 1 ; } return - 1 ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 7 , 8 ] ; var N = arr . length ; document . write ( findmissing ( arr , N ) ) ;

Index/key variables: mid
Javascript program:
function findFirst ( arr , n , x ) { arr . sort ( ) ; let ptr = lowerBound ( arr , 0 , n , x ) ; return ( arr [ ptr ] != x ) ? - 1 : ( ptr ) ; } function lowerBound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } let x = 20 ; let arr = [ 10 , 30 , 20 , 50 , 20 ] ; let n = arr . length ; document . write ( findFirst ( arr , n , x ) ) ;

Index/key variables: middle, ptr
Javascript program:
function findFirst ( arr , n , x ) { var count = 0 ; var isX = false ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == x ) { isX = true ; } else if ( arr [ i ] < x ) { count ++ ; } } return ( isX == false ) ? - 1 : count ; } var x = 20 , arr = [ 10 , 30 , 20 , 50 , 20 ] ; var n = arr . length ; document . write ( findFirst ( arr , n , x ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: isX
Javascript program:
function findDuplicate ( arr ) { let slow = arr [ 0 ] ; let fast = arr [ 0 ] ; do { slow = arr [ slow ] ; fast = arr [ arr [ fast ] ] ; } while ( slow != fast ) ; let ptr1 = arr [ 0 ] ; let ptr2 = slow ; while ( ptr1 != ptr2 ) { ptr1 = arr [ ptr1 ] ; ptr2 = arr [ ptr2 ] ; } return ptr1 ; } let arr = [ 1 , 3 , 2 , 1 ] ; document . write ( findDuplicate ( arr ) + " " ) ;

Index/key variables: fast, ptr1, ptr2, slow
Javascript program:
let MAX_CHAR = 26 ; function printGreaterCount ( str ) { let len = str . length ; let ans = new Array ( len ) ; ans . fill ( 0 ) ; let count = new Array ( MAX_CHAR ) ; count . fill ( 0 ) ; for ( let i = len - 1 ; i >= 0 ; i -- ) { count [ str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; for ( let j = str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ; j < MAX_CHAR ; j ++ ) { ans [ i ] += count [ j ] ; } } for ( let i = 0 ; i < len ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let str = " " ; printGreaterCount ( str ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printPairs ( arr , n , sum ) { var m = { } ; for ( var i = 0 ; i < n ; i ++ ) { var rem = sum - arr [ i ] ; if ( m . hasOwnProperty ( rem ) ) { var count = m [ rem ] ; for ( var j = 0 ; j < count ; j ++ ) { document . write ( " " + rem + " " + arr [ i ] + " " + " " ) ; } } if ( m . hasOwnProperty ( arr [ i ] ) ) { m [ arr [ i ] ] ++ ; } else { m [ arr [ i ] ] = 1 ; } } } var arr = [ 1 , 5 , 7 , - 1 , 5 ] ; var n = arr . length ; var sum = 6 ; printPairs ( arr , n , sum ) ;

Index/key variables: i, rem
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxProduct ( arr , n ) { if ( n < 4 ) { return - 1 ; } let maxA = Number . MIN_VALUE , maxB = Number . MIN_VALUE , maxC = Number . MIN_VALUE , maxD = Number . MIN_VALUE ; let minA = Number . MAX_VALUE , minB = Number . MAX_VALUE , minC = Number . MAX_VALUE , minD = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxD = maxC ; maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxD = maxC ; maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) { maxD = maxC ; maxC = arr [ i ] ; } else if ( arr [ i ] > maxD ) { maxD = arr [ i ] ; } if ( arr [ i ] < minA ) { minD = minC ; minC = minB ; minB = minA ; minA = arr [ i ] ; } else if ( arr [ i ] < minB ) { minD = minC ; minC = minB ; minB = arr [ i ] ; } else if ( arr [ i ] < minC ) { minD = minC ; minC = arr [ i ] ; } else if ( arr [ i ] < minD ) { minD = arr [ i ] ; } } let x = maxA * maxB * maxC * maxD ; let y = minA * minB * minC * minD ; let z = minA * minB * maxA * maxB ; return Math . max ( x , Math . max ( y , z ) ) ; } let arr = [ 1 , - 4 , 3 , - 6 , 7 , 0 ] ; let n = arr . length ; let max = maxProduct ( arr , n ) ; if ( max == - 1 ) document . write ( " " ) ; else document . write ( " " + max ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countTripletsLessThanL ( n , L , arr ) { arr . sort ( ) ; var ways = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { for ( k = j + 1 ; k < n ; k ++ ) { var mostDistantDistance = arr [ k ] - arr [ i ] ; if ( mostDistantDistance <= L ) { ways ++ ; } } } } return ways ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var L = 3 ; var ans = countTripletsLessThanL ( n , L , arr ) ; document . write ( " " + ans ) ;

Index/key variables: i, k
Accumulator variables: i, j, k, ways
Iterator variables: i, j, k
Javascript program:
function binary_lower ( value , arr , n ) { var start = 0 ; var end = n - 1 ; var ans = - 1 ; var mid ; while ( start <= end ) { mid = parseInt ( ( start + end ) / 2 ) ; if ( arr [ mid ] >= value ) { end = mid - 1 ; ans = mid ; } else { start = mid + 1 ; } } return ans ; } function countTriplet ( arr , n , k ) { var count = 0 ; arr . sort ( ( a , b ) => a - b ) for ( var i = 2 ; i < n ; i ++ ) { var cur = binary_lower ( arr [ i ] - k , arr , n ) ; if ( cur <= i - 2 ) { count += parseInt ( ( ( i - cur ) * ( i - cur - 1 ) ) / 2 ) ; } } return count ; } var arr = [ 1 , 1 , 2 , 2 , 3 ] ; var k = 1 ; var n = arr . length ; document . write ( countTriplet ( arr , n , k ) ) ;

Index/key variables: i, mid
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = ' ' ; this . next = null ; } } ; var head_ref = null ; function maxChar ( head ) { var p = head ; var max = - 1 ; var res = ' ' ; while ( p != null ) { var q = p . next ; var count = 1 ; while ( q != null ) { if ( p . data == q . data ) count ++ ; q = q . next ; } if ( max < count ) { res = p . data ; max = count ; } p = p . next ; } return res ; } function push ( new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; } head_ref = null ; var str = " " ; var st = str . split ( ' ' ) ; var i ; for ( i = 0 ; i < st . length ; i ++ ) push ( st [ i ] ) ; document . write ( maxChar ( head_ref ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Node
Javascript program:
function missingNum ( arr , n ) { let minvalue = Math . min ( ... arr ) ; let xornum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { xornum ^= ( minvalue ) ^ arr [ i ] ; minvalue ++ ; } return xornum ^ minvalue ; } let arr = [ 13 , 12 , 11 , 15 ] ; let n = arr . length ; document . write ( missingNum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, minvalue, xornum
Iterator variables: i
Javascript program:
function findLastIndex ( str , x ) { let index = - 1 ; for ( let i = 0 ; i < str . length ; i ++ ) if ( str [ i ] == x ) index = i ; return index ; } let str = " " ; let x = ' ' ; let index = findLastIndex ( str , x ) ; if ( index == - 1 ) document . write ( " " ) ; else document . write ( " " + index ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findLastIndex ( str , x ) { for ( let i = str . length - 1 ; i >= 0 ; i -- ) if ( str [ i ] == x ) return i ; return - 1 ; } let str = " " ; let x = ' ' ; let index = findLastIndex ( str , x ) ; if ( index == - 1 ) document . write ( " " ) ; else document . write ( " " + index ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countMaxSetBits ( left , right ) { while ( ( left | ( left + 1 ) ) <= right ) left |= left + 1 ; return left ; } let l = 1 , r = 5 ; document . write ( countMaxSetBits ( l , r ) + " " ) ; l = 1 , r = 10 ; document . write ( countMaxSetBits ( l , r ) ) ;

Accumulator variables: left
Javascript program:
class Node { constructor ( item ) { this . key = item ; this . left = null ; this . right = null ; } } function newNode ( item ) { let temp = new Node ( item ) ; return temp ; } function insert ( node , key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } function findFloor ( root , key ) { let curr = root , ans = null ; while ( curr != null ) { if ( curr . key <= key ) { ans = curr ; curr = curr . right ; } else curr = curr . left ; } if ( ans != null ) return ans . key ; return - 1 ; } let N = 25 ; let root = new Node ( N ) ; insert ( root , 19 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; document . write ( findFloor ( root , N ) ) ;

Class/struct names: Node
Javascript program:
function compareStrings ( str1 , str2 ) { let i = 0 ; while ( i < str1 . length - 1 && str1 [ i ] == str2 [ i ] ) i ++ ; if ( str1 [ i ] > str2 [ i ] ) return - 1 ; if ( str1 [ i ] < str2 [ i ] ) return 1 ; else return 0 ; } function searchStr ( arr , str , first , last ) { if ( first > last ) return - 1 ; let mid = parseInt ( ( last + first ) / 2 , 10 ) ; if ( arr [ mid ] == " " ) { let left = mid - 1 ; let right = mid + 1 ; while ( true ) { if ( left < right && right > last ) return - 1 ; if ( right <= last && arr [ right ] != " " ) { mid = right ; break ; } if ( left >= right && ! arr [ left ] == " " ) { mid = left ; break ; } right ++ ; left -- ; } } if ( compareStrings ( str , arr [ mid ] ) == 0 ) return mid ; if ( compareStrings ( str , arr [ mid ] ) < 0 ) return searchStr ( arr , str , mid + 1 , last ) ; return searchStr ( arr , str , first , mid - 1 ) ; } let arr = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let str = " " ; let n = arr . length ; document . write ( searchStr ( arr , str , 0 , n - 1 ) ) ;

Index/key variables: i, left, mid, right
Accumulator variables: i, left, right
Javascript program:
function countPlates ( plates , n ) { var maximum_plates = 1 ; var dp = Array ( n ) . fill ( 1 ) ; for ( var i = 1 ; i < n ; i ++ ) { var cur = dp [ i ] ; for ( var j = i - 1 ; j >= 0 ; j -- ) { if ( plates [ i ] [ 0 ] < plates [ j ] [ 0 ] && plates [ i ] [ 1 ] < plates [ j ] [ 1 ] ) { if ( cur + dp [ j ] > dp [ i ] ) { dp [ i ] = cur + dp [ j ] ; maximum_plates = Math . max ( maximum_plates , dp [ i ] ) ; } } } } return maximum_plates ; } var plates = [ [ 6 , 4 ] , [ 5 , 7 ] , [ 1 , 2 ] , [ 3 , 3 ] , [ 7 , 9 ] ] ; var n = plates . length ; plates . sort ( ( v1 , v2 ) => { return ( ( v2 [ 0 ] * v2 [ 1 ] ) - ( v1 [ 0 ] * v1 [ 1 ] ) ) ; } ) ; document . write ( countPlates ( plates , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countReduction ( num ) { let ans = 0 ; while ( num >= 10 ) { let temp = num ; num = 1 ; while ( temp > 0 ) { let digit = temp % 10 ; temp = Math . floor ( temp / 10 ) ; num *= digit ; } ans ++ ; } return ans ; } function compare ( x , y ) { let x1 = countReduction ( x ) ; let y1 = countReduction ( y ) ; if ( x1 < y1 ) return - 1 ; return 1 ; } function sortArray ( a , n ) { a . sort ( compare ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let arr = [ 39 , 999 , 4 , 9876 ] ; let N = arr . length ; sortArray ( arr , N ) ;

Index/key variables: i
Accumulator variables: ans, i, num
Iterator variables: i
Javascript program:
function canSortString ( S , N ) { let flag = 1 ; let i , j ; for ( let i = N - 2 ; i >= 0 ; i -- ) { if ( S [ i ] == ' ' && S [ i + 1 ] == ' ' ) { break ; } } for ( let j = i ; j >= 0 ; j -- ) { if ( S [ j ] == ' ' && S [ j + 1 ] == ' ' ) { flag = 0 ; break ; } } if ( flag == 0 ) { return " " ; } else { return " " ; } } let S = " " ; let N = S . length ; document . write ( canSortString ( S , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumMex ( arr , N ) { var ans = [ ] ; arr . sort ( ) ; var i ; for ( i = 0 ; i < N ; i ++ ) { if ( i == 0 arr [ i ] != arr [ i - 1 ] ) ans . push ( arr [ i ] ) ; } for ( i = 0 ; i < N ; i ++ ) { if ( i > 0 && arr [ i ] == arr [ i - 1 ] ) ans . push ( arr [ i ] ) ; } for ( i = 0 ; i < N ; i ++ ) document . write ( ans [ i ] + " " ) ; } var arr = [ 1 , 0 , 0 ] ; var N = arr . length ; maximumMex ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function bubble_sort ( ar ) { if ( ar . length <= 1 ) return ar ; if ( ar . length == 2 ) { if ( ar [ 0 ] < ar [ 1 ] ) return ar ; else return [ ar [ 1 ] , ar [ 0 ] ] ; } let a = ar [ 0 ] ; let b = ar [ 1 ] ; let bs = [ ] ; for ( let i = 2 ; i < ar . length ; i ++ ) bs . push ( ar [ i ] ) ; let res = [ ] ; if ( a < b ) { let temp1 = [ ] ; temp1 . push ( b ) ; for ( let i = 0 ; i < bs . length ; i ++ ) temp1 . push ( bs [ i ] ) ; let v = bubble_sort ( temp1 ) ; v . unshift ( a ) ; res = v ; } else { let temp1 = [ ] ; temp1 . push ( a ) ; for ( let i = 0 ; i < bs . length ; i ++ ) temp1 . push ( bs [ i ] ) ; let v = bubble_sort ( temp1 ) ; v . unshift ( b ) ; res = v ; } let pass = [ ] ; for ( let i = 0 ; i < res . length - 1 ; i ++ ) pass . push ( res [ i ] ) ; let ans = bubble_sort ( pass ) ; ans . push ( res [ res . length - 1 ] ) ; return ans ; } let arr = [ 1 , 3 , 4 , 5 , 6 , 2 ] ; let res = bubble_sort ( arr ) ; document . write ( res . join ( " " ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printMatrix ( a ) { for ( let i = 0 ; i < a . length ; i ++ ) { for ( let j = 0 ; j < a [ i ] . length ; j ++ ) { document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function sortBoundaryWise ( a ) { let i , k = 0 , l = 0 ; let m = a . length , n = a [ 0 ] . length ; let n_i , n_k = 0 , n_l = 0 , n_m = m , n_n = n ; while ( k < m && l < n ) { let boundary = [ ] ; for ( i = l ; i < n ; ++ i ) { boundary . push ( a [ k ] [ i ] ) ; } k ++ ; for ( i = k ; i < m ; ++ i ) { boundary . push ( a [ i ] [ n - 1 ] ) ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) { boundary . push ( a [ m - 1 ] [ i ] ) ; } m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { boundary . push ( a [ i ] [ l ] ) ; } l ++ ; } boundary . sort ( function ( a , b ) { return a - b ; } ) ; let ind = 0 ; for ( i = n_l ; i < n_n ; ++ i ) { a [ n_k ] [ i ] = boundary [ ind ] ; ind ++ ; } n_k += 1 ; for ( i = n_k ; i < n_m ; ++ i ) { a [ i ] [ n_n - 1 ] = boundary [ ind ] ; ind ++ ; } n_n -- ; if ( n_k < n_m ) { for ( i = n_n - 1 ; i >= n_l ; -- i ) { a [ n_m - 1 ] [ i ] = boundary [ ind ] ; ind ++ ; } n_m -- ; } if ( n_l < n_n ) { for ( i = n_m - 1 ; i >= n_k ; -- i ) { a [ i ] [ n_l ] = boundary [ ind ] ; ind ++ ; } n_l ++ ; } } printMatrix ( a ) ; } let matrix = [ ] ; let list1 = [ 9 , 7 , 4 , 5 ] ; let list2 = [ 1 , 6 , 2 , - 6 ] ; let list3 = [ 12 , 20 , 2 , 0 ] ; let list4 = [ - 5 , - 6 , 7 , - 2 ] ; matrix . push ( list1 ) ; matrix . push ( list2 ) ; matrix . push ( list3 ) ; matrix . push ( list4 ) ; sortBoundaryWise ( matrix ) ;

Index/key variables: i, ind, j, k, l, n_k, n_l
Accumulator variables: i, ind, j, k, l, m, n, n_k, n_l, n_m, n_n
Iterator variables: i, j
Javascript program:
function minimum_sum ( A , N ) { A . sort ( ) ; var sum = 1000000000 ; for ( var i = 0 ; i <= N - 3 ; i ++ ) { sum = Math . min ( sum , Math . abs ( A [ i ] - A [ i + 1 ] ) + Math . abs ( A [ i + 1 ] - A [ i + 2 ] ) ) ; } document . write ( sum ) ; } var A = [ 1 , 1 , 2 , 3 ] ; var N = A . length ; minimum_sum ( A , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sameChar ( S , N ) { var arr = S . split ( " " ) ; var sorted = arr . sort ( ) ; S = sorted . join ( " " ) ; var mid = S [ parseInt ( N / 2 ) ] . charCodeAt ( 0 ) ; var total_operations = 0 ; for ( var i = 0 ; i < N ; i ++ ) { total_operations += Math . abs ( S [ i ] . charCodeAt ( 0 ) - mid ) ; } document . write ( total_operations ) ; } var S = " " ; var N = S . length ; sameChar ( S , N ) ;

Index/key variables: i
Accumulator variables: i, total_operations
Iterator variables: i
Javascript program:
function maxScore ( i , A , K , N , dp ) { if ( i >= N - 1 ) return A [ N - 1 ] ; if ( dp [ i ] != - 1 ) return dp [ i ] ; let score = - 1000 ; for ( let j = 1 ; j <= K ; j ++ ) { score = Math . max ( score , maxScore ( i + j , A , K , N , dp ) ) ; } return dp [ i ] = score + A [ i ] ; } function getScore ( A , N , K ) { let dp = new Array ( N ) . fill ( - 1 ) ; document . write ( maxScore ( 0 , A , K , N , dp ) ) ; } let A = [ 100 , - 30 , - 50 , - 15 , - 20 , - 30 ] ; let K = 3 ; let N = A . length ; getScore ( A , N , K ) ;

Index/key variables: i
Accumulator variables: j
Iterator variables: j
Javascript program:
function maxScore ( A , K , N ) { var maxheap = [ ] ; var maxScore = 0 ; maxheap . push ( [ A [ 0 ] , 0 ] ) ; for ( var i = 1 ; i < N ; i ++ ) { while ( maxheap [ maxheap . length - 1 ] [ 1 ] < ( i - K ) ) { maxheap . pop ( ) ; } maxScore = A [ i ] + maxheap [ maxheap . length - 1 ] [ 0 ] ; maxheap . push ( [ maxScore , i ] ) ; maxheap . sort ( ) ; } return maxScore ; } var A = [ - 44 , - 17 , - 54 , 79 ] ; var K = 2 ; var N = A . length ; document . write ( maxScore ( A , K , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getCount ( arr , N ) { var count = 0 ; if ( N < 3 ) return 0 ; for ( var b = 0 ; b < N ; b ++ ) { for ( var a = 0 ; a < N ; a ++ ) { if ( a == b ) continue ; for ( var c = 0 ; c < N ; c ++ ) { if ( c == a c == b ) continue ; var d = arr [ b ] * arr [ b ] / 4 ; if ( arr [ a ] * arr <= d ) count ++ ; } } } return count ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var N = arr . length ; document . write ( getCount ( arr , N ) ) ;

Index/key variables: a, b
Accumulator variables: a, b, c, count
Iterator variables: a, b, c
Javascript program:
function findAns ( A , N , X ) { if ( check ( A , X ) ) { return true ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { let gcdd = gcd ( A [ i ] , A [ j ] ) ; if ( gcdd != 1 ) { if ( gcdd <= X ) { return true ; } } } } return false ; } function check ( A , X ) { for ( let i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] > X ) { return false ; } } return true ; } function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } let X = 4 ; let A = [ 2 , 1 , 5 , 3 , 6 ] ; let N = 5 ; document . write ( findAns ( A , N , X ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isIncreasing ( arr ) { for ( let i = 0 ; i < arr . length - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } function sortArr ( arr ) { let prev = - 1 ; for ( let i = 0 ; i < arr . length ; i ++ ) { let optEle = arr [ i ] ; let strEle = arr [ i ] . toString ( ) ; for ( let idx = 0 ; idx < strEle . length ; idx ++ ) { let strEle2 = strEle . substr ( idx ) + strEle . substr ( 0 , idx ) ; let temp = parseInt ( strEle2 ) ; if ( temp >= prev && temp < optEle ) optEle = temp ; } arr [ i ] = optEle ; prev = arr [ i ] ; } if ( isIncreasing ( arr ) ) return arr ; else { arr = [ - 1 ] ; return arr ; } } let arr = [ 511 , 321 , 323 , 432 , 433 ] ; let res = sortArr ( arr ) ; for ( let i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, idx
Iterator variables: i, idx
Javascript program:
function maxSum ( arr , brr , N , K ) { let crr = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { crr . push ( arr [ i ] ) ; } for ( let i = 0 ; i < K ; i ++ ) { crr . push ( brr [ i ] ) ; } crr . sort ( function ( a , b ) { return a - b } ) ; crr . reverse ( ) ; let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( crr [ i ] > 0 ) { sum += crr [ i ] ; } else { break ; } } document . write ( sum ) ; } let arr = [ 7 , 2 , - 1 , 4 , 5 ] ; let N = arr . length ; let brr = [ 1 , 2 , 3 , 2 ] ; let K = brr . length ; maxSum ( arr , brr , N , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countPairs ( A , N ) { var count = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var xo = ( A [ i ] ^ A [ j ] ) ; var mx = Math . max ( A [ i ] , A [ j ] ) ; if ( xo > mx ) { count ++ ; } } } document . write ( count ) ; } var arr = [ 2 , 4 , 3 ] ; var N = arr . length ; countPairs ( arr , N ) ;

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