dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Numberofways ( n ) { var count = 0 ; for ( var a = 1 ; a < n ; a ++ ) { for ( var b = 1 ; b < n ; b ++ ) { var c = n - ( a + b ) ; if ( a + b > c && a + c > b && b + c > a ) { count ++ ; } } } return count ; } var n = 15 ; document . write ( Numberofways ( n ) ) ;

Accumulator variables: a, b, count
Iterator variables: a, b
Javascript program:
function countPairs ( N , arr ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i == arr [ arr [ i ] - 1 ] - 1 ) { count ++ ; } } document . write ( count / 2 ) ; } let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ; let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function LongestFibSubseq ( A , n ) { var S = new Set ( A ) ; var maxLen = 0 , x , y ; for ( var i = 0 ; i < n ; ++ i ) { for ( var j = i + 1 ; j < n ; ++ j ) { x = A [ j ] ; y = A [ i ] + A [ j ] ; var length = 2 ; while ( S . has ( y ) ) { var z = x + y ; x = y ; y = z ; maxLen = Math . max ( maxLen , ++ length ) ; } } } return maxLen >= 3 ? maxLen : 0 ; } var A = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ; var n = A . length ; document . write ( LongestFibSubseq ( A , n ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
function CountMaximum ( arr , n , k ) { arr . sort ( ) ; let sum = 0 , count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum > k ) break ; count ++ ; } return count ; } let arr = [ 30 , 30 , 10 , 10 ] ; let n = 4 ; let k = 50 ; document . write ( CountMaximum ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function num_candyTypes ( candies ) { let s = new Set ( ) ; for ( let i = 0 ; i < candies . length ; i ++ ) { s . add ( candies [ i ] ) ; } return s . size ; } function distribute_candies ( candies ) { let allowed = candies . length / 2 ; let types = num_candyTypes ( candies ) ; if ( types < allowed ) document . write ( types ) ; else document . write ( allowed ) ; } let candies = [ 4 , 4 , 5 , 5 , 3 , 3 ] ; distribute_candies ( candies ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function __builtin_popcount ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function countEvenOdd ( arr , n , K ) { let even = 0 , odd = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let x = __builtin_popcount ( arr [ i ] ) ; if ( x % 2 == 0 ) even ++ ; else odd ++ ; } let y ; y = __builtin_popcount ( K ) ; if ( ( y & 1 ) != 0 ) { document . write ( " " + odd + " " + even ) ; } else { document . write ( " " + even + " " + odd ) ; } } let arr = [ 4 , 2 , 15 , 9 , 8 , 8 ] ; let K = 3 ; let n = arr . length ; countEvenOdd ( arr , n , K ) ;

Index/key variables: i
Accumulator variables: count, even, i, odd
Iterator variables: i
Javascript program:
function countTriplets ( A ) { var cnt = 0 ; var tuples = new Map ( ) ; A . forEach ( a => { A . forEach ( b => { if ( tuples . has ( a & b ) ) tuples . set ( a & b , tuples . get ( a & b ) + 1 ) else tuples . set ( a & b , 1 ) } ) ; } ) ; A . forEach ( a => { tuples . forEach ( ( value , key ) => { if ( ( key & a ) == 0 ) cnt += value ; } ) ; } ) ; return cnt ; } var A = [ 2 , 1 , 3 ] ; document . write ( countTriplets ( A ) ) ;

Accumulator variables: cnt
Javascript program:
function CountWays ( n ) { var noOfWays = Array ( n + 3 ) . fill ( 0 ) ; noOfWays [ 0 ] = 1 ; noOfWays [ 1 ] = 1 ; noOfWays [ 2 ] = 1 + 1 ; for ( var i = 3 ; i < n + 1 ; i ++ ) { noOfWays [ i ] = noOfWays [ i - 1 ] + noOfWays [ i - 3 ] ; } return noOfWays [ n ] ; } var n = 5 ; document . write ( CountWays ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function printSpiral ( size ) { let row = 0 , col = 0 ; let boundary = size - 1 ; let sizeLeft = size - 1 ; let flag = 1 ; let move = ' ' ; let matrix = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) { matrix [ i ] = new Array ( size ) . fill ( 0 ) ; } for ( let i = 1 ; i < size * size + 1 ; i ++ ) { matrix [ row ] [ col ] = i ; switch ( move ) { case ' ' : col += 1 ; break ; case ' ' : col -= 1 ; break ; case ' ' : row -= 1 ; break ; case ' ' : row += 1 ; break ; } if ( i == boundary ) { boundary += sizeLeft ; if ( flag != 2 ) { flag = 2 ; } else { flag = 1 ; sizeLeft -= 1 ; } switch ( move ) { case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; } } } for ( row = 0 ; row < size ; row ++ ) { for ( col = 0 ; col < size ; col ++ ) { let n = matrix [ row ] [ col ] ; if ( n < 10 ) document . write ( n + " " ) ; else document . write ( n + " " ) ; } document . write ( " " ) ; } } let size = 5 ; printSpiral ( size ) ;

Index/key variables: col, i, row
Accumulator variables: boundary, col, i, row, sizeLeft
Iterator variables: col, i, row
Javascript program:
function findWinner ( a , n ) { let v = [ ] ; let c = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == ' ' ) { c ++ ; } else { if ( c != 0 ) v . push ( c ) ; c = 0 ; } } if ( c != 0 ) v . push ( c ) ; if ( v . length == 0 ) { document . write ( " " ) ; return ; } if ( v . length == 1 ) { if ( ( v [ 0 ] & 1 ) != 0 ) document . write ( " " ) ; else document . write ( " " ) ; return ; } let first = Number . MIN_VALUE ; let second = Number . MIN_VALUE ; for ( let i = 0 ; i < v . length ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } if ( ( first & 1 ) != 0 && parseInt ( ( first + 1 ) / 2 , 10 ) > second ) document . write ( " " ) ; else document . write ( " " ) ; } let S = " " ; let N = S . length ; findWinner ( S , N ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function can_Construct ( S , K ) { var m = new Map ( ) ; var i = 0 , j = 0 , p = 0 ; if ( S . length == K ) { return true ; } for ( i = 0 ; i < S . length ; i ++ ) { if ( m . has ( S [ i ] ) ) m . set ( S [ i ] , m . get ( S [ i ] ) + 1 ) else m . set ( S [ i ] , 1 ) } if ( K > S . length ) { return false ; } else { m . forEach ( ( value , key ) => { if ( value % 2 != 0 ) { p = p + 1 ; } } ) ; } if ( K < p ) { return false ; } return true ; } var S = " " ; var K = 4 ; if ( can_Construct ( S , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function steps ( str , n ) { var flag ; var x = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( x == 0 ) flag = true ; if ( x == n - 1 ) flag = false ; for ( var j = 0 ; j < x ; j ++ ) document . write ( " " ) ; document . write ( str [ i ] + " " ) ; if ( flag == true ) x ++ ; else x -- ; } } var n = 4 ; var str = " " ; document . write ( " " + str + " " ) ; document . write ( " " + n + " " ) ; steps ( str , n ) ;

Index/key variables: i
Accumulator variables: i, j, x
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function countFreq ( arr , n ) { let visited = new Array ( n ) ; visited . fill ( false ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == true ) continue ; let count = 1 ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { visited [ j ] = true ; count ++ ; } } document . write ( arr [ i ] + " " + count + " " ) ; } } let arr = [ 10 , 20 , 20 , 10 , 10 , 20 , 5 , 20 ] ; let n = arr . length ; countFreq ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function isDivisible ( str , k ) { let n = str . length ; let c = 0 ; for ( let i = 0 ; i < k ; i ++ ) if ( str [ n - i - 1 ] == ' ' ) c ++ ; return ( c == k ) ; } let str1 = " " ; let k = 2 ; if ( isDivisible ( str1 , k ) == true ) document . write ( " " + " " ) ; else document . write ( " " ) ; let str2 = " " ; k = 2 ; if ( isDivisible ( str2 , k ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: c, i
Iterator variables: i
Javascript program:
let NO_OF_CHARS = 256 ; function canFormPalindrome ( str ) { let count = new Array ( NO_OF_CHARS ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] . charCodeAt ( ) ] ++ ; let odd = 0 ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( ( count [ i ] & 1 ) != 0 ) odd ++ ; if ( odd > 1 ) return false ; } return true ; } document . write ( canFormPalindrome ( " " ) ? " " + " " : " " + " " ) ; document . write ( canFormPalindrome ( " " ) ? " " : " " ) ;

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Javascript program:
function isNumber ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) if ( s [ i ] < ' ' s [ i ] > ' ' ) return false ; return true ; } let str = " " ; if ( isNumber ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function reverse ( str , len ) { if ( len == str . length ) { return ; } reverse ( str , len + 1 ) ; document . write ( str [ len ] ) ; } let a = " " ; reverse ( a , 0 ) ;

Index/key variables: len
Javascript program:
var box1 = 0 ; var box2 = 0 ; var fact = Array ( 11 ) ; function getProbability ( balls , M ) { factorial ( 10 ) ; box2 = M ; var K = 0 ; for ( var i = 0 ; i < M ; i ++ ) K += balls [ i ] ; if ( K % 2 == 1 ) return 0 ; var all = comb ( K , K / 2 ) ; var validPermutation = validPermutations ( K / 2 , balls , 0 , 0 , M ) ; return validPermutation / all ; } function validPermutations ( n , balls , usedBalls , i , M ) { if ( usedBalls == n ) { return box1 == box2 ? 1 : 0 ; } if ( i >= M ) return 0 ; var res = validPermutations ( n , balls , usedBalls , i + 1 , M ) ; box1 ++ ; for ( var j = 1 ; j <= balls [ i ] ; j ++ ) { if ( j == balls [ i ] ) box2 -- ; var combinations = comb ( balls [ i ] , j ) ; res += combinations * validPermutations ( n , balls , usedBalls + j , i + 1 , M ) ; } box1 -- ; box2 ++ ; return res ; } function factorial ( N ) { fact [ 0 ] = 1 ; for ( var i = 1 ; i <= N ; i ++ ) fact [ i ] = fact [ i - 1 ] * i ; } function comb ( n , r ) { var res = fact [ n ] / fact [ r ] ; res /= fact [ n - r ] ; return res ; } var arr = [ 2 , 1 , 1 ] ; var N = 4 ; var M = arr . length ; document . write ( getProbability ( arr , M ) ) ;

Index/key variables: i, n, r
Accumulator variables: K, box1, box2, i, j, res
Iterator variables: i, j
Javascript program:
function is_partition_possible ( n , x , y , w ) { let weight_at_x = new Map ( ) ; let max_x = - 2e3 , min_x = 2e3 ; for ( let i = 0 ; i < n ; i ++ ) { let new_x = x [ i ] - y [ i ] ; max_x = Math . max ( max_x , new_x ) ; min_x = Math . min ( min_x , new_x ) ; if ( weight_at_x . has ( new_x ) ) { weight_at_x . set ( new_x , weight_at_x . get ( new_x ) + w [ i ] ) ; } else { weight_at_x . set ( new_x , w [ i ] ) ; } } let sum_till = [ ] ; sum_till . push ( 0 ) ; for ( let s = min_x ; s <= max_x ; s ++ ) { if ( weight_at_x . get ( s ) == null ) sum_till . push ( sum_till [ sum_till . length - 1 ] ) ; else sum_till . push ( sum_till [ sum_till . length - 1 ] + weight_at_x . get ( s ) ) ; } let total_sum = sum_till [ sum_till . length - 1 ] ; let partition_possible = 0 ; for ( let i = 1 ; i < sum_till . length ; i ++ ) { if ( sum_till [ i ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; if ( sum_till [ i - 1 ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; } document . write ( partition_possible == 1 ? " " : " " ) ; } let n = 3 ; let x = [ - 1 , - 2 , 1 ] ; let y = [ 1 , 1 , - 1 ] ; let w = [ 3 , 1 , 4 ] ; is_partition_possible ( n , x , y , w ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i, s
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } function PrimeFactor ( N ) { let primef = new Map ( ) ; while ( N % 2 == 0 ) { if ( primef . has ( 2 ) ) { primef . set ( 2 , primef . get ( 2 ) + 1 ) ; } else { primef . set ( 2 , 1 ) ; } N = parseInt ( N / 2 , 10 ) ; } for ( let i = 3 ; i <= Math . sqrt ( N ) ; i ++ ) { while ( N % i == 0 ) { if ( primef . has ( i ) ) { primef . set ( i , primef . get ( i ) + 1 ) ; } else { primef . set ( i , 1 ) ; } N = parseInt ( N / 2 , 10 ) ; } } if ( N > 2 ) { primef [ N ] = 1 ; } return primef ; } function CountToMakeEqual ( X , Y ) { let gcdofXY = gcd ( X , Y ) ; let newX = parseInt ( Y / gcdofXY , 10 ) ; let newY = parseInt ( X / gcdofXY , 10 ) ; let primeX = PrimeFactor ( newX ) ; let primeY = PrimeFactor ( newY ) ; let ans = 0 ; primeX . forEach ( ( values , keys ) => { if ( X % keys != 0 ) { return - 1 ; } ans += primeX . get ( keys ) ; } ) ans += 1 ; primeY . forEach ( ( values , keys ) => { if ( Y % keys != 0 ) { return - 1 ; } ans += primeY . get ( keys ) ; } ) return ans ; } let X = 36 ; let Y = 48 ; let ans = CountToMakeEqual ( X , Y ) ; document . write ( ans ) ;

Index/key variables: N
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
class Node { constructor ( L , R , V ) { this . L = L ; this . R = R ; this . V = V ; } } function check ( Adj , Src , N , visited ) { let color = new Array ( N ) ; visited [ Src ] = true ; let q = [ ] ; q . push ( Src ) ; while ( q . length != 0 ) { let u = q . shift ( ) ; let Col = color [ u ] ; for ( let x = 0 ; x < Adj [ u ] . length ; x ++ ) { if ( visited [ Adj [ u ] [ x ] ] == true && color [ Adj [ u ] [ x ] ] == Col ) { return false ; } else if ( visited [ Adj [ u ] [ x ] ] == false ) { visited [ Adj [ u ] [ x ] ] = true ; q . push ( Adj [ u ] [ x ] ) ; color [ Adj [ u ] [ x ] ] = 1 - Col ; } } } return true ; } function addEdge ( Adj , u , v ) { Adj [ u ] . push ( v ) ; Adj [ v ] . push ( u ) ; } function isPossible ( Arr , N ) { let Adj = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) Adj [ i ] = [ ] ; for ( let i = 0 ; i < N - 1 ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( Arr [ i ] . R < Arr [ j ] . L Arr [ i ] . L > Arr [ j ] . R ) { continue ; } else { if ( Arr [ i ] . V == Arr [ j ] . V ) { addEdge ( Adj , i , j ) ; } } } } let visited = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) visited [ i ] = false ; for ( let i = 0 ; i < N ; i ++ ) { if ( visited [ i ] == false && Adj [ i ] . length > 0 ) { if ( check ( Adj , i , N , visited ) == false ) { document . write ( " " ) ; return ; } } } document . write ( " " ) ; } let arr = [ new Node ( 5 , 7 , 2 ) , new Node ( 4 , 6 , 1 ) , new Node ( 1 , 5 , 2 ) , new Node ( 6 , 5 , 1 ) ] ; let N = arr . length ; isPossible ( arr , N ) ;

Index/key variables: Src, i, j, u, v, x
Accumulator variables: i, j, x
Iterator variables: i, j, x
Class/struct names: Node
Javascript program:
function lexNumbers ( n ) { var sol = [ ] ; dfs ( 1 , n , sol ) ; document . write ( " " + sol [ 0 ] ) ; for ( var i = 1 ; i < sol . length ; i ++ ) document . write ( " " + sol [ i ] ) ; document . write ( " " ) ; } function dfs ( temp , n , sol ) { if ( temp > n ) return ; sol . push ( temp ) ; dfs ( temp * 10 , n , sol ) ; if ( temp % 10 != 9 ) dfs ( temp + 1 , n , sol ) ; } var n = 15 ; lexNumbers ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumSwaps ( arr ) { let count = 0 ; let i = 0 ; while ( i < arr . length ) { if ( arr [ i ] != i + 1 ) { while ( arr [ i ] != i + 1 ) { let temp = 0 ; temp = arr [ arr [ i ] - 1 ] ; arr [ arr [ i ] - 1 ] = arr [ i ] ; arr [ i ] = temp ; count ++ ; } } i ++ ; } return count ; } let arr = [ 2 , 3 , 4 , 1 , 5 ] ; document . write ( minimumSwaps ( arr ) ) ;

Index/key variables: i
Accumulator variables: count, i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; this . prev = null ; } } class Node { constructor ( ) { this . data = 0 ; this . next = null ; this . prev = null ; } } function append ( head_ref , new_data ) { new_node = new Node ( ) ; last = head_ref ; new_node . data = new_data ; new_node . next = null ; if ( head_ref == null ) { new_node . prev = null ; head_ref = new_node ; return head_ref ; } while ( last . next != null ) last = last . next ; last . next = new_node ; new_node . prev = last ; return head_ref ; } function printList ( node ) { last ; while ( node != null ) { document . write ( node . data + " " ) ; last = node ; node = node . next ; } } function mergeList ( p , q ) { s = null ; if ( p == null q == null ) { return ( p == null ? q : p ) ; } if ( p . data < q . data ) { p . prev = s ; s = p ; p = p . next ; } else { q . prev = s ; s = q ; q = q . next ; } head = s ; while ( p != null && q != null ) { if ( p . data < q . data ) { s . next = p ; p . prev = s ; s = s . next ; p = p . next ; } else { s . next = q ; q . prev = s ; s = s . next ; q = q . next ; } } if ( p == null ) { s . next = q ; q . prev = s ; } if ( q == null ) { s . next = p ; p . prev = s ; } return head ; } function mergeAllList ( head , k ) { finalList = null ; for ( i = 0 ; i < k ; i ++ ) { finalList = mergeList ( finalList , head [ i ] ) ; } return finalList ; } var k = 3 ; head = Array ( k ) . fill ( null ) ; for ( i = 0 ; i < k ; i ++ ) { head [ i ] = null ; } head [ 0 ] = append ( head [ 0 ] , 1 ) ; head [ 0 ] = append ( head [ 0 ] , 5 ) ; head [ 0 ] = append ( head [ 0 ] , 9 ) ; head [ 1 ] = append ( head [ 1 ] , 2 ) ; head [ 1 ] = append ( head [ 1 ] , 3 ) ; head [ 1 ] = append ( head [ 1 ] , 7 ) ; head [ 1 ] = append ( head [ 1 ] , 12 ) ; head [ 2 ] = append ( head [ 2 ] , 8 ) ; head [ 2 ] = append ( head [ 2 ] , 11 ) ; head [ 2 ] = append ( head [ 2 ] , 13 ) ; head [ 2 ] = append ( head [ 2 ] , 18 ) ; finalList = mergeAllList ( head , k ) ; printList ( finalList ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function insertionSortRecursive ( arr , n ) { if ( n <= 1 ) return ; insertionSortRecursive ( arr , n - 1 ) ; let last = arr [ n - 1 ] ; let j = n - 2 ; while ( j >= 0 && arr [ j ] > last ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = last ; } let arr = [ 12 , 11 , 13 , 5 , 6 ] ; insertionSortRecursive ( arr , arr . length ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function bubbleSort ( arr , n ) { if ( n == 1 ) return ; for ( var i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) { var temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } bubbleSort ( arr , n - 1 ) ; } var arr = [ 64 , 34 , 25 , 12 , 22 , 11 , 90 ] bubbleSort ( arr , arr . length ) ; document . write ( " " + " " ) ; for ( var i = 0 ; i < arr . length ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSumAfterPartition ( arr , n ) { let pos = [ ] ; let neg = [ ] ; let zero = 0 ; let pos_sum = 0 ; let neg_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { pos . push ( arr [ i ] ) ; pos_sum += arr [ i ] ; } else if ( arr [ i ] < 0 ) { neg . push ( arr [ i ] ) ; neg_sum += arr [ i ] ; } else { zero ++ ; } } let ans = 0 ; pos . sort ( function ( a , b ) { return a - b } ) neg . sort ( function ( a , b ) { return b - a } ) if ( pos . length > 0 && neg . length > 0 ) { ans = ( pos_sum - neg_sum ) ; } else if ( pos . length > 0 ) { if ( zero > 0 ) { ans = ( pos_sum ) ; } else { ans = ( pos_sum - 2 * pos [ 0 ] ) ; } } else { if ( zero > 0 ) { ans = ( - 1 * neg_sum ) ; } else { ans = ( neg [ 0 ] - ( neg_sum - neg [ 0 ] ) ) ; } } return ans ; } let arr = [ 1 , 2 , 3 , - 5 , - 7 ] ; let n = arr . length ; document . write ( maxSumAfterPartition ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, neg_sum, pos_sum, zero
Iterator variables: i
Javascript program:
function MaxXOR ( arr , N ) { var res = 0 ; for ( var i = 0 ; i < N ; i ++ ) { res |= arr [ i ] ; } return res ; } var arr = [ 1 , 5 , 7 ] ; var N = arr . length ; document . write ( MaxXOR ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function countEqual ( A , B , N ) { let first = 0 ; let second = N - 1 ; let count = 0 ; while ( first < N && second >= 0 ) { if ( A [ first ] < B [ second ] ) { first ++ ; } else if ( B [ second ] < A [ first ] ) { second -- ; } else { count ++ ; first ++ ; second -- ; } } return count ; } let A = [ 2 , 4 , 5 , 8 , 12 , 13 , 17 , 18 , 20 , 22 , 309 , 999 ] ; let B = [ 109 , 99 , 68 , 54 , 22 , 19 , 17 , 13 , 11 , 5 , 3 , 1 ] ; let N = A . length ; document . write ( countEqual ( A , B , N ) ) ;

Index/key variables: first, second
Accumulator variables: count, first, second
Javascript program:
let arr = [ ] ; for ( let m = 0 ; m < 100005 ; m ++ ) { arr [ m ] = 0 ; } function isPalindrome ( N ) { int temp = N ; let res = 0 ; while ( temp != 0 ) { let rem = temp % 10 ; res = res * 10 + rem ; temp = Math . floor ( temp / 10 ) ; } if ( res == N ) { return true ; } else { return false ; } } function sumOfDigits ( N ) { let sum = 0 ; while ( N != 0 ) { sum += N % 10 ; N = Math . floor ( N / 10 ) ; } return sum ; } function isPrime ( n ) { if ( n <= 1 ) { return false ; } for ( let i = 2 ; i <= Math . floor ( n / 2 ) ; ++ i ) { if ( n % i == 0 ) return false ; } return true ; } function precompute ( ) { for ( let i = 1 ; i <= 100000 ; i ++ ) { if ( isPalindrome ( i ) ) { let sum = sumOfDigits ( i ) ; if ( isPrime ( sum ) ) arr [ i ] = 1 ; else arr [ i ] = 0 ; } else arr [ i ] = 0 ; } for ( let i = 1 ; i <= 100000 ; i ++ ) { arr [ i ] = arr [ i ] + arr [ i - 1 ] ; } } function countNumbers ( Q , N ) { precompute ( ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( ( arr [ Q [ i ] [ 1 ] ] - arr [ Q [ i ] [ 0 ] - 1 ] ) + " " ) ; } } let Q = [ [ 5 , 9 ] , [ 1 , 101 ] ] ; let N = Q . length ; countNumbers ( Q , N ) ;

Index/key variables: i, m
Accumulator variables: i, m, sum
Iterator variables: i, m
Javascript program:
function sum ( n ) { var res = 0 ; while ( n > 0 ) { res += n % 10 ; n /= 10 ; } return res ; } function smallestNumber ( n , s ) { if ( sum ( n ) <= s ) { return n ; } var ans = n , k = 1 ; for ( i = 0 ; i < 9 ; ++ i ) { var digit = ( ans / k ) % 10 ; var add = k * ( ( 10 - digit ) % 10 ) ; ans += add ; if ( sum ( ans ) <= s ) { break ; } k *= 10 ; } return ans ; } var N = 3 , S = 2 ; document . write ( smallestNumber ( N , S ) ) ;

Accumulator variables: ans, k, n, res
Iterator variables: i
Javascript program:
function maxSubsequences ( arr , n ) { let map = new Map ( ) ; let maxCount = 0 ; let count ; for ( let i = 0 ; i < n ; i ++ ) { if ( map . has ( arr [ i ] ) ) { count = map [ arr [ i ] ] ; if ( count > 1 ) { map . add ( arr [ i ] , count - 1 ) ; } else map . delete ( arr [ i ] ) ; if ( arr [ i ] - 1 > 0 ) if ( map . has ( arr [ i ] - 1 ) ) map [ arr [ i ] - 1 ] ++ ; else map . set ( arr [ i ] - 1 , 1 ) ; } else { maxCount ++ ; if ( arr [ i ] - 1 > 0 ) if ( map . has ( arr [ i ] - 1 ) ) map [ arr [ i ] - 1 ] ++ ; else map . set ( arr [ i ] - 1 , 1 ) ; } } return maxCount ; } let n = 5 ; let arr = [ 4 , 5 , 2 , 1 , 4 ] ; document . write ( maxSubsequences ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, maxCount
Iterator variables: i
Javascript program:
Function to remove first and last occurrence of a given character from the given String * / function removeOcc ( s , ch ) { for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] === ch ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; break ; } } for ( var i = s . length - 1 ; i > - 1 ; i -- ) { if ( s [ i ] === ch ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; break ; } } return s ; } var s = " " ; var ch = " " ; document . write ( removeOcc ( s , ch ) ) ;

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