dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findMaxSumByAlternatingSign ( arr , N ) { let cntNeg = 0 ; let MaxAltSum = 0 ; let SmValue = 0 ; let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { cntNeg += 1 ; } sum += Math . abs ( arr [ i ] ) ; SmValue = Math . min ( SmValue , Math . abs ( arr [ i ] ) ) ; } MaxAltSum = sum ; if ( cntNeg % 2 == 1 ) { MaxAltSum -= 2 * SmValue ; } return MaxAltSum ; } let arr = [ 1 , 1 , - 2 , - 4 , 5 ] ; let N = arr . length ; document . write ( findMaxSumByAlternatingSign ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: MaxAltSum, cntNeg, i, sum
Iterator variables: i
Javascript program:
function constructNewArraySumZero ( arr , N ) { let newArr = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { newArr [ i ] = arr [ i + 1 ] ; } else { newArr [ i ] = - arr [ i - 1 ] ; } } for ( let i = 0 ; i < N ; i ++ ) { document . write ( newArr [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , - 5 , - 6 , 8 ] ; let N = arr . length ; constructNewArraySumZero ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function bitonicSequence ( num , lower , upper ) { if ( num > ( upper - lower ) * 2 + 1 ) { document . write ( - 1 ) ; return ; } var ans = [ ] ; for ( var i = 0 ; i < Math . min ( upper - lower + 1 , num - 1 ) ; i ++ ) ans . push ( upper - i ) ; for ( var i = 0 ; i < num - ans . length ; i ++ ) { ans . splice ( 0 , 0 , upper - i - 1 ) } document . write ( ' ' ) ; ans . forEach ( element => { document . write ( " " + element ) ; } ) ; document . write ( ' ' + ' ' ) ; } var N = 5 , L = 3 , R = 10 ; bitonicSequence ( N , L , R ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubStrings ( s , t ) { let answ = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { for ( let j = 0 ; j < t . length ; j ++ ) { if ( t [ j ] != s [ i ] ) { answ += 1 ; let k = 1 ; let z = - 1 ; let q = 1 ; while ( j + z >= 0 && 0 <= i + z && s [ i + z ] == t [ j + z ] ) { z -= 1 ; answ += 1 ; q += 1 ; } while ( s . length > i + k && j + k < t . length && s [ i + k ] == t [ j + k ] ) { k += 1 ; answ += q ; z = - 1 ; } } } } return answ ; } let S = " " ; let T = " " ; document . write ( countSubStrings ( S , T ) ) ;

Index/key variables: i, j
Accumulator variables: answ, i, j, k, q, z
Iterator variables: i, j
Javascript program:
function minimumCntOfFlipsRequired ( str ) { let n = str . length ; let zeros = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { zeros ++ ; } } if ( zeros == 0 zeros == n ) { return 0 ; } let minFlips = Number . MAX_VALUE ; let currOnes = 0 ; let flips ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { currOnes ++ ; } flips = currOnes + ( zeros - ( i + 1 - currOnes ) ) ; minFlips = Math . min ( minFlips , flips ) ; } return minFlips ; } let s1 = " " ; document . write ( minimumCntOfFlipsRequired ( s1 ) ) ;

Index/key variables: i
Accumulator variables: currOnes, i, zeros
Iterator variables: i
Javascript program:
function findLongestNonDecreasing ( A , N ) { let res = 0 ; let start = 0 ; let end = N - 1 ; let prev = - 1 ; while ( start <= end ) { if ( A [ start ] <= A [ end ] ) { if ( prev == - 1 ) { prev = A [ start ] ; res ++ ; start ++ ; } else { if ( A [ start ] >= prev ) { res ++ ; prev = A [ start ] ; start ++ ; } else if ( A [ end ] >= prev ) { res ++ ; prev = A [ end ] ; end -- ; } else { break ; } } } else { if ( prev == - 1 ) { prev = A [ end ] ; res ++ ; end -- ; } else { if ( A [ end ] >= prev ) { res ++ ; prev = A [ end ] ; end -- ; } else if ( A [ start ] >= prev ) { res ++ ; prev = A [ start ] ; start ++ ; } else { break ; } } } } return res ; } let A = [ 1 , 1 , 3 , 5 , 4 , 3 , 6 , 2 , 1 ] ; let N = A . length ; document . write ( findLongestNonDecreasing ( A , N ) ) ;

Index/key variables: end, start
Accumulator variables: end, res, start
Javascript program:
function findPairs ( N ) { for ( let i = 0 ; i <= N ; i ++ ) { document . write ( " " + i + " " + ( N - i ) + " " ) ; } } let N = 5 ; findPairs ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } function findPartition ( nums , N ) { var prefix = Array ( N ) , suffix = Array ( N ) , i , k ; prefix [ 0 ] = nums [ 0 ] ; for ( i = 1 ; i < N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] * nums [ i ] ; } suffix [ N - 1 ] = nums [ N - 1 ] ; for ( i = N - 2 ; i >= 0 ; i -- ) { suffix [ i ] = suffix [ i + 1 ] * nums [ i ] ; } for ( k = 0 ; k < N - 1 ; k ++ ) { if ( GCD ( prefix [ k ] , suffix [ k + 1 ] ) == 1 ) { return k ; } } return - 1 ; } var arr = [ 2 , 3 , 4 , 5 ] ; var N = arr . length ; document . write ( findPartition ( arr , N ) ) ;

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function separate ( arr , n , parity ) { let count = 1 , res = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( ( ( arr [ i ] + parity ) & 1 ) != 0 && ( ( arr [ i - 1 ] + parity ) & 1 ) != 0 ) count ++ ; else { if ( count > 1 ) res += count - 1 ; count = 1 ; } } return res ; } function prletArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function requiredOps ( arr , N ) { let res1 = separate ( arr , N , 0 ) ; let res2 = separate ( arr , N , 1 ) ; document . write ( Math . max ( res1 , res2 ) ) ; } let arr = [ 13 , 2 , 6 , 8 , 3 , 5 , 7 , 10 , 14 , 15 ] ; let N = arr . length ; requiredOps ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i, res
Iterator variables: i
Javascript program:
function SieveOfEratosthenes ( N ) { let isPrime = [ ] ; for ( let i = 0 ; i < N + 1 ; i ++ ) { isPrime [ i ] = true ; } isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( let p = 2 ; p * p <= N ; p ++ ) { if ( isPrime [ p ] ) { for ( let i = p * p ; i <= N ; i += p ) { isPrime [ i ] = false ; } } } return isPrime ; } function cntPairsdiffOfPrimeisPrime ( N ) { let cntPairs = 0 ; let isPrime = SieveOfEratosthenes ( N ) ; for ( let i = 2 ; i <= N ; i ++ ) { if ( isPrime [ i ] && isPrime [ i - 2 ] ) { cntPairs += 2 ; } } return cntPairs ; } let N = 5 ; document . write ( cntPairsdiffOfPrimeisPrime ( N ) ) ;

Index/key variables: i, p
Accumulator variables: cntPairs, i, p
Iterator variables: i, p
Javascript program:
function longestSubsequence ( arr , N ) { let count = 1 ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != arr [ i - 1 ] ) { count ++ ; } } document . write ( count ) ; } let arr = [ 7 , 8 , 1 , 2 , 2 , 5 , 5 , 1 ] ; let N = arr . length ; longestSubsequence ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function substringCount ( s ) { var freq = new Array ( 26 ) . fill ( 0 ) ; var max_char = " " ; var maxfreq = - 21474836487 ; for ( var i = 0 ; i < s . length ; i ++ ) { freq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; if ( maxfreq < freq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ) maxfreq = freq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ; } for ( var i = 0 ; i < 26 ; i ++ ) { if ( maxfreq === freq [ i ] ) { max_char = String . fromCharCode ( i + " " . charCodeAt ( 0 ) ) ; break ; } } var ans = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { var ch = s [ i ] ; if ( max_char === ch ) { ans += s . length - i ; } } return ans ; } var S = " " ; document . write ( substringCount ( S ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function minSum ( arr , n ) { let ans = new Array ( n ) . fill ( 1 ) ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { ans [ i ] = Math . max ( ans [ i ] , ans [ i - 1 ] + 1 ) ; } } for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) { ans [ i ] = Math . max ( ans [ i ] , ans [ i + 1 ] + 1 ) ; } } let s = 0 ; for ( let x in ans ) { s = s + ans [ x ] ; } document . write ( s + " " ) ; } let arr = [ 1 , 2 , 2 ] ; let N = arr . length ; minSum ( arr , N ) ;

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i, x
Javascript program:
function minSteps ( S ) { let new_str = " " ; let N = S . length ; let i = 0 ; while ( i < N ) { new_str += S [ i ] ; let j = i ; while ( i < N && S [ i ] == S [ j ] ) ++ i ; } document . write ( Math . ceil ( ( new_str . length + 1 ) / 2.0 ) ) ; } let S = " " ; minSteps ( S )

Index/key variables: i, j
Accumulator variables: new_str
Javascript program:
function countPairs ( arr , N ) { var cntPairs = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) ; } mp . forEach ( ( value , key ) => { cntPairs += parseInt ( ( value * ( value - 1 ) ) / 2 ) ; } ) ; return cntPairs ; } var arr = [ 1 , 2 , 3 , 1 , 2 , 2 ] ; var N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: cntPairs, i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function palindromeMatrix ( N , M , arr ) { let ans = 0 ; for ( let i = 0 ; i < Math . floor ( ( N + 1 ) / 2 ) ; i ++ ) { for ( let j = 0 ; j < Math . floor ( ( M + 1 ) / 2 ) ; j ++ ) { let s = new Set ( ) ; s . add ( new pair ( i , j ) ) ; s . add ( new pair ( i , M - j - 1 ) ) ; s . add ( new pair ( N - i - 1 , j ) ) ; s . add ( new pair ( N - i - 1 , M - j - 1 ) ) ; let values = [ ] ; for ( let p of s . values ( ) ) { values . push ( arr [ p . first ] [ p . second ] ) ; } values . sort ( function ( a , b ) { return a - b ; } ) ; let max = Math . max ( ... values ) ; for ( let k = 1 ; k < values . length ; k ++ ) { ans += max - values [ k ] ; } } } document . write ( ans ) ; } let N = 3 , M = 3 ; let arr = [ [ 1 , 2 , 1 ] , [ 3 , 4 , 1 ] , [ 1 , 2 , 1 ] ] ; palindromeMatrix ( N , M , arr ) ;

Index/key variables: k
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k, p
Class/struct names: pair
Javascript program:
function minimumMoves ( n ) { let cnt2 = 0 , cnt5 = 0 ; while ( n % 2 == 0 ) { n /= 2 ; cnt2 ++ ; } while ( n % 5 == 0 ) { n /= 5 ; cnt5 ++ ; } if ( n == 1 && cnt2 <= cnt5 ) { return 2 * cnt5 - cnt2 ; } else return - 1 ; } let N = 25 ; document . write ( minimumMoves ( N ) ) ;

Accumulator variables: cnt2, cnt5, n
Javascript program:
function MinOperation ( arr , N , K ) { let cntOpe = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( K > arr [ i ] ) { if ( ( K - arr [ i ] ) % 2 == 0 ) { cntOpe += 2 ; } else { cntOpe += 1 ; } } else if ( K < arr [ i ] ) { if ( ( K - arr [ i ] ) % 2 == 0 ) { cntOpe += 1 ; } else { cntOpe += 2 ; } } } return cntOpe ; } let arr = [ 8 , 7 , 2 , 1 , 3 ] ; let K = 5 ; let N = arr . length ; document . write ( MinOperation ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: cntOpe, i
Iterator variables: i
Javascript program:
function rearrangeArray ( A , B , N ) { let m = new Map ( ) ; let xor_value = 0 ; for ( let i = 0 ; i < N ; i ++ ) { xor_value ^= A [ i ] ; xor_value ^= B [ i ] ; if ( m . has ( B [ i ] ) ) { m . set ( B [ i ] , m . get ( B [ i ] ) + 1 ) } else { m . set ( B [ i ] , 1 ) } } for ( let i = 0 ; i < N ; i ++ ) { B [ i ] = A [ i ] ^ xor_value ; if ( m . has ( B [ i ] ) ) { m . set ( B [ i ] , m . get ( B [ i ] ) - 1 ) } else return [ ] ; } return B ; } function rearrangeArrayUtil ( A , B , N ) { let ans = rearrangeArray ( A , B , N ) ; if ( ans . length > 0 ) { for ( let x of ans ) { document . write ( x + " " ) ; } } else { document . write ( " " ) ; } } let A = [ 13 , 21 , 33 , 49 , 53 ] ; let B = [ 54 , 50 , 34 , 22 , 14 ] ; let N = A . length ; rearrangeArrayUtil ( A , B , N ) ;

Index/key variables: i
Accumulator variables: i, xor_value
Iterator variables: i, x
Javascript program:
function binCoff ( n , r ) { let val = 1 ; let i ; if ( r > ( n - r ) ) r = ( n - r ) ; for ( i = 0 ; i < r ; i ++ ) { val *= ( n - i ) ; val /= ( i + 1 ) ; } return val ; } function findWays ( M ) { let n = M / 2 ; let a , b , ans ; a = binCoff ( 2 * n , n ) ; b = a / ( n + 1 ) ; document . write ( b ) ; } let M = 4 , X = 5 ; findWays ( M ) ;

Accumulator variables: i, val
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function countInverse ( arr , N , M ) { var XOR = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var gcdOfMandelement = gcd ( M , arr [ i ] ) ; if ( gcdOfMandelement == 1 ) { XOR ^= arr [ i ] ; } } document . write ( XOR ) ; } var arr = [ 1 , 2 , 3 ] ; var M = 4 ; var N = arr . length ; countInverse ( arr , N , M ) ;

Index/key variables: i
Accumulator variables: XOR, i
Iterator variables: i
Javascript program:
function Moves_Calculator ( x , y , row , col ) { let total_moves = 0 ; if ( ( row - x ) > 0 && ( col - y ) > 0 ) total_moves += Math . min ( ( row - x ) , ( col - y ) ) ; if ( ( y - 1 ) > 0 && ( x - 1 ) > 0 ) total_moves += Math . min ( ( y - 1 ) , ( x - 1 ) ) ; if ( ( x - 1 ) > 0 && ( col - y ) > 0 ) total_moves += Math . min ( ( x - 1 ) , ( col - y ) ) ; if ( ( row - x ) > 0 && ( y - 1 ) > 0 ) total_moves += Math . min ( ( row - x ) , ( y - 1 ) ) ; total_moves += ( row - 1 ) + ( col - 1 ) ; let king_moves = 0 ; if ( x + 1 <= row ) king_moves += 1 ; if ( x - 1 > 0 ) king_moves += 1 ; if ( y + 1 <= col ) king_moves += 1 ; if ( y - 1 > 0 ) king_moves += 1 ; if ( x + 1 <= row && y + 1 <= col ) king_moves += 1 ; if ( x + 1 <= row && y - 1 > 0 ) king_moves += 1 ; if ( x - 1 > 0 && y - 1 > 0 ) king_moves += 1 ; if ( x - 1 > 0 && y + 1 <= col ) king_moves += 1 ; return total_moves - king_moves ; } let n = 8 , m = 8 ; let x = 1 , y = 1 ; document . write ( Moves_Calculator ( x , y , m , n ) ) ;

Accumulator variables: king_moves, total_moves
Javascript program:
function equvInverse ( arr , N , P ) { let cntElem = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] * arr [ i ] ) % P == 1 ) { cntElem ++ ; } } return cntElem ; } let arr = [ 1 , 6 , 4 , 5 ] ; let N = arr . length ; let P = 7 ; document . write ( equvInverse ( arr , N , P ) ) ;

Index/key variables: i
Accumulator variables: cntElem, i
Iterator variables: i
Javascript program:
function power ( K , M ) { var res = 1 ; while ( M > 0 ) { if ( ( M & 1 ) == 1 ) { res = ( res * K ) ; } M = M >> 1 ; K = ( K * K ) ; } return res ; } function cntWays ( arr , N , K ) { var cntways = 0 ; var M = 0 ; var st = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { st . add ( arr [ i ] ) ; } M = st . size ; cntways = power ( K , M ) ; return cntways ; } var arr = [ 2 , 3 ] ; var N = arr . length ; var K = 2 ; document . write ( cntWays ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let mod = 1e9 + 7 ; function minProduct ( n ) { let ans = 1 ; for ( let i = 1 ; i <= Math . floor ( ( n - 4 ) / 2 ) ; i ++ ) { ans = ( 1 * ans * ( n - 2 ) ) % mod ; } ans = ( 1 * ans * ( n - 2 ) * ( n - 1 ) ) % mod ; document . write ( ans + " " ) ; } let N = 8 ; minProduct ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function TotalXorPair ( arr , N ) { let totalXOR = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { totalXOR ^= arr [ i ] ^ arr [ j ] ; } } return totalXOR ; } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; document . write ( TotalXorPair ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, totalXOR
Iterator variables: i, j
Javascript program:
function countPairs ( arr , n ) { let oneCount = 0 ; let desiredPair = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) { oneCount ++ ; } if ( arr [ i ] == 0 ) { desiredPair += oneCount ; } } return desiredPair ; } let arr = [ 3 , 1 , 1 , 0 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: desiredPair, i, oneCount
Iterator variables: i
Javascript program:
function smlstNonNeg ( arr , N ) { let smNonNeg = 0 ; let hash = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { hash [ i ] = false ; } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i ] < N ) { hash [ arr [ i ] ] = true ; } while ( hash [ smNonNeg ] ) { smNonNeg ++ ; } document . write ( smNonNeg + " " ) ; } } let arr = [ 0 , 1 , 2 , 3 , 5 ] ; let N = arr . length ; smlstNonNeg ( arr , N ) ;

Index/key variables: i, smNonNeg
Accumulator variables: i, smNonNeg
Iterator variables: i
Javascript program:
function solve ( arr , N , X ) { var A = [ ] , B = [ ] ; var c = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( ( 2 * arr [ i ] ) < X ) { A . push ( arr [ i ] ) ; } else if ( ( 2 * arr [ i ] ) > X ) { B . push ( arr [ i ] ) ; } else { if ( c % 2 == 0 ) { A . push ( arr [ i ] ) ; } else { B . push ( arr [ i ] ) ; } c ++ ; } } document . write ( " " ) ; for ( var i = 0 ; i < A . length ; i ++ ) { document . write ( A [ i ] + " " ) ; } document . write ( " " ) ; document . write ( " " ) ; for ( var i = 0 ; i < B . length ; i ++ ) { document . write ( B [ i ] + " " ) ; } } var arr = [ 1 , 5 , 4 , 3 , 6 , 2 , 4 , 3 ] ; var X = 7 ; var N = arr . length ; solve ( arr , N , X ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function cntMinSub ( arr , N , K ) { var res = 0 ; var start = 0 ; var end = N - 1 ; arr . sort ( ) ; while ( end - start > 1 ) { if ( arr [ start ] + arr [ end ] <= K ) { start ++ ; } else { res ++ ; end -- ; } } if ( end - start == 1 ) { if ( arr [ start ] + arr [ end ] <= K ) { res ++ ; start ++ ; end -- ; } else { res ++ ; end -- ; } } if ( start == end ) { res ++ ; } return res ; } var arr = [ 2 , 6 , 8 , 10 , 20 , 25 ] ; var N = arr . length ; var K = 26 ; document . write ( cntMinSub ( arr , N , K ) ) ;

Index/key variables: end, start
Accumulator variables: end, res, start
Javascript program:
function condition ( a , b ) { let d = Math . abs ( a - b ) , count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( d ) ; i ++ ) { if ( d % i == 0 ) { if ( d / i == i ) count += 1 ; else count += 2 ; } } return count ; } let x = 2 , y = 6 ; document . write ( condition ( x , y ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isComposite ( N ) { var i ; for ( i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { return true ; } } return false ; } function compositePair ( arr , N ) { var res = 0 ; var i , j ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var prod = arr [ i ] * arr [ j ] ; if ( isComposite ( prod ) ) { res ++ ; } } } return res ; } var arr = [ 1 , 1 , 2 , 2 , 8 ] ; var N = arr . length ; document . write ( compositePair ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function generateArray ( arr , n ) { var ans = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( i & 1 ) ans . splice ( 0 , 0 , arr [ i ] ) ; else ans . push ( arr [ i ] ) ; } if ( n & 1 ) { ans . reverse ( ) ; } ans . forEach ( x => { document . write ( x + " " ) ; } ) ; } var n = 4 ; var arr = [ 1 , 2 , 3 , 4 ] ; generateArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function closestgtNum ( str ) { var res = " " ; var n = str . length ; if ( str [ 0 ] < ' ' ) { res = res + String . fromCharCode ( str [ 0 ] . charCodeAt ( 0 ) + 1 ) ; } else { res = res + ' ' ; res = res + ' ' ; } for ( var i = 0 ; i < n - 1 ; i ++ ) { res = res + ' ' ; } return res ; } var str = " " ; document . write ( closestgtNum ( str ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumSubarrays ( arr , N , target ) { var ans = 0 ; var availIdx = - 1 ; var cur_sum = 0 ; var mp = new Map ( ) ; mp . set ( 0 , 1 ) ; for ( var i = 0 ; i < N ; i ++ ) { cur_sum += arr [ i ] ; if ( mp . has ( cur_sum - target ) && mp . get ( cur_sum - target ) >= availIdx ) { ans ++ ; availIdx = i ; } mp . set ( cur_sum , i ) ; } return ans ; } var arr = [ 2 , - 1 , 4 , 3 , 6 , 4 , 5 , 1 ] ; var N = arr . length ; var target = 6 ; document . write ( maximumSubarrays ( arr , N , target ) ) ;

Index/key variables: i
Accumulator variables: ans, cur_sum, i
Iterator variables: i
Javascript program:
function countOfPairs ( x , y ) { let counter = 1 ; while ( x > 0 y > 0 ) { let bit1 = x % 2 ; let bit2 = y % 2 ; x >>= 1 ; y >>= 1 ; if ( bit1 == 1 && bit2 == 0 ) { counter *= 2 ; continue ; } if ( ( bit1 & bit2 ) > 0 ) { counter = 0 ; break ; } } return counter ; } let X = 2 , Y = 5 ; document . write ( countOfPairs ( X , Y ) ) ;

Accumulator variables: counter
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function findGCD ( arr , N ) { let result = 0 ; for ( let element in arr ) { result = gcd ( result , element ) ; if ( result == 1 ) { return 1 ; } } return result ; } let arr = [ 2 , 3 , 4 ] ; let N = arr . length ; document . write ( findGCD ( arr , N ) ) ;

Iterator variables: element
Javascript program:
function factorsOf3 ( arr , N ) { let a = 0 , b = 0 , c = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 3 == 0 ) a ++ ; else if ( arr [ i ] % 3 == 1 ) b ++ ; else if ( arr [ i ] % 3 == 2 ) c ++ ; } if ( a >= 1 && a <= b + c + 1 ) document . write ( " " + " " ) ; else if ( a == 0 && b == 0 && c > 0 ) document . write ( " " + " " ) ; else if ( a == 0 && c == 0 && b > 0 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let arr = [ 1 , 2 , 3 , 3 ] ; let N = arr . length ; factorsOf3 ( arr , N ) ;

Index/key variables: i
Accumulator variables: a, b, c, i
Iterator variables: i
Javascript program:
function countSubstring ( s , n ) { var m = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( m . has ( s [ i ] ) ) m . set ( s [ i ] , m . get ( s [ i ] ) + 1 ) else m . set ( s [ i ] , 1 ) } var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var cnt = 0 ; if ( m . has ( s [ i ] ) ) m . set ( s [ i ] , m . get ( s [ i ] ) - 1 ) m . forEach ( ( value , key ) => { if ( key != s [ i ] ) { cnt += value ; } } ) ; ans += cnt ; } document . write ( ans ) ; } var S = " " ; var N = 5 ; countSubstring ( S , N ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function power ( x , n ) { let temp ; if ( n == 0 ) return 1 ; temp = power ( x , parseInt ( n / 2 ) ) ; if ( n % 2 == 0 ) return temp * temp ; else return x * temp * temp ; } function count_Total_Numbers ( n , x ) { let total , multiples = 0 ; for ( let i = 0 ; i < 10 ; i ++ ) { if ( i % x == 0 ) multiples ++ ; } if ( n == 1 ) return multiples ; total = ( multiples - 1 ) * power ( multiples , n - 1 ) ; return total ; } let N = 1 , X = 3 ; document . write ( count_Total_Numbers ( N , X ) ) ;

Accumulator variables: i, multiples
Iterator variables: i
Javascript program:
function number_of_strings ( N , M ) { var ans = 0 ; while ( N > 0 && M > 0 ) { if ( N > M ) { if ( N >= 2 ) { N -= 2 ; -- M ; ++ ans ; } else { break ; } } else { if ( M >= 2 ) { M -= 2 ; -- N ; ++ ans ; } else { break ; } } } document . write ( ans ) ; } var N = 4 , M = 19 ; number_of_strings ( N , M ) ;

Accumulator variables: M, N
Javascript program:
function minLength ( A , N ) { var elem = A [ 0 ] , count = 1 ; for ( var i = 1 ; i < N ; i ++ ) { if ( A [ i ] == elem ) { count ++ ; } else { break ; } } if ( count == N ) return N ; else return 1 ; } var arr = [ 2 , 1 , 3 , 1 ] ; var N = arr . length ; document . write ( minLength ( arr , N ) + " " ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function NegEqu ( N , X , Y ) { while ( X > 0 && ( N > N / 2 + 10 ) ) { N = N / 2 + 10 ; X -= 1 ; } while ( Y > 0 ) { N = N - 10 ; Y -= 1 ; } if ( N <= 0 ) return true ; return false ; } let N = 100 ; let X = 3 ; let Y = 4 ; if ( NegEqu ( N , X , Y ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: X, Y