dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function longestEvenOddSubarray ( a , n ) { let longest = 1 ; let cnt = 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] + a [ i + 1 ] ) % 2 == 1 ) { cnt ++ ; } else { longest = Math . max ( longest , cnt ) ; cnt = 1 ; } } if ( longest == 1 ) return 0 ; return Math . max ( cnt , longest ) ; } let a = [ 1 , 2 , 3 , 4 , 5 , 7 , 8 ] ; let n = a . length ; document . write ( longestEvenOddSubarray ( a , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function digSum ( a ) { let sum = 0 ; while ( a ) { sum += a % 10 ; a = Math . floor ( a / 10 ) ; } return sum ; } function isPrime ( r ) { let s = true ; for ( let i = 2 ; i * i <= r ; i ++ ) { if ( r % i == 0 ) { s = false ; break ; } } return s ; } function moranNo ( n ) { let dup = n ; let sum = digSum ( dup ) ; if ( n % sum == 0 ) { let c = n / sum ; if ( isPrime ( c ) ) { document . write ( " " ) ; return ; } } document . write ( " " + " " ) ; } let n = 21 ; moranNo ( n ) ;

Accumulator variables: i, sum
Iterator variables: i
Boolean variables: s
Javascript program:
function constructArray ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { document . write ( i + " " ) ; } } let N = 5 ; constructArray ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i += 6 ) { if ( n % i == 0 || n % ( i + 6 ) == 0 ) { return false ; } } return true ; } function SexyPrime ( n1 , n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && Math . abs ( n1 - n2 ) == 6 ) ; } function countSexyPairs ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( SexyPrime ( arr [ i ] , arr [ j ] ) ) { count ++ ; } } } return count ; } var arr = [ 6 , 7 , 5 , 11 , 13 ] var n = arr . length ; document . write ( countSexyPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function calculateMoves ( n ) { var count = 0 ; var layers = parseInt ( n / 2 ) ; for ( var k = 1 ; k < layers + 1 ; k ++ ) { count += 8 * k * k ; } return count ; } var N = 5 ; document . write ( calculateMoves ( N ) ) ;

Accumulator variables: count, k
Iterator variables: k
Javascript program:
function cntArray ( A , N ) { let result = 0 ; let frequency = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { frequency [ A [ i ] ] ++ ; } for ( let i = 1 ; i <= N ; i ++ ) { let frequency_of_i = frequency [ i ] ; result += ( ( frequency_of_i ) * ( frequency_of_i + 1 ) ) / 2 ; } document . write ( result ) ; } let A = [ 1 , 5 , 6 , 1 , 9 , 5 , 8 , 10 , 8 , 9 ] ; let N = A . length ; cntArray ( A , N ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function findMaxSize ( a , n ) { var frq = Array ( n + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; ++ i ) frq [ a [ i ] ] ++ ; var maxfrq = frq . reduce ( ( a , b ) => Math . max ( a , b ) ) var dist = n + 1 - frq . filter ( x => x == 0 ) . length ; var ans1 = Math . min ( maxfrq - 1 , dist ) ; var ans2 = Math . min ( maxfrq , dist - 1 ) ; var ans = Math . max ( ans1 , ans2 ) ; return ans ; } var arr = [ 4 , 2 , 4 , 1 , 4 , 3 , 4 ] ; var n = arr . length ; document . write ( findMaxSize ( arr , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function subarray ( arr , n ) { var ans = 1 , temp = 1 ; for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { ++ temp ; } else { ans = Math . max ( ans , temp ) ; temp = 1 ; } } ans = Math . max ( ans , temp ) ; return ans ; } var arr = [ 2 , 2 , 1 , 1 , 2 , 2 , 2 , 3 , 3 ] ; var n = arr . length ; document . write ( subarray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaxMinSubArray ( arr , k , n ) { let min = n ; let max = 0 ; let left ; let right ; let tmp ; for ( let i = 0 ; i < n ; i ++ ) { tmp = 1 ; left = i ; while ( left - 1 >= 0 && Math . abs ( arr [ left ] - arr [ left - 1 ] ) <= K ) { left -- ; tmp ++ ; } right = i ; while ( right + 1 <= n - 1 && Math . abs ( arr [ right ] - arr [ right + 1 ] ) <= K ) { right ++ ; tmp ++ ; } if ( min > tmp ) min = tmp ; if ( max < tmp ) max = tmp ; } document . write ( min ) ; document . write ( " " ) ; document . write ( max ) ; } let arr = [ 1 , 2 , 5 , 6 , 7 ] ; let K = 2 ; let n = arr . length ; findMaxMinSubArray ( arr , K , n ) ;

Index/key variables: left, right
Accumulator variables: i, left, right, tmp
Iterator variables: i
Javascript program:
function countElement ( arr , n ) { let freq = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } for ( let i = 0 ; i < n - 1 ; i ++ ) { let tmpsum = arr [ i ] ; for ( let j = i + 1 ; j < n ; j ++ ) { tmpsum += arr [ j ] ; if ( tmpsum <= n ) { ans += freq [ tmpsum ] ; freq [ tmpsum ] = 0 ; } } } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; let n = arr . length ; document . write ( countElement ( arr , n ) ) ;

Index/key variables: i, j, tmpsum
Accumulator variables: ans, i, j, tmpsum
Iterator variables: i, j
Javascript program:
function LongestMountain ( a ) { let i = 0 , j = - 1 , k = - 1 , p = 0 , d = 0 , n = 0 ; if ( a . length < 3 ) return 0 ; for ( i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i + 1 ] > a [ i ] ) { if ( k != - 1 ) { k = - 1 ; j = - 1 ; } if ( j == - 1 ) j = i ; } else { if ( a [ i + 1 ] < a [ i ] ) { if ( j != - 1 ) k = i + 1 ; if ( k != - 1 && j != - 1 ) { if ( d < k - j + 1 ) d = k - j + 1 ; } } else { k = - 1 ; j = - 1 ; } } } if ( k != - 1 && j != - 1 ) { if ( d < k - j + 1 ) d = k - j + 1 ; } return d ; } let a = [ 1 , 3 , 1 , 4 , 5 , 6 , 7 , 8 , 9 , 8 , 7 , 6 , 5 ] ; document . write ( LongestMountain ( a ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( A ) { let i , ctr = 0 ; for ( i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] % 2 ) { ctr ++ ; } } if ( ctr % 2 ) { return " " ; } else { return " " ; } } let arr = [ 9 , 17 ] ; document . write ( solve ( arr ) ) ;

Index/key variables: i
Accumulator variables: ctr, i
Iterator variables: i
Javascript program:
function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function countSquares ( n ) { let cnt = 0 ; for ( let i = Math . pow ( 10 , ( n - 1 ) ) ; i < Math . pow ( 10 , n ) ; i ++ ) { if ( i != 0 && isPerfectSquare ( i ) ) cnt ++ ; } return cnt ; } let n = 3 ; document . write ( countSquares ( n ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function findMinDivisor ( arr , n , limit ) { let low = 0 , high = 1000000000 ; while ( low < high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += Math . ceil ( arr [ i ] / mid ) ; } if ( sum <= limit ) high = mid ; else low = mid + 1 ; } return low ; } let arr = [ 2 , 3 , 4 , 9 ] ; let N = arr . length ; let K = 6 ; document . write ( findMinDivisor ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function getCount ( arr , n ) { var count = 0 ; for ( var j = 1 ; j < n - 1 ; j ++ ) { var p = 0 , q = 0 ; for ( var i = 0 ; i < j ; i ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) p ++ ; } for ( var k = j + 1 ; k < n ; k ++ ) { if ( arr [ k ] % arr [ j ] == 0 ) q ++ ; } count += p * q ; } return count ; } var arr = [ 1 , 2 , 2 ] ; var N = arr . length ; document . write ( getCount ( arr , N ) ) ;

Index/key variables: i, j, k
Accumulator variables: count, i, j, k, p, q
Iterator variables: i, j, k
Javascript program:
function computeMaxValue ( arr , n ) { var ans = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { var val = Math . max ( arr [ i ] / arr [ j ] , arr [ j ] / arr [ i ] ) ; ans = Math . max ( ans , val ) ; } } return ans ; } var arr = [ 15 , 10 , 3 , 2 ] ; var n = arr . length ; document . write ( computeMaxValue ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let sz = 1e3 ; function isEvenParity ( x ) { let parity = 0 ; while ( x != 0 ) { if ( x % 2 == 1 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return true ; else return false ; } function prletArray ( arr , len ) { for ( let i = 0 ; i < len ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function findPairEvenParity ( arr , len ) { let firstMaximum = Number . MIN_VALUE ; let secondMaximum = Number . MIN_VALUE ; for ( let i = 0 ; i < len ; i ++ ) { if ( isEvenParity ( arr [ i ] ) ) { if ( arr [ i ] >= firstMaximum ) { secondMaximum = firstMaximum ; firstMaximum = arr [ i ] ; } else if ( arr [ i ] >= secondMaximum ) { secondMaximum = arr [ i ] ; } } } document . write ( firstMaximum + " " + secondMaximum ) ; } let arr = [ 18 , 15 , 8 , 9 , 14 ] ; let len = arr . length ; findPairEvenParity ( arr , len ) ; ;

Index/key variables: i
Accumulator variables: i, parity
Iterator variables: i
Javascript program:
function Solve ( arr , n ) { let temp = 0 , count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { temp = 0 ; for ( let j = i ; j < n ; j ++ ) { temp += arr [ j ] ; if ( ( temp + 2 ) % 4 != 0 ) count ++ ; } } return count ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; let N = arr . length ; document . write ( Solve ( arr , N ) ) ;

Index/key variables: j
Accumulator variables: count, i, j, temp
Iterator variables: i, j
Javascript program:
let m = 4 ; function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } function nCr ( n , p , f ) { for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= m ; j ++ ) { if ( j > i ) f [ i ] [ j ] = 0 ; else if ( j == 0 j == i ) f [ i ] [ j ] = 1 ; else f [ i ] [ j ] = ( f [ i - 1 ] [ j ] + f [ i - 1 ] [ j - 1 ] ) % p ; } } } function operations ( arr , n , f ) { let p = 1000000007 ; nCr ( n , p - 1 , f ) ; arr . sort ( ) ; let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) { let x = 0 ; for ( let j = 1 ; j <= m ; j ++ ) { if ( m % j == 0 ) x = ( x + ( f [ n - i - 1 ] [ m - j ] * f [ i ] [ j - 1 ] ) % ( p - 1 ) ) % ( p - 1 ) ; } ans = ( ( ans * power ( arr [ i ] , x , p ) ) % p ) ; } document . write ( ans + " " ) ; } let arr = [ 4 , 5 , 7 , 9 , 3 ] ; let n = arr . length ; let f = new Array ( n + 1 ) ; for ( var i = 0 ; i < f . length ; i ++ ) { f [ i ] = new Array ( 2 ) ; } operations ( arr , n , f ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function prodSquare ( n ) { for ( i = 2 ; i * i <= n ; i ++ ) for ( j = 2 ; j <= n ; j ++ ) if ( i * i * j * j == n ) return true ; return false ; } var n = 25 ; if ( prodSquare ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function prodSquare ( n ) { var s = new Map ( ) ; for ( var i = 2 ; i * i <= n ; ++ i ) { s . set ( i * i , 1 ) ; if ( s . has ( n / ( i * i ) ) ) return true ; } return false ; } var n = 25 ; if ( prodSquare ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Iterator variables: i
Javascript program:
function printArr ( n ) { if ( n % 4 == 0 ) { for ( var i = 1 ; i <= n / 2 ; i ++ ) document . write ( i * 2 + ' ' ) ; for ( var i = 1 ; i < n / 2 ; i ++ ) document . write ( i * 2 - 1 + ' ' ) ; document . write ( n + n / 2 - 1 + ' ' ) ; } else document . write ( " " ) ; } var n = 22 ; printArr ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function GetSum ( n ) { var divisors = [ ] ; for ( var i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { divisors . push ( i ) ; if ( i != n / i ) { divisors . push ( n / i ) ; } } } var ans = 1 ; for ( var i = 0 ; i < divisors . length ; i ++ ) { ans *= ( divisors [ i ] + 1 ) ; } ans = ans - 1 ; return ans ; } var N = 4 ; document . write ( GetSum ( N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function isPowerful ( n ) { while ( n % 2 == 0 ) { let power = 0 ; while ( n % 2 == 0 ) { n /= 2 ; power ++ ; } if ( power == 1 ) return false ; } for ( let factor = 3 ; factor <= Math . sqrt ( n ) ; factor += 2 ) { let power = 0 ; while ( n % factor == 0 ) { n = n / factor ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } function longestPowerfulSubsequence ( arr , n ) { let answer = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerful ( arr [ i ] ) ) answer ++ ; } return answer ; } let arr = [ 6 , 4 , 10 , 13 , 9 , 25 ] ; let n = arr . length ; document . write ( longestPowerfulSubsequence ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: answer, factor, i, n, power
Iterator variables: factor, i
Javascript program:
function maxOR ( arr , n ) { var max_value = Math . max . apply ( Math , arr ) ; var number_of_bits = parseInt ( ( ( Math . log ( max_value ) ) ) ) + 2 ; var complement = ( ( 1 << number_of_bits ) - 1 ) ^ max_value ; var c = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != max_value ) { c = Math . max ( c , ( complement & arr [ i ] ) ) ; } } return ( max_value + c ) ; } var arr = [ 3 , 6 , 8 , 16 ] ; var n = arr . length ; document . write ( maxOR ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function update ( res , L , R , K ) { L -= 1 ; R -= 1 ; res [ L ] ^= K ; res [ R + 1 ] ^= K ; } function display ( arr , res , n ) { let i ; for ( i = 1 ; i < n ; i ++ ) { res [ i ] = res [ i ] ^ res [ i - 1 ] ; } for ( i = 0 ; i < n ; i ++ ) { document . write ( ( arr [ i ] ^ res [ i ] ) + " " ) ; } document . write ( " " ) ; } let arr = [ 2 , 4 , 6 , 8 , 10 ] ; let N = arr . length ; let res = Array . from ( { length : N } , ( _ , i ) => 0 ) ; let L = 1 , R = 3 , K = 2 ; update ( res , L , R , K ) ; L = 2 ; R = 4 ; K = 3 ; update ( res , L , R , K ) ; display ( arr , res , N ) ;

Index/key variables: L, i
Accumulator variables: L, R, i
Iterator variables: i
Javascript program:
function check ( a , n , k ) { let m = new Map ( ) ; let extra = 0 ; for ( let i = k ; i < n ; i ++ ) m . set ( a [ i ] , m . get ( a [ i ] ) == null ? 1 : m . get ( a [ i ] ) + 1 ) ; for ( let x of m . values ( ) ) extra += x - 1 ; if ( extra == 0 ) return true ; for ( let i = 1 ; i + k - 1 < n ; i ++ ) { if ( m . get ( a [ i + k - 1 ] ) > 1 ) extra -- ; m . set ( a [ i + k - 1 ] , m . get ( a [ i + k - 1 ] ) - 1 ) ; m . set ( a [ i - 1 ] , m . get ( a [ i - 1 ] ) + 1 ) ; if ( m . get ( a [ i - 1 ] ) > 1 ) extra ++ ; if ( extra == 0 ) return true ; } return false ; } function minlength ( a , n ) { let lo = 0 , hi = n + 1 ; let ans = 0 ; while ( lo < hi ) { let mid = Math . floor ( ( lo + hi ) / 2 ) ; if ( check ( a , n , mid ) ) { ans = mid ; hi = mid ; } else lo = mid + 1 ; } return ans ; } let a = [ 1 , 2 , 1 , 2 , 3 ] ; let n = a . length ; document . write ( minlength ( a , n ) ) ;

Index/key variables: i
Accumulator variables: extra, i
Iterator variables: i, x
Javascript program:
function findNumbers ( N ) { for ( var i = 1 ; i <= N / 2 ; i ++ ) { document . write ( i + " " + - i + " " ) ; } if ( N % 2 == 1 ) document . write ( 0 ) ; } var N = 10 ; findNumbers ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countPrimeFactors ( n ) { if ( n == 1 ) return 0 ; let cnt = 0 ; while ( n % 2 == 0 ) { cnt ++ ; n = parseInt ( n / 2 ) ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { cnt ++ ; n = parseInt ( n / i ) ; } } if ( n > 2 ) cnt ++ ; return cnt ; } let x = 8 ; let prime_factor_cnt = countPrimeFactors ( x ) ; document . write ( prime_factor_cnt ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function countSubArrayWithOddProduct ( A , N ) { var count = 0 ; var last = - 1 ; var K = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) { K = ( i - last - 1 ) ; count += ( K * ( K + 1 ) / 2 ) ; last = i ; } } K = ( N - last - 1 ) ; count += ( K * ( K + 1 ) / 2 ) ; return count ; } var arr = [ 12 , 15 , 7 , 3 , 25 , 6 , 2 , 1 , 1 , 7 ] ; var n = arr . length ; document . write ( countSubArrayWithOddProduct ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function CgpaCalc ( marks , n ) { let grade = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let cgpa , sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { grade [ i ] = ( marks [ i ] / 10 ) ; } for ( let i = 0 ; i < n ; i ++ ) { sum += grade [ i ] ; } cgpa = sum / n ; return cgpa ; } let n = 5 ; let marks = [ 90 , 80 , 70 , 80 , 90 ] ; let cgpa = CgpaCalc ( marks , n ) ; document . write ( " " + cgpa + " " ) ; document . write ( " " + ( cgpa * 9.5 ) . toFixed ( 2 ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findMinXORSubarray ( arr , n , k ) { if ( n < k ) return ; let res_index = 0 ; let curr_xor = 0 ; for ( let i = 0 ; i < k ; i ++ ) curr_xor ^= arr [ i ] ; let min_xor = curr_xor ; for ( let i = k ; i < n ; i ++ ) { curr_xor ^= ( arr [ i ] ^ arr [ i - k ] ) ; if ( curr_xor < min_xor ) { min_xor = curr_xor ; res_index = ( i - k + 1 ) ; } } document . write ( min_xor + " " ) ; } let arr = [ 3 , 7 , 90 , 20 , 10 , 50 , 40 ] ; let n = arr . length ; findMinXORSubarray ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: curr_xor, i
Iterator variables: i
Javascript program:
function getNumber ( a , b ) { var X = a . toString ( ) ; var Y = b . toString ( ) ; var XY = X + Y ; var YX = Y + X ; return XY > YX ? XY : YX ; } function printMaxPair ( arr , n ) { var largest = - 100000000 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) { var number = parseInt ( getNumber ( arr [ i ] , arr [ j ] ) ) ; largest = Math . max ( largest , number ) ; } document . write ( largest ) ; } var a = [ 23 , 14 , 16 , 25 , 3 , 9 ] ; var n = a . length ; printMaxPair ( a , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function previousPerfectSquare ( N ) { let prevN = Math . floor ( Math . sqrt ( N ) ) ; if ( prevN * prevN == N ) prevN -= 1 ; return prevN * prevN ; } function previousPerfectCube ( N ) { let prevN = Math . floor ( Math . cbrt ( N ) ) ; if ( prevN * prevN * prevN == N ) prevN -= 1 ; return prevN * prevN * prevN ; } let n = 30 ; document . write ( previousPerfectSquare ( n ) + " " ) ; document . write ( previousPerfectCube ( n ) + " " ) ;

Accumulator variables: prevN
Javascript program:
function findCount ( arr , n ) { let res = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( ( arr [ i ] % 2 == 0 ) && ( arr [ j ] % 2 == 1 ) ) { res ++ ; } return res ; } let a = [ 5 , 4 , 1 , 2 , 3 ] ; let n = a . length ; document . write ( findCount ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function findCount ( arr , n ) { let count = 0 , ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) count ++ ; else ans = ans + count ; } return ans ; } let a = [ 5 , 4 , 1 , 2 , 3 ] ; let n = a . length ; document . write ( findCount ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function product ( arr ) { let occurrence = Math . pow ( 2 , arr . length - 1 ) ; let product = 1 ; for ( let i = 0 ; i < arr . length ; i ++ ) { product *= Math . pow ( arr [ i ] , occurrence ) ; } return product ; } let arr = [ 10 , 3 , 7 ] ; document . write ( product ( arr ) ) ;

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
Javascript program:
let MOD = 1000000007 ; function power ( a , b ) { if ( b == 0 ) return 1 ; let temp = power ( a , b / 2 ) ; temp = ( temp * temp ) % MOD ; if ( b % 2 != 0 ) { temp = ( temp * a ) % MOD ; } return temp ; } function palindromicSum ( N ) { let sum = 0 , res , ways ; if ( N == 1 ) { document . write ( " " + " " ) ; return ; } if ( N == 2 ) { document . write ( " " + " " ) ; return ; } ways = Math . floor ( N / 2 ) ; if ( N % 2 == 0 ) ways -- ; res = power ( 9 , ways - 1 ) ; for ( let i = 0 ; i < N ; i ++ ) { sum = sum * 10 + 45 * res ; sum %= MOD ; } document . write ( sum + " " ) ; } let N = 3 ; palindromicSum ( N ) ;

Accumulator variables: i, ways
Iterator variables: i
Javascript program:
function joinNumbers ( numA , numB ) { var revB = 0 ; while ( numB > 0 ) { revB = revB * 10 + ( numB % 10 ) ; numB = parseInt ( numB / 10 ) ; } while ( revB > 0 ) { numA = numA * 10 + ( revB % 10 ) ; revB = parseInt ( revB / 10 ) ; } return numA ; } function findMaxSum ( A , B , n ) { var maxArr = Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; ++ i ) { var X = joinNumbers ( A [ i ] , B [ i ] ) ; var Y = joinNumbers ( B [ i ] , A [ i ] ) ; var mx = Math . max ( X , Y ) ; maxArr [ i ] = mx ; } var maxAns = 0 ; for ( var i = 0 ; i < n ; i ++ ) { maxAns += maxArr [ i ] ; } return maxAns ; } var N = 5 ; var A = [ 11 , 23 , 38 , 43 , 59 ] ; var B = [ 36 , 24 , 17 , 40 , 56 ] ; document . write ( findMaxSum ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i, maxAns
Iterator variables: i
Javascript program:
function createSets ( n ) { if ( n <= 2 ) { document . write ( " " ) ; return ; } else { let x = ( n % 2 == 0 ) ? ( n / 2 ) : ( ( n + 1 ) / 2 ) ; document . write ( x + " " ) ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i == x ) continue ; document . write ( i + " " ) ; } } return ; } let N = 7 ; createSets ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function calcCount ( arr , n , k ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( k % arr [ i ] == 0 ) count ++ ; } return count ; } var arr = [ 1 , 2 , 4 , 5 , 6 ] ; var n = arr . length ; var k = 6 ; document . write ( calcCount ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isPerfect ( n ) { let sum = 1 ; let i ; for ( i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return true ; return false ; } function contiguousPerfectNumber ( arr , n ) { let current_length = 0 ; let max_length = 0 ; let i ; for ( i = 0 ; i < n ; i ++ ) { if ( isPerfect ( arr [ i ] ) ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } let arr = [ 1 , 7 , 36 , 4 , 6 , 28 , 4 ] ; let n = arr . length ; document . write ( contiguousPerfectNumber ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: current_length, i
Iterator variables: i
Javascript program:
function isPowerful ( n ) { while ( n % 2 == 0 ) { let power = 0 ; while ( n % 2 == 0 ) { n /= 2 ; power ++ ; } if ( power == 1 ) return false ; } for ( let factor = 3 ; factor <= Math . sqrt ( n ) ; factor += 2 ) { let power = 0 ; while ( n % factor == 0 ) { n = n / factor ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } function contiguousPowerfulNumber ( arr , n ) { let current_length = 0 ; let max_length = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerful ( arr [ i ] ) ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } let arr = [ 1 , 7 , 36 , 4 , 6 , 28 , 4 ] ; let n = arr . length ; document . write ( contiguousPowerfulNumber ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: current_length, factor, i, n, power
Iterator variables: factor, i