dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countSubarrays ( A , N ) { let ans = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) { ans ++ ; for ( let j = i - 1 , k = i + 2 ; j >= 0 && k < N && A [ j ] == A [ i ] && A [ k ] == A [ i + 1 ] ; j -- , k ++ ) { ans ++ ; } } } document . write ( ans + " " ) ; } let A = [ 1 , 1 , 0 , 0 , 1 , 0 ] ; let N = A . length ; countSubarrays ( A , N ) ;

Index/key variables: i, j, k
Accumulator variables: ans, i, j, k
Iterator variables: i, j
Javascript program:
let maxN = 2002 ; let lcount = new Array ( maxN ) ; let rcount = new Array ( maxN ) ; for ( let i = 0 ; i < maxN ; i ++ ) { lcount [ i ] = new Array ( maxN ) ; rcount [ i ] = new Array ( maxN ) ; for ( let j = 0 ; j < maxN ; j ++ ) { lcount [ i ] [ j ] = 0 ; rcount [ i ] [ j ] = 0 ; } } function fill_counts ( a , n ) { let i , j ; let maxA = a [ 0 ] ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] > maxA ) { maxA = a [ i ] ; } } for ( i = 0 ; i < n ; i ++ ) { lcount [ a [ i ] ] [ i ] = 1 ; rcount [ a [ i ] ] [ i ] = 1 ; } for ( i = 0 ; i <= maxA ; i ++ ) { for ( j = 1 ; j < n ; j ++ ) { lcount [ i ] [ j ] = lcount [ i ] [ j - 1 ] + lcount [ i ] [ j ] ; } for ( j = n - 2 ; j >= 0 ; j -- ) { rcount [ i ] [ j ] = rcount [ i ] [ j + 1 ] + rcount [ i ] [ j ] ; } } } function countSubsequence ( a , n ) { let i , j ; fill_counts ( a , n ) ; let answer = 0 ; for ( i = 1 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n - 1 ; j ++ ) { answer += lcount [ a [ j ] ] [ i - 1 ] * rcount [ a [ i ] ] [ j + 1 ] ; } } return answer ; } let a = [ 1 , 2 , 3 , 2 , 1 , 3 , 2 ] ; document . write ( countSubsequence ( a , a . length ) ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function removeOuterParentheses ( S ) { let res = " " ; let count = 0 ; for ( let c = 0 ; c < S . length ; c ++ ) { if ( S . charAt ( c ) == ' ' && count ++ > 0 ) res += S . charAt ( c ) ; if ( S . charAt ( c ) == ' ' && count -- > 1 ) res += S . charAt ( c ) ; } return res ; } let S = " " ; document . write ( removeOuterParentheses ( S ) ) ;

Accumulator variables: c, count, res
Iterator variables: c
Javascript program:
function maxiConsecutiveSubarray ( arr , N ) { let maxi = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { let cnt = 1 , j ; for ( j = i ; j < N - 1 ; j ++ ) { if ( arr [ j + 1 ] == arr [ j ] + 1 ) { cnt ++ ; } else { break ; } } maxi = Math . max ( maxi , cnt ) ; i = j ; } return maxi ; } let N = 11 ; let arr = [ 1 , 3 , 4 , 2 , 3 , 4 , 2 , 3 , 5 , 6 , 7 ] ; document . write ( maxiConsecutiveSubarray ( arr , N ) ) ;

Index/key variables: j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
let N = 100005 ; function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } function digitSum ( number ) { let sum = 0 ; while ( number > 0 ) { sum += ( number % 10 ) ; number = Math . floor ( number / 10 ) ; } return sum ; } function longestCompositeDigitSumSubsequence ( arr , n ) { let count = 0 ; let prime = new Array ( N + 1 ) ; for ( let i = 0 ; i <= N ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , N ) ; for ( let i = 0 ; i < n ; i ++ ) { let res = digitSum ( arr [ i ] ) ; if ( res == 1 ) { continue ; } if ( prime [ res ] == false ) { count ++ ; } } document . write ( count ) ; } let arr = [ 13 , 55 , 7 , 3 , 5 , 1 , 10 , 21 , 233 , 144 , 89 ] ; let n = arr . length ; longestCompositeDigitSumSubsequence ( arr , n ) ;

Index/key variables: i, p, res
Accumulator variables: count, i, p, sum
Iterator variables: i, p
Javascript program:
let sum ; class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newnode ( data ) { let temp = new Node ( data ) ; return temp ; } function insert ( s , i , N , root , temp ) { if ( i == N ) return temp ; if ( s [ i ] == ' ' ) root . left = insert ( s , i + 1 , N , root . left , temp ) ; else root . right = insert ( s , i + 1 , N , root . right , temp ) ; return root ; } function SBTUtil ( root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return root . data ; let left = SBTUtil ( root . left ) ; let right = SBTUtil ( root . right ) ; if ( root . left != null && root . right != null ) { if ( ( left % 2 == 0 && right % 2 != 0 ) || ( left % 2 != 0 && right % 2 == 0 ) ) { sum += root . data ; } } return left + right + root . data ; } function build_tree ( R , N , str , values ) { let root = newnode ( R ) ; let i ; for ( i = 0 ; i < N - 1 ; i ++ ) { let s = str [ i ] ; let x = values [ i ] ; let temp = newnode ( x ) ; root = insert ( s , 0 , s . length , root , temp ) ; } return root ; } function speciallyBalancedNodes ( R , N , str , values ) { let root = build_tree ( R , N , str , values ) ; sum = 0 ; SBTUtil ( root ) ; document . write ( sum + " " ) ; } let N = 7 ; let R = 12 ; let str = [ " " , " " , " " , " " , " " , " " ] ; let values = [ 17 , 16 , 4 , 9 , 2 , 3 ] ; speciallyBalancedNodes ( R , N , str , values ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: Node
Javascript program:
function position ( arr , N ) { let pos = - 1 ; let count ; for ( let i = 0 ; i < N ; i ++ ) { count = 0 ; for ( let j = 0 ; j < N ; j ++ ) { if ( arr [ i ] [ 0 ] <= arr [ j ] [ 0 ] && arr [ i ] [ 1 ] >= arr [ j ] [ 1 ] ) { count ++ ; } } if ( count == N ) { pos = i ; } } if ( pos == - 1 ) { document . write ( pos ) ; } else { document . write ( pos + 1 ) ; } } let arr = [ [ 3 , 3 ] , [ 1 , 3 ] , [ 2 , 2 ] , [ 2 , 3 ] , [ 1 , 2 ] ] ; let N = arr . length ; position ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function ctMinEdits ( str1 , str2 ) { let N1 = str1 . length ; let N2 = str2 . length ; let freq1 = new Array ( 256 ) . fill ( 0 ) ; for ( let i = 0 ; i < N1 ; i ++ ) { freq1 [ str1 [ i ] . charCodeAt ( ) ] ++ ; } let freq2 = new Array ( 256 ) . fill ( 0 ) ; for ( let i = 0 ; i < N2 ; i ++ ) { freq2 [ str2 [ i ] . charCodeAt ( ) ] ++ ; } for ( let i = 0 ; i < 256 ; i ++ ) { if ( freq1 [ i ] > freq2 [ i ] ) { freq1 [ i ] = freq1 [ i ] - freq2 [ i ] ; freq2 [ i ] = 0 ; } else { freq2 [ i ] = freq2 [ i ] - freq1 [ i ] ; freq1 [ i ] = 0 ; } } let sum1 = 0 ; let sum2 = 0 ; for ( let i = 0 ; i < 256 ; i ++ ) { sum1 += freq1 [ i ] ; sum2 += freq2 [ i ] ; } return Math . max ( sum1 , sum2 ) ; } let str1 = " " ; let str2 = " " ; document . write ( ctMinEdits ( str1 . split ( ' ' ) , str2 . split ( ' ' ) ) ) ;

Index/key variables: i
Accumulator variables: i, sum1, sum2
Iterator variables: i
Javascript program:
function CountPairs ( a , b , n ) { var C = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { C [ i ] = a [ i ] + b [ i ] ; } var freqCount = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freqCount . has ( C [ i ] ) ) freqCount . set ( C [ i ] , freqCount . get ( C [ i ] ) + 1 ) else freqCount . set ( C [ i ] , 1 ) } var NoOfPairs = 0 ; freqCount . forEach ( ( value , key ) => { var y = value ; NoOfPairs = NoOfPairs + y * ( y - 1 ) / 2 ; } ) ; document . write ( NoOfPairs ) ; } var arr = [ 1 , 4 , 20 , 3 , 10 , 5 ] ; var brr = [ 9 , 6 , 1 , 7 , 11 , 6 ] ; var N = arr . length ; CountPairs ( arr , brr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function medianChange ( arr1 , arr2 ) { let N = arr1 . length ; let median = [ ] ; if ( ( N & 1 ) ) median . push ( ( arr1 [ Math . floor ( N / 2 ) ] * 1 ) ) ; else median . push ( Math . floor ( ( arr1 [ Math . floor ( N / 2 ) ] + arr1 [ Math . floor ( ( N - 1 ) / 2 ) ] ) / 2 ) ) ; for ( let x = 0 ; x < arr2 . length ; x ++ ) { let it = arr1 . indexOf ( arr2 [ x ] ) ; arr1 . splice ( it , 1 ) ; N -- ; if ( ( N & 1 ) ) { median . push ( arr1 [ Math . floor ( N / 2 ) ] * 1 ) ; } else { median . push ( Math . floor ( ( arr1 [ Math . floor ( N / 2 ) ] + arr1 [ Math . floor ( ( N - 1 ) / 2 ) ] ) / 2 ) ) ; } } for ( let i = 0 ; i < median . length - 1 ; i ++ ) { document . write ( ( median [ i + 1 ] - median [ i ] ) + " " ) ; } } let arr1 = [ 2 , 4 , 6 , 8 , 10 ] ; let arr2 = [ 4 , 6 ] ; medianChange ( arr1 , arr2 )

Index/key variables: i, x
Accumulator variables: N, i, x
Iterator variables: i, x
Javascript program:
let nfa = 1 ; let flag = 0 ; function state1 ( c ) { if ( c == ' ' ) nfa = 2 ; else if ( c == ' ' c == ' ' ) nfa = 1 ; else flag = 1 ; } function state2 ( c ) { if ( c == ' ' ) nfa = 3 ; else if ( c == ' ' c == ' ' ) nfa = 2 ; else flag = 1 ; } function state3 ( c ) { if ( c == ' ' ) nfa = 1 ; else if ( c == ' ' c == ' ' ) nfa = 3 ; else flag = 1 ; } function state4 ( c ) { if ( c == ' ' ) nfa = 5 ; else if ( c == ' ' c == ' ' ) nfa = 4 ; else flag = 1 ; } function state5 ( c ) { if ( c == ' ' ) nfa = 6 ; else if ( c == ' ' c == ' ' ) nfa = 5 ; else flag = 1 ; } function state6 ( c ) { if ( c == ' ' ) nfa = 4 ; else if ( c == ' ' c == ' ' ) nfa = 6 ; else flag = 1 ; } function state7 ( c ) { if ( c == ' ' ) nfa = 8 ; else if ( c == ' ' c == ' ' ) nfa = 7 ; else flag = 1 ; } function state8 ( c ) { if ( c == ' ' ) nfa = 9 ; else if ( c == ' ' c == ' ' ) nfa = 8 ; else flag = 1 ; } function state9 ( c ) { if ( c == ' ' ) nfa = 7 ; else if ( c == ' ' c == ' ' ) nfa = 9 ; else flag = 1 ; } function checkA ( s , x ) { for ( let i = 0 ; i < x ; i ++ ) { if ( nfa == 1 ) state1 ( s [ i ] ) ; else if ( nfa == 2 ) state2 ( s [ i ] ) ; else if ( nfa == 3 ) state3 ( s [ i ] ) ; } if ( nfa == 1 ) { return true ; } else { nfa = 4 ; } } function checkB ( s , x ) { for ( let i = 0 ; i < x ; i ++ ) { if ( nfa == 4 ) state4 ( s [ i ] ) ; else if ( nfa == 5 ) state5 ( s [ i ] ) ; else if ( nfa == 6 ) state6 ( s [ i ] ) ; } if ( nfa == 4 ) { return true ; } else { nfa = 7 ; } } function checkC ( s , x ) { for ( let i = 0 ; i < x ; i ++ ) { if ( nfa == 7 ) state7 ( s [ i ] ) ; else if ( nfa == 8 ) state8 ( s [ i ] ) ; else if ( nfa == 9 ) state9 ( s [ i ] ) ; } if ( nfa == 7 ) { return true ; } } let s = " " ; let x = 5 ; if ( checkA ( s , x ) || checkB ( s , x ) || checkC ( s , x ) ) { document . write ( " " ) ; } else { if ( flag == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getPositionCount ( a , n ) { var count = 1 ; var min = a [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= min ) { min = a [ i ] ; count ++ ; } } return count ; } var a = [ 5 , 4 , 6 , 1 , 3 , 1 ] ; var n = a . length ; document . write ( getPositionCount ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function maxSum ( arr , n , k ) { if ( n < k ) { return - 1 ; } var res = 0 ; for ( i = 0 ; i < k ; i ++ ) res += arr [ i ] ; var curr_sum = res ; for ( i = k ; i < n ; i ++ ) { curr_sum += arr [ i ] - arr [ i - k ] ; res = Math . max ( res , curr_sum ) ; } return res ; } function solve ( arr , n , k ) { var max_len = 0 , l = 0 , r = n , m ; while ( l <= r ) { m = parseInt ( ( l + r ) / 2 ) ; if ( maxSum ( arr , n , m ) > k ) r = m - 1 ; else { l = m + 1 ; max_len = m ; } } return max_len ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; var k = 10 ; document . write ( solve ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: curr_sum, i, res
Iterator variables: i
Javascript program:
var MAX = 100001 var ROW = 10 var COl = 3 var indices = Array . from ( Array ( MAX ) , ( ) => new Array ( ) ) ; var test = [ [ 2 , 3 , 6 ] , [ 2 , 4 , 4 ] , [ 2 , 6 , 3 ] , [ 3 , 2 , 6 ] , [ 3 , 3 , 3 ] , [ 3 , 6 , 2 ] , [ 4 , 2 , 4 ] , [ 4 , 4 , 2 ] , [ 6 , 2 , 3 ] , [ 6 , 3 , 2 ] ] ; function find_triplet ( array , n ) { var answer = 0 ; for ( var i = 0 ; i < n ; i ++ ) { indices [ array [ i ] ] . push ( i ) ; } for ( var i = 0 ; i < n ; i ++ ) { var y = array [ i ] ; for ( var j = 0 ; j < ROW ; j ++ ) { var s = test [ j ] [ 1 ] * y ; if ( s % test [ j ] [ 0 ] != 0 ) continue ; if ( s % test [ j ] [ 2 ] != 0 ) continue ; var x = s / test [ j ] [ 0 ] ; var z = s / test [ j ] [ 2 ] ; if ( x > MAX z > MAX ) continue ; var l = 0 ; var r = indices [ x ] . length - 1 ; var first = - 1 ; while ( l <= r ) { var m = ( l + r ) / 2 ; if ( indices [ x ] [ m ] < i ) { first = m ; l = m + 1 ; } else { r = m - 1 ; } } l = 0 ; r = indices [ z ] . length - 1 ; var third = - 1 ; while ( l <= r ) { var m = ( l + r ) / 2 ; if ( indices [ z ] [ m ] > i ) { third = m ; r = m - 1 ; } else { l = m + 1 ; } } if ( first != - 1 && third != - 1 ) { answer += ( first + 1 ) * ( indices [ z ] . length - third ) ; } } } return answer ; } var array = [ 2 , 4 , 5 , 6 , 7 ] ; var n = array . length ; document . write ( find_triplet ( array , n ) ) ;

Index/key variables: i, j, m, x, z
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function distinct ( arr , n ) { let count = 0 ; if ( n == 1 ) return 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( i == 0 ) { if ( arr [ i ] != arr [ i + 1 ] ) count += 1 ; } else { if ( arr [ i ] != arr [ i + 1 ] arr [ i ] != arr [ i - 1 ] ) count += 1 ; } } if ( arr [ n - 1 ] != arr [ n - 2 ] ) count += 1 ; return count ; } let arr = [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ; let n = arr . length ; document . write ( distinct ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isSorted ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] [ 0 ] > arr [ i - 1 ] [ 0 ] ) { return false ; } } return true ; } function isPossibleToSort ( arr , N ) { let group = arr [ 0 ] [ 1 ] ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] [ 1 ] != group ) { return " " ; } } if ( isSorted ( arr , N ) ) { return " " ; } else { return " " ; } } let arr = [ [ 340000 , 2 ] , [ 15000 , 2 ] , [ 34000 , 2 ] , [ 10000 , 2 ] ] ; let N = arr . length ; document . write ( isPossibleToSort ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } var root = null ; function AlphaScore ( ) { root = null ; } var sum = 0 , total_sum = 0 ; var mod = 1000000007 ; function getAlphaScore ( node ) { if ( node . left != null ) getAlphaScore ( node . left ) ; sum = ( sum + node . data ) % mod ; total_sum = ( total_sum + sum ) % mod ; if ( node . right != null ) getAlphaScore ( node . right ) ; return total_sum ; } function constructBST ( arr , start , end , root ) { if ( start > end ) return null ; var mid = parseInt ( ( start + end ) / 2 ) ; if ( root == null ) root = new Node ( arr [ mid ] ) ; root . left = constructBST ( arr , start , mid - 1 , root . left ) ; root . right = constructBST ( arr , mid + 1 , end , root . right ) ; return root ; } var arr = [ 10 , 11 , 12 ] ; var length = arr . length ; arr . sort ( ) ; var root = null ; root = constructBST ( arr , 0 , length - 1 , root ) ; document . write ( getAlphaScore ( root ) ) ;

Index/key variables: mid
Class/struct names: Node
Javascript program:
function sortByFreq ( arr , n ) { var maxE = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { maxE = Math . max ( maxE , arr [ i ] ) ; } var freq = new Array ( maxE + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } var cnt = 0 ; for ( var i = 0 ; i <= maxE ; i ++ ) { if ( freq [ i ] > 0 ) { var value = 100000 - i ; arr [ cnt ] = 100000 * freq [ i ] + value ; cnt ++ ; } } return cnt ; } function printSortedArray ( arr , cnt ) { for ( var i = 0 ; i < cnt ; i ++ ) { var frequency = parseInt ( arr [ i ] / 100000 ) ; var value = 100000 - ( arr [ i ] % 100000 ) ; for ( var j = 0 ; j < frequency ; j ++ ) { document . write ( value + " " ) ; } } } var arr = [ 4 , 4 , 5 , 6 , 4 , 2 , 2 , 8 , 5 ] ; var n = arr . length ; var cnt = sortByFreq ( arr , n ) ; arr . sort ( ( a , b ) => b - a ) ; printSortedArray ( arr , cnt ) ;

Index/key variables: cnt, i
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function checkRectangles ( arr , n ) { let ans = true ; arr . sort ( ) ; var area = arr [ 0 ] * arr [ 4 * n - 1 ] ; for ( let i = 0 ; i < 2 * n ; i = i + 2 ) { if ( arr [ i ] != arr [ i + 1 ] arr [ 4 * n - i - 1 ] != arr [ 4 * n - i - 2 ] arr [ i ] * arr [ 4 * n - i - 1 ] != area ) { ans = false ; break ; } } if ( ans ) return true ; return false ; } var arr = [ 1 , 8 , 2 , 1 , 2 , 4 , 4 , 8 ] ; var n = 2 ; if ( checkRectangles ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Iterator variables: i
Boolean variables: ans
Javascript program:
function cntElements ( arr , n ) { let copy_arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) copy_arr [ i ] = arr [ i ] ; let count = 0 ; arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != copy_arr [ i ] ) { count ++ ; } } return count ; } let arr = [ 1 , 2 , 6 , 2 , 4 , 5 ] ; let n = arr . length ; document . write ( cntElements ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findPairs ( arr , n , k , d ) { if ( n < 2 * k ) { document . write ( - 1 ) ; return ; } let pairs = [ ] ; arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < k ; i ++ ) { if ( arr [ n - k + i ] - arr [ i ] >= d ) { let p = [ arr [ i ] , arr [ n - k + i ] ] ; pairs . push ( p ) ; } } if ( pairs . length < k ) { document . write ( - 1 ) ; return ; } for ( let v of pairs ) { document . write ( " " + v [ 0 ] + " " + v [ 1 ] + " " + " " ) ; } } let arr = [ 4 , 6 , 10 , 23 , 14 , 7 , 2 , 20 , 9 ] ; let n = arr . length ; let k = 4 , d = 3 ; findPairs ( arr , n , k , d ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, v
Javascript program:
function pairs_count ( arr , n , sum ) { let ans = 0 ; arr . sort ( ) ; let i = 0 , j = n - 1 ; while ( i < j ) { if ( arr [ i ] + arr [ j ] < sum ) i ++ ; else if ( arr [ i ] + arr [ j ] > sum ) j -- ; else { let x = arr [ i ] , xx = i ; while ( i < j && arr [ i ] == x ) i ++ ; let y = arr [ j ] , yy = j ; while ( j >= i && arr [ j ] == y ) j -- ; if ( x == y ) { let temp = i - xx + yy - j - 1 ; ans += ( temp * ( temp + 1 ) ) / 2 ; } else ans += ( i - xx ) * ( yy - j ) ; } } return ans ; } let arr = [ 1 , 5 , 7 , 5 , - 1 ] ; let n = arr . length ; let sum = 6 ; document . write ( pairs_count ( arr , n , sum ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Javascript program:
function check ( str ) { var min = Number . MAX_VALUE ; var max = Number . MIN_VALUE ; var sum = 0 ; for ( i = 0 ; i < str . length ; i ++ ) { var ascii = parseInt ( str . charCodeAt ( i ) ) ; if ( ascii < 96 ascii > 122 ) return false ; sum += ascii ; if ( min > ascii ) min = ascii ; if ( max < ascii ) max = ascii ; } min -= 1 ; var eSum = parseInt ( ( max * ( max + 1 ) ) / 2 ) - ( ( min * ( min + 1 ) ) / 2 ) ; return sum == eSum ; } var str = " " ; if ( check ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; var str1 = " " ; if ( check ( str1 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, min, sum
Iterator variables: i
Javascript program:
function findKth ( arr , n , k ) { var missing = new Set ( ) ; var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) missing . add ( arr [ i ] ) ; var maxm = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var minm = arr . reduce ( ( a , b ) => Math . min ( a , b ) ) ; for ( var i = minm + 1 ; i < maxm ; i ++ ) { if ( ! missing . has ( i ) ) count ++ ; if ( count == k ) return i ; } return - 1 ; } var arr = [ 2 , 10 , 9 , 4 ] ; var n = arr . length ; var k = 5 ; document . write ( findKth ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } var start = null ; function sortList ( head ) { var startVal = 1 ; while ( head != null ) { head . data = startVal ; startVal ++ ; head = head . next ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; start = head_ref ; } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } } start = null ; push ( start , 2 ) ; push ( start , 1 ) ; push ( start , 6 ) ; push ( start , 4 ) ; push ( start , 5 ) ; push ( start , 3 ) ; sortList ( start ) ; printList ( start ) ;

Accumulator variables: startVal
Class/struct names: Node
Javascript program:
function minSum ( arr , n ) { let evenArr = [ ] ; let oddArr = [ ] ; arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i < Math . floor ( n / 2 ) ) { oddArr . push ( arr [ i ] ) ; } else { evenArr . push ( arr [ i ] ) ; } } evenArr . sort ( function ( a , b ) { return b - a ; } ) ; let i = 0 , sum = 0 ; for ( let j = 0 ; j < evenArr . length ; j ++ ) { arr [ i ++ ] = evenArr [ j ] ; arr [ i ++ ] = oddArr [ j ] ; sum += evenArr [ j ] * oddArr [ j ] ; } return sum ; } let arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] ; let n = arr . length ; document . write ( " " + minSum ( arr , n ) + " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
funs minTime ( string word ) { int ans = 0 ; let curr = 0 ; for ( let i = 0 ; i < word . Length ; i ++ ) { int k = word [ i ] . charAt ( 0 ) - ' ' . charAt ( 0 ) ; let a = Math . abs ( curr - k ) ; let b = 26 - Math . abs ( curr - k ) ; ans += Math . min ( a , b ) ; ans ++ ; curr = word [ i ] . charAt ( 0 ) - ' ' . charAt ( 0 ) ; } document . write ( ans ) ; } let str = " " ; minTime ( str ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function reduceToOne ( N ) { let cnt = 0 ; while ( N != 1 ) { if ( N == 2 || ( N % 2 == 1 ) ) { N = N - 1 ; cnt ++ ; } else if ( N % 2 == 0 ) { N = Math . floor ( N / Math . floor ( N / 2 ) ) ; cnt ++ ; } } return cnt ; } let N = 35 ; document . write ( reduceToOne ( N ) ) ;

Accumulator variables: cnt
Javascript program:
function maxDiamonds ( A , N , K ) { let pq = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { pq . push ( A [ i ] ) ; } let ans = 0 ; pq . sort ( ( a , b ) => a - b ) while ( pq . length && K -- ) { pq . sort ( ( a , b ) => a - b ) let top = pq [ pq . length - 1 ] ; pq . pop ( ) ; ans += top ; top = Math . floor ( top / 2 ) ; pq . push ( top ) ; } document . write ( ans ) ; } let A = [ 2 , 1 , 7 , 4 , 2 ] ; let K = 3 ; let N = A . length ; maxDiamonds ( A , N , K ) ;

Index/key variables: i
Accumulator variables: K, ans, i
Iterator variables: i
Javascript program:
function MinimumCost ( A , B , N ) { var totalCost = 0 ; for ( i = 0 ; i < N ; i ++ ) { var mod_A = B [ i ] % A [ i ] ; var totalCost_A = Math . min ( mod_A , A [ i ] - mod_A ) ; var mod_B = A [ i ] % B [ i ] ; var totalCost_B = Math . min ( mod_B , B [ i ] - mod_B ) ; totalCost += Math . min ( totalCost_A , totalCost_B ) ; } return totalCost ; } var A = [ 3 , 6 , 3 ] ; var B = [ 4 , 8 , 13 ] ; var N = A . length ; document . write ( MinimumCost ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i, totalCost
Iterator variables: i
Javascript program:
function printLargestDivisible ( arr , N ) { var i , count0 = 0 , count7 = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) count0 ++ ; else count7 ++ ; } if ( count7 % 50 == 0 ) { while ( count7 -- ) document . write ( 7 ) ; while ( count0 -- ) document . write ( 0 ) ; } else if ( count7 < 5 ) { if ( count0 == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } else { count7 = count7 - count7 % 5 ; while ( count7 -- ) document . write ( 7 ) ; while ( count0 -- ) document . write ( 0 ) ; } } var arr = [ 0 , 7 , 0 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 ] ; var N = arr . length ; printLargestDivisible ( arr , N ) ;

Index/key variables: i
Accumulator variables: count0, count7, i
Iterator variables: i