dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findWinner ( a , n ) { let win = 0 ; if ( n % 2 == 0 ) win = 1 ; else win = 0 ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( i % 2 == 1 ) { if ( win == 0 && a [ i ] > 1 ) win = 1 ; } else { if ( win == 1 && a [ i ] > 1 ) win = 0 ; } } if ( win == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 1 , 1 , 1 , 2 ] ; let N = arr . length ; findWinner ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let isprime = new Array ( 2000010 ) ; function SieveOfEratosthenes ( n ) { isprime . fill ( true ) ; isprime [ 1 ] = false ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( isprime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) isprime [ i ] = false ; } } } function KDistinctPrime ( arr , n , k ) { SieveOfEratosthenes ( 2000000 ) ; let cnt = new Map ( ) ; let result = - 1 ; for ( let i = 0 , j = - 1 ; i < n ; ++ i ) { let x = arr [ i ] ; if ( isprime [ x ] ) { if ( cnt . has ( x ) ) cnt . set ( x , cnt . get ( x ) + 1 ) else cnt . set ( x , 1 ) ; if ( cnt . get ( x ) == 1 ) { -- k ; } } while ( k < 0 ) { x = arr [ ++ j ] ; if ( isprime [ x ] ) { if ( cnt . has ( x ) ) cnt . set ( x , cnt . get ( x ) - 1 ) else cnt . set ( x , - 1 ) ; if ( cnt . get ( x ) == 0 ) { ++ k ; } } } if ( k == 0 ) result = Math . max ( result , i - j ) ; } return result ; } let arr = [ 1 , 2 , 3 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let K = 3 ; let N = arr . length ; document . write ( KDistinctPrime ( arr , N , K ) ) ;

Index/key variables: i, p, x
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
var MAX_SIZE = 1000005 ; function SieveOfEratosthenes ( StorePrimes ) { var IsPrime = Array ( MAX_SIZE ) . fill ( true ) ; var p , i ; for ( p = 2 ; p * p < MAX_SIZE ; p ++ ) { if ( IsPrime [ p ] == true ) { for ( i = p * p ; i < MAX_SIZE ; i += p ) IsPrime [ i ] = false ; } } for ( p = 2 ; p < MAX_SIZE ; p ++ ) if ( IsPrime [ p ] ) StorePrimes . push ( p ) ; } function Smallest_non_Prime ( StorePrimes , N ) { var x = StorePrimes [ N ] ; return x * x ; } N = 3 ; var StorePrimes = [ ] ; SieveOfEratosthenes ( StorePrimes ) ; document . write ( Smallest_non_Prime ( StorePrimes , N ) ) ;

Index/key variables: N, i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function printSubset ( n , k ) { var answer = [ ] ; while ( n > 0 ) { var p = parseInt ( Math . log2 ( n ) ) ; answer . push ( Math . pow ( k , p ) ) ; n %= parseInt ( Math . pow ( 2 , p ) ) ; } answer . sort ( ) ; for ( var i = 0 ; i < answer . length ; i ++ ) { document . write ( answer [ i ] + " " ) ; } } var n = 5 ; var k = 4 ; printSubset ( n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getLeftmostBit ( n ) { var m = 0 ; while ( n > 1 ) { n = n >> 1 ; m ++ ; } return m ; } function getNextLeftmostBit ( n , m ) { var temp = 1 << m ; while ( n < temp ) { temp = temp >> 1 ; m -- ; } return m ; } function countSetBit ( n ) { var m = getLeftmostBit ( n ) ; return _countSetBit ( n , m ) ; } function _countSetBit ( n , m ) { if ( n == 0 ) return 0 ; m = getNextLeftmostBit ( n , m ) ; if ( n == ( 1 << ( m + 1 ) ) - 1 ) return ( m + 1 ) * ( 1 << m ) ; n = n - ( 1 << m ) ; return ( ( n + 1 ) + countSetBit ( n ) + m * ( 1 << ( m - 1 ) ) ) ; } function countSetBits ( L , R ) { return Math . abs ( countSetBit ( R ) - countSetBit ( L - 1 ) ) ; } var L = 3 , R = 5 ; document . write ( " " + countSetBits ( L , R ) ) ;

Accumulator variables: m
Javascript program:
function printPermutation ( arr , n ) { let odd = [ ] ; let even = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even . push ( arr [ i ] ) ; else odd . push ( arr [ i ] ) ; } let size_odd = odd . length ; let size_even = even . length ; if ( size_odd > size_even + 1 ) document . write ( " " ) ; else { let i = 0 ; let j = 0 ; while ( i < size_odd && j < size_even ) { document . write ( odd [ i ] + " " ) ; ++ i ; document . write ( even [ j ] + " " ) ; ++ j ; } while ( i < size_odd ) { document . write ( odd [ i ] + " " ) ; ++ i ; } while ( j < size_even ) { document . write ( even [ j ] + " " ) ; } } } let arr = [ 6 , 7 , 9 , 8 , 10 , 11 ] ; let N = arr . length ; printPermutation ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
let rem = new Array ( 11 ) ; for ( var i = 0 ; i < rem . length ; i ++ ) { rem [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < rem . length ; i ++ ) { for ( var j = 0 ; j < rem . length ; j ++ ) { rem [ i ] [ j ] = 0 ; } } function countPairs ( a , n , k ) { let len = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let p = Array . from ( { length : 11 } , ( _ , i ) => 0 ) ; p [ 0 ] = 1 ; for ( let i = 1 ; i <= 10 ; i ++ ) { p [ i ] = ( p [ i - 1 ] * 10 ) % k ; } for ( let i = 0 ; i < n ; i ++ ) { let x = a [ i ] ; while ( x > 0 ) { len [ i ] ++ ; x = Math . floor ( x / 10 ) ; } rem [ len [ i ] ] [ a [ i ] % k ] ++ ; } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 1 ; j <= 10 ; j ++ ) { let r = ( a [ i ] * p [ j ] ) % k ; let xr = ( k - r ) % k ; ans += rem [ j ] [ xr ] ; if ( len [ i ] == j && ( r + a [ i ] % k ) % k == 0 ) ans -- ; } } return ans ; } let a = [ 4 , 5 , 2 ] ; let n = a . length , k = 2 ; document . write ( countPairs ( a , n , k ) ) ;

Index/key variables: i, j, xr
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countDigitSum ( N , K ) { var l = parseInt ( Math . pow ( 10 , N - 1 ) ) , var r = parseInt ( Math . pow ( 10 , N ) - 1 ) ; var count = 0 ; for ( i = l ; i <= r ; i ++ ) { var num = i ; var digits = Array ( N ) . fill ( 0 ) ; for ( j = N - 1 ; j >= 0 ; j -- ) { digits [ j ] = num % 10 ; num = parseInt ( num / 10 ) ; } var sum = 0 , flag = 0 ; for ( j = 0 ; j < K ; j ++ ) sum += digits [ j ] ; for ( j = K ; j < N ; j ++ ) { if ( sum - digits [ j - K ] + digits [ j ] != sum ) { flag = 1 ; break ; } } if ( flag == 0 ) { count ++ ; } } return count ; } var N = 2 , K = 1 ; document . write ( countDigitSum ( N , K ) ) ;

Index/key variables: j
Accumulator variables: count, i, j, sum
Iterator variables: i, j
Javascript program:
function calculate ( arr ) { let n = arr . length ; let ans = [ ] ; for ( let i = 0 ; i < arr . length ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j < arr . length ; j ++ ) { sum += Math . abs ( arr [ i ] - arr [ j ] ) ; } ans . push ( sum ) ; } return ans ; } let arr = [ 2 , 3 , 5 , 6 ] ; document . write ( calculate ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findMinimum ( s ) { var n = s . length ; var x = Array ( n + 1 ) . fill ( 0 ) ; s . reverse ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { if ( x [ i ] == 1 ) { x [ i + 1 ] = 1 ; x [ i ] = 0 ; } else if ( i && x [ i - 1 ] == 1 ) { x [ i + 1 ] = 1 ; x [ i - 1 ] = - 1 ; } else x [ i ] = 1 ; } } var c = 0 ; for ( var i = 0 ; i <= n ; i ++ ) { if ( x [ i ] != 0 ) c ++ ; } document . write ( c ) ; } var str = " " . split ( ' ' ) ; findMinimum ( str ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function splitIntoFibonacciHelper ( pos , S , seq ) { if ( pos == S . length && ( seq . length >= 3 ) ) { return true ; } let num = 0 ; for ( let i = pos ; i < S . length ; i ++ ) { num = num * 10 + ( S [ i ] - ' ' ) ; if ( num > Number . MAX_VALUE ) break ; if ( S [ pos ] == ' ' && i > pos ) break ; if ( seq . length > 2 && ( num > ( seq [ seq . length - 1 ] + seq [ seq . length - 2 ] ) ) ) break ; if ( seq . length < 2 || ( num == ( seq [ seq . length - 1 ] + seq [ seq . length - 2 ] ) ) ) { seq . push ( num ) ; if ( splitIntoFibonacciHelper ( i + 1 , S , seq ) ) return true ; seq . pop ( ) ; } } return false ; } function splitIntoFibonacci ( S ) { let seq = [ ] ; splitIntoFibonacciHelper ( 0 , S , seq ) ; if ( seq . length >= 3 ) { for ( let i = 0 ; i < seq . length ; i ++ ) document . write ( seq [ i ] + " " ) ; } else { document . write ( " " ) ; } } let S = " " ; splitIntoFibonacci ( S ) ;

Index/key variables: i, pos
Accumulator variables: i
Iterator variables: i
Javascript program:
function good_pairs ( str , N ) { let arr = new Array ( 32 ) ; arr . fill ( 0 ) ; let strCount = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let Weight = 0 ; for ( let j = 0 ; j < str [ i ] . length ; j ++ ) { switch ( str [ i ] [ j ] ) { case ' ' : Weight = Weight | 1 ; break ; case ' ' : Weight = Weight | 2 ; break ; case ' ' : Weight = Weight | 4 ; break ; case ' ' : Weight = Weight | 8 ; break ; case ' ' : Weight = Weight | 16 ; break ; } } arr [ Weight ] ++ ; } for ( let i = 0 ; i < 32 ; i ++ ) { for ( let j = i + 1 ; j < 32 ; j ++ ) { if ( ( i j ) == 31 ) strCount += arr [ i ] * arr [ j ] ; } } strCount += parseInt ( ( arr [ 31 ] * ( arr [ 31 ] - 1 ) ) / 2 , 10 ) ; return strCount ; } let str = [ " " , " " ] ; let N = str . length ; document . write ( good_pairs ( str , N ) ) ;

Index/key variables: Weight, i, j
Accumulator variables: i, j, strCount
Iterator variables: i, j
Javascript program:
function solve ( arr , r , c ) { var idx = 1 ; var dp = new Array ( r ) ; var i , j ; for ( i = 0 ; i < r ; i ++ ) dp [ i ] = new Array ( c ) ; for ( i = 0 ; i < r ; i ++ ) { if ( i % 2 == 0 ) { for ( j = 0 ; j < c ; j ++ ) { if ( arr [ idx - 1 ] == 0 ) idx ++ ; dp [ i ] [ j ] = idx ; arr [ idx - 1 ] -- ; } } else { for ( j = c - 1 ; j >= 0 ; j -- ) { if ( arr [ idx - 1 ] == 0 ) idx ++ ; dp [ i ] [ j ] = idx ; arr [ idx - 1 ] -- ; } } } for ( i = 0 ; i < r ; ++ i ) { for ( j = 0 ; j < c ; ++ j ) { document . write ( dp [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } var r = 3 , c = 5 ; var n = 5 ; var arr = [ 1 , 2 , 3 , 4 , 5 ] ; solve ( arr , r , c ) ;

Index/key variables: i, j
Accumulator variables: i, idx, j
Iterator variables: i, j
Javascript program:
function count ( k , s ) { var ar = Array ( s . length ) . fill ( 0 ) ; var end = 0 ; var i , j ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { for ( j = i ; j < s . length && j <= i + k ; j ++ ) { ar [ j ] = - 1 ; end = j ; } i = end ; } } end = 0 ; for ( i = s . length - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' ) { for ( j = i ; j >= 0 && j >= i - k ; j -- ) { ar [ j ] = - 1 ; end = j ; } i = end ; } } var ans = 0 ; end = 0 ; var g ; for ( j = 0 ; j < s . length ; j ++ ) { if ( ar [ j ] == 0 ) { ans ++ ; for ( g = j ; g <= j + k && g < s . length ; g ++ ) { ar [ g ] = - 1 ; end = g ; } j = end - 1 ; } } return ans ; } var K = 2 ; var s = " " ; document . write ( count ( K , s ) ) ;

Index/key variables: g, i, j
Accumulator variables: ans, g, i, j
Iterator variables: g, i, j
Javascript program:
let row = 6 ; let col = 7 ; let vis = new Array ( row + 1 ) ; for ( var i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = new Array ( 2 ) ; } let id = 0 ; let diameter = 0 , length = 0 ; let x = 0 , y = 0 ; let dx = [ - 1 , 1 , 0 , 0 ] ; let dy = [ 0 , 0 , - 1 , 1 ] ; function dfs ( a , b , lis ) { vis [ a ] [ b ] = id ; length ++ ; if ( length > diameter ) { x = a ; y = b ; diameter = length ; } for ( let j = 0 ; j < 4 ; j ++ ) { let cx = a + dx [ j ] ; let cy = b + dy [ j ] ; if ( cx < 0 cy < 0 cx >= row cy >= col lis [ cx ] [ cy ] == 0 vis [ cx ] [ cy ] > 0 ) { continue ; } dfs ( cx , cy , lis ) ; } vis [ a ] [ b ] = 0 ; length -- ; } function findMaximumLength ( lis ) { id ++ ; length = 0 ; diameter = 0 ; for ( let i = 0 ; i < row ; i ++ ) { for ( let j = 0 ; j < col ; j ++ ) { if ( lis [ i ] [ j ] != 0 ) { dfs ( i , j , lis ) ; i = row ; break ; } } } id ++ ; length = 0 ; diameter = 0 ; dfs ( x , y , lis ) ; document . write ( diameter ) ; } let grid = [ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 , 1 , 1 , 0 ] , [ 0 , 0 , 0 , 1 , 0 , 0 , 0 ] ] ; findMaximumLength ( grid ) ;

Index/key variables: a, b, cx, cy, i, j
Accumulator variables: i, id, j
Iterator variables: i, j
Javascript program:
function getSubsequence ( ar ) { let N = ar . length ; let ans = [ ] ; ans . push ( ar [ 0 ] ) ; for ( let i = 1 ; i < N - 1 ; i ++ ) { if ( ar [ i ] > ar [ i - 1 ] ) { if ( i < N - 1 && ar [ i ] <= ar [ i + 1 ] ) { continue ; } else { ans . push ( ar [ i ] ) ; } } else { if ( i < N - 1 && ar [ i + 1 ] < ar [ i ] ) { continue ; } else { ans . push ( ar [ i ] ) ; } } } ans . push ( ar [ N - 1 ] ) ; for ( let it = 0 ; it < ans . length ; it ++ ) document . write ( ans [ it ] + " " ) ; } let arr = [ 1 , 2 , 4 , 3 , 5 ] ; getSubsequence ( arr ) ;

Index/key variables: i, it
Accumulator variables: i, it
Iterator variables: i, it
Javascript program:
function Minsteps ( n ) { var ans = 0 ; while ( n > 1 ) { if ( n % 5 == 0 ) { ans ++ ; n = n / 5 ; continue ; } else if ( n % 4 == 0 ) { ans ++ ; n = n / 4 ; continue ; } else if ( n % 3 == 0 ) { ans ++ ; n = n / 3 ; continue ; } else if ( n % 2 == 0 ) { ans ++ ; n = n / 2 ; continue ; } return - 1 ; } return ans ; } var n = 10 ; document . write ( Minsteps ( n ) ) ;

Accumulator variables: ans
Javascript program:
function minDifference ( num ) { let maximum = ( num . toString ( ) ) . split ( ' ' ) ; let minimum = ( num . toString ( ) ) . split ( ' ' ) ; let n = maximum . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( maximum [ i ] != ' ' ) { let digit = maximum [ i ] ; for ( let j = i ; j < n ; j ++ ) { if ( maximum [ j ] == digit ) maximum [ j ] = ' ' ; } break ; } } if ( minimum [ 0 ] == ' ' ) { for ( let i = 1 ; i < n ; i ++ ) { if ( minimum [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) > 1 ) { let digit = minimum [ i ] ; for ( let j = i ; j < n ; j ++ ) { if ( digit == minimum [ j ] ) minimum [ j ] = ' ' ; } break ; } } } else { let digit = minimum [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( minimum [ i ] == digit ) minimum [ i ] = ' ' ; } } return parseInt ( maximum . join ( " " ) ) - parseInt ( minimum . join ( " " ) ) ; } let N = 1101157 ; document . write ( minDifference ( N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { return b == 0 ? a : gcd ( b , a % b ) ; } function checkDivisible ( x , k ) { var g = gcd ( x , k ) ; k /= g ; if ( x % k == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var x = 6 , k = 9 ; checkDivisible ( x , k ) ;

Accumulator variables: k
Javascript program:
function MinimumValue ( arr , n ) { arr . sort ( ) ; let minXor = Number . MAX_VALUE ; let val = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { val = arr [ i ] ^ arr [ i + 1 ] ; minXor = Math . min ( minXor , val ) ; } return minXor ; } let N = 6 ; let A = [ 12 , 3 , 14 , 5 , 9 , 8 ] ; document . write ( MinimumValue ( A , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxNormalSubstring ( P , Q , K , N ) { if ( K == 0 ) return 0 ; var count = 0 ; var left = 0 , right = 0 ; var ans = 0 ; while ( right < N ) { while ( right < N && count <= K ) { var pos = P [ right ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( Q [ pos ] == ' ' ) { if ( count + 1 > K ) break ; else count ++ ; } right ++ ; if ( count <= K ) ans = Math . max ( ans , right - left ) ; } while ( left < right ) { var pos = P [ left ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; left ++ ; if ( Q [ pos ] == ' ' ) count -- ; if ( count < K ) break ; } } return ans ; } var P = " " , Q = " " ; var K = 2 ; var N = P . length ; document . write ( maxNormalSubstring ( P , Q , K , N ) ) ;

Index/key variables: left, pos, right
Accumulator variables: count, left, right
Javascript program:
function countOperations ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] & 1 ) { arr [ i ] ++ ; arr [ i + 1 ] ++ ; count += 2 ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & 1 ) return - 1 ; } return count ; } let arr = [ 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; document . write ( countOperations ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countPairs ( arr , k , n ) { arr . sort ( ( a , b ) => a - b ) ; let pair = 0 ; let index = 0 ; while ( index < n - 1 ) { if ( arr [ index + 1 ] - arr [ index ] <= k ) { pair += 1 ; index += 2 ; } else { index += 1 ; } } return pair ; } let arr = [ 1 , 4 , 3 , 7 , 5 ] ; let k = 2 ; let n = arr . length ; let count = countPairs ( arr , k , n ) ; document . write ( count + " " ) ;

Index/key variables: index
Accumulator variables: index, pair
Javascript program:
function maxProfit ( profitA , profitB , n ) { let preSum = new Array ( n ) ; preSum [ 0 ] = profitA [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { preSum [ i ] = preSum [ i - 1 ] + profitA [ i ] ; } let suffSum = new Array ( n ) ; suffSum [ n - 1 ] = profitB [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) { suffSum [ i ] = suffSum [ i + 1 ] + profitB [ i ] ; } let res = preSum [ n - 1 ] ; for ( let i = 1 ; i < n - 1 ; i ++ ) { res = Math . max ( res , preSum [ i ] + suffSum [ i + 1 ] ) ; } res = Math . max ( res , suffSum [ 0 ] ) ; return res ; } let profitA = [ 2 , 3 , 2 ] ; let profitB = [ 10 , 30 , 40 ] ; let n = profitA . length ; document . write ( maxProfit ( profitA , profitB , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LongestXorSubsequence ( arr , n ) { let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { v . push ( [ arr [ i ] ^ arr [ j ] , [ i , j ] ] ) ; } } v . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ; let dp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = 1 ; } for ( let i of v ) { dp [ i [ 1 ] [ 1 ] ] = Math . max ( dp [ i [ 1 ] [ 1 ] ] , 1 + dp [ i [ 1 ] [ 0 ] ] ) ; } let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) ans = Math . max ( ans , dp [ i ] ) ; return ans ; } let arr = [ 2 , 12 , 6 , 7 , 13 , 14 , 8 , 6 ] ; let n = arr . length ; document . write ( LongestXorSubsequence ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function FindMinOperation ( a , n , k ) { let Q = [ ] ; for ( let i = 0 ; i < n ; i ++ ) Q . push ( a [ i ] ) ; Q . sort ( function ( a , b ) { return a - b } ) ; let ans = 0 ; while ( true ) { if ( Q [ 0 ] >= k ) break ; if ( Q . length < 2 ) return - 1 ; let x = Q [ 0 ] ; Q . shift ( ) ; let y = Q [ 0 ] ; Q . shift ( ) ; let z = parseInt ( ( x * y ) / gcd ( x , y ) , 10 ) ; Q . push ( z ) ; Q . sort ( function ( a , b ) { return a - b } ) ; ans ++ ; } return ans ; } let a = [ 3 , 5 , 7 , 6 , 8 ] ; let k = 8 ; let n = a . length ; document . write ( FindMinOperation ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
using System ; using System . Collections ; class GfG { function Check ( a , b , n , m ) { for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( a [ i ] [ j ] > b [ i ] [ j ] ) { let temp = a [ i ] [ j ] ; a [ i ] [ j ] = b [ i ] [ j ] ; b [ i ] [ j ] = temp ; } for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m - 1 ; j ++ ) if ( a [ i ] [ j ] >= a [ i ] [ j + 1 ] b [ i ] [ j ] >= b [ i ] [ j + 1 ] ) return " " ; for ( let i = 0 ; i < n - 1 ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( a [ i ] [ j ] >= a [ i + 1 ] [ j ] b [ i ] [ j ] >= b [ i + 1 ] [ j ] ) return " " ; return " " ; } let n = 2 , m = 2 ; let a = [ [ 2 , 10 ] , [ 11 , 5 ] ] ; let b = [ [ 9 , 4 ] , [ 3 , 12 ] ] ; document . write ( Check ( a , b , n , m ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GfG
Javascript program:
function smallestString ( N , A ) { let ch = ' ' ; let S = " " ; if ( N < 1 A [ 0 ] != 1 ) { S = " " ; return S ; } S += ch ; ch = String . fromCharCode ( ch . charCodeAt ( 0 ) + 1 ) ; for ( let i = 1 ; i < N ; i ++ ) { let diff = A [ i ] - A [ i - 1 ] ; if ( diff > 1 diff < 0 A [ i ] > 26 ) { S = " " ; return S ; } else if ( diff == 0 ) S += ' ' ; else { S += ch ; ch = String . fromCharCode ( ch . charCodeAt ( 0 ) + 1 ) ; } } return S ; } let arr = [ 1 , 1 , 2 , 3 , 3 ] ; let n = arr . length ; document . write ( smallestString ( n , arr ) ) ;

Index/key variables: i
Accumulator variables: S, i
Iterator variables: i
Javascript program:
function canBePicked ( digits , num ) { var copyDigits = new Array ( 10 ) ; ; for ( var i = 0 ; i < 10 ; i ++ ) copyDigits [ i ] = digits [ i ] ; while ( num > 0 ) { var digit = num % 10 ; if ( copyDigits [ digit ] == 0 ) return false ; else copyDigits [ digit ] -= 1 ; num = Math . floor ( num / 10 ) ; } return true ; } function countAlphabets ( n ) { var count = 0 ; var digits = new Array ( 10 ) ; digits . fill ( 0 ) ; while ( n > 0 ) { var digit = n % 10 ; digits [ digit ] += 1 ; n = Math . floor ( n / 10 ) ; } for ( var i = 97 ; i <= 122 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; for ( var i = 65 ; i < 91 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; return count ; } var n = 1623455078 ; document . write ( countAlphabets ( n ) ) ;

Index/key variables: digit, i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function greatestKBits ( X , K ) { let set_bit_count = countSetBits ( X ) ; if ( set_bit_count <= K ) return X ; let diff = set_bit_count - K ; for ( let i = 0 ; i < diff ; i ++ ) X &= ( X - 1 ) ; return X ; } let X = 21 , K = 2 ; document . write ( greatestKBits ( X , K ) ) ;

Accumulator variables: X, count, i
Iterator variables: i
Javascript program:
function findMaxDistance ( numOfCities , station , n ) { var hasStation = Array ( numOfCities + 1 ) . fill ( false ) ; for ( var city = 0 ; city < n ; city ++ ) { hasStation [ station [ city ] ] = true ; } var dist = 0 ; var maxDist = 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { maxDist = Math . min ( station [ i ] , maxDist ) ; } for ( var city = 0 ; city < numOfCities ; city ++ ) { if ( hasStation [ city ] == true ) { maxDist = Math . max ( ( dist + 1 ) / 2 , maxDist ) ; dist = 0 ; } else dist += 1 ; } return Math . max ( maxDist , dist ) ; } var numOfCities = 6 ; var station = [ 3 , 1 ] ; var n = station . length ; document . write ( " " + findMaxDistance ( numOfCities , station , n ) ) ;

Index/key variables: city, i
Accumulator variables: city, dist, i
Iterator variables: city, i
Javascript program:
function split ( x , n ) { if ( x < n ) document . write ( " " ) ; else if ( x % n == 0 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( ( x / n ) + " " ) ; } else { let zp = n - ( x % n ) ; let pp = Math . floor ( x / n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i >= zp ) document . write ( ( pp + 1 ) + " " ) ; else document . write ( pp + " " ) ; } } } let x = 5 ; let n = 3 ; split ( x , n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function cal_minimum_time ( X ) { let t = 0 ; let sum = 0 ; while ( sum < X ) { t ++ ; sum = sum + t ; } return t ; } let n = 6 ; let ans = cal_minimum_time ( n ) ; document . write ( " " + ans ) ;

Accumulator variables: t
Javascript program:
let s = " " ; let u = Array ( 26 ) . fill ( 0 ) ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] . toUpperCase ( ) ) { u [ s [ i ] - 65 ] += 1 ; } else { u [ s [ i ] - 97 ] -= 1 ; } } let f1 = true ; let po = 0 ; let ne = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( u [ i ] > 0 ) po += u [ i ] ; if ( u [ i ] < 0 ) ne += u [ i ] ; } if ( po == 0 && ne == 0 ) document . write ( " " ) ; else if ( po == 1 && ne == 0 ) document . write ( " " ) ; else if ( po == 0 && ne == - 1 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, ne, po
Iterator variables: i
Boolean variables: f1