dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let ans = 0 ; let edges = new Array ( 100000 ) ; for ( let i = 0 ; i < 100000 ; i ++ ) edges [ i ] = [ ] ; function Add_edge ( u , v ) { edges [ u ] . push ( v ) ; edges [ v ] . push ( u ) ; } function minTimeToColor ( node , parent , arrival_time ) { let current_time = 0 ; for ( let x = 0 ; x < edges [ node ] . length ; x ++ ) { if ( edges [ node ] [ x ] != parent ) { ++ current_time ; if ( current_time == arrival_time ) ++ current_time ; ans = Math . max ( ans , current_time ) ; minTimeToColor ( edges [ node ] [ x ] , node , current_time ) ; } } } let A = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ] ; for ( let i = 0 ; i < A . length ; i ++ ) { Add_edge ( A [ i ] [ 0 ] , A [ i ] [ 1 ] ) ; } minTimeToColor ( 1 , - 1 , 0 ) ; document . write ( ans ) ;

Index/key variables: i, node, u, v, x
Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
function largestNum ( arr ) { let res = 0 ; arr . sort ( ( a , b ) => a - b ) ; let l = 0 , r = arr . length - 1 ; while ( l < r ) { let sum = arr [ l ] + arr [ r ] ; if ( sum == 0 ) { res = Math . max ( res , Math . max ( arr [ l ] , arr [ r ] ) ) ; return res ; } else if ( sum < 0 ) { l ++ ; } else { r -- ; } } return res ; } let arr = [ 3 , 2 , - 2 , 5 , - 3 ] ; document . write ( ( largestNum ( arr ) ) ) ;

Index/key variables: l, r
Accumulator variables: l, r
Javascript program:
function findLarger ( arr , n ) { let mid = ( n + 1 ) / 2 ; let mx = Math . max . apply ( null , arr ) var count = new Array ( mx + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { count [ arr [ i ] ] ++ ; } for ( let i = mx ; i >= 0 ; i -- ) { while ( count [ i ] > 0 ) { count [ i ] -- ; mid -- ; document . write ( i + ' ' ) ; if ( mid == 0 ) break ; } if ( mid == 0 ) break ; } } var arr = [ 10 , 4 , 2 , 8 , 9 ] ; var N = 5 ; findLarger ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, mid
Iterator variables: i
Javascript program:
function probability ( arr1 , arr2 ) { let N = arr1 . length ; let M = arr2 . length ; let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let y = 0 ; for ( let j = 0 ; j < M ; j ++ ) { if ( arr2 [ j ] > arr1 [ i ] ) y ++ ; } res += y ; } res = ( res / ( N * M ) ) ; return res ; } let arr1 = [ 5 , 2 , 6 , 1 ] ; let arr2 = [ 1 , 6 , 10 , 1 ] ; document . write ( probability ( arr1 , arr2 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res, y
Iterator variables: i, j
Javascript program:
function probability ( arr1 , arr2 ) { var N = 4 ; var M = 4 ; var res = 0 ; arr2 . sort ( function ( a , b ) { return a - b ; } ) ; for ( var i = 0 ; i < N ; i ++ ) { var y = countGreater ( arr2 , arr1 [ i ] ) ; res += y ; } res = res / ( N * M ) ; return res ; } function countGreater ( arr , k ) { var n = 4 ; var l = 0 ; var r = n - 1 ; var leftGreater = n ; while ( l <= r ) { var m = Math . floor ( l + ( r - l ) / 2 ) ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return n - leftGreater ; } var arr1 = [ 5 , 2 , 6 , 1 ] ; var arr2 = [ 1 , 6 , 10 , 1 ] ; document . write ( probability ( arr1 , arr2 ) ) ;

Index/key variables: i, m
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function minCost ( arr , A , B ) { let n = arr . length ; let m = arr [ 0 ] . length ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( arr [ i ] [ j ] == ' ' ) continue ; if ( j == m - 1 ) ans += A ; else { if ( arr [ i ] [ j + 1 ] == ' ' ) { ans += Math . min ( 2 * A , B ) ; j ++ ; } else ans += A ; } } } document . write ( ans ) ; } var arr = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; let A = 2 , B = 10 ; minCost ( arr , A , B ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countInversions ( arr , n ) { var v = [ ] ; var i ; for ( i = 1 ; i <= n ; i ++ ) { v . push ( i ) ; } var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { var index = v . indexOf ( arr [ i ] ) ; ans += index ; v . splice ( index , 1 ) ; } document . write ( ans ) ; } var arr = [ 2 , 3 , 1 , 5 , 4 ] ; var n = arr . length ; countInversions ( arr , n ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findPairs ( A , B ) { for ( let i = 1 ; i <= B ; i ++ ) { let y = A ^ i ; if ( y > 0 && ( i y ) == B ) { document . write ( i + " " + y + " " ) ; } } } let A = 8 , B = 10 ; findPairs ( A , B ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function binarysearch ( array , right , element ) { let left = 1 ; while ( left <= right ) { let mid = Math . floor ( ( left + right / 2 ) ) ; if ( array [ mid ] == element ) { return mid ; } if ( mid - 1 > 0 && array [ mid ] > element && array [ mid - 1 ] < element ) { return mid ; } else if ( array [ mid ] < element ) { left = mid + 1 ; } else { right = mid - 1 ; } } return 1 ; } function countDistinct ( arr , L , R ) { let count = 0 ; let pref = Array . from ( { length : arr . length + 1 } , ( _ , i ) => 0 ) ; for ( let i = 1 ; i <= arr . length ; ++ i ) { count += arr [ i - 1 ] ; pref [ i ] = count ; } let left = binarysearch ( pref , arr . length + 1 , L ) ; let right = binarysearch ( pref , arr . length + 1 , R ) ; document . write ( ( right - left ) + 1 ) ; } let arr = [ 3 , 6 , 7 , 1 , 8 ] ; let L = 3 ; let R = 7 ; countDistinct ( arr , L , R ) ;

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Javascript program:
function countSubstrings ( s ) { var n = s . length ; var ans = 0 ; var i , j ; for ( i = 0 ; i < n ; i ++ ) { var cnt = 0 ; for ( j = i ; j < n ; j ++ ) { if ( s [ j ] == ' ' ) cnt ++ ; else if ( s [ j ] == ' ' ) cnt -- ; if ( cnt > 0 ) { ans ++ ; } } } document . write ( ans ) ; } var S = " " ; countSubstrings ( S ) ;

Index/key variables: j
Accumulator variables: ans, cnt, i, j
Iterator variables: i, j
Javascript program:
function ischar ( x ) { if ( ( x >= ' ' && x <= ' ' ) || ( x >= ' ' && x <= ' ' ) ) { return true ; } return false ; } function isnum ( x ) { if ( x >= ' ' && x <= ' ' ) return true ; return false ; } function findIdandDomain ( S , N ) { let ID , Domain ; let words = [ ] ; let curr = " " ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { words . push ( curr ) ; curr = " " ; } else { if ( S [ i ] == ' ' ) { if ( i + 1 == N || ( i + 1 < N && S [ i + 1 ] == ' ' ) ) continue ; } curr += S [ i ] ; } } if ( curr . length >= 1 ) words . push ( curr ) ; for ( let i = 0 ; i < words . length ; i ++ ) { if ( words [ i ] . length == 10 ) { let flag = 0 ; for ( let j = 0 ; j <= 9 ; j ++ ) { if ( j >= 5 && j < 9 ) { if ( isnum ( words [ i ] [ j ] ) == 0 ) flag = 1 ; } else { if ( ischar ( words [ i ] [ j ] ) == 0 ) flag = 1 ; } } if ( ! flag ) { ID = words [ i ] ; } } if ( words [ i ] . substring ( 0 , 3 ) == " " && words [ i ] . substring ( words [ i ] . length - 3 ) == " " ) { Domain = words [ i ] . substring ( 4 ) ; } } document . write ( " " + ID + " " ) ; document . write ( " " + Domain ) ; } let S = " " + " " + " " ; let N = S . length ; findIdandDomain ( S , N ) ;

Index/key variables: i, j
Accumulator variables: curr, i, j
Iterator variables: i, j
Javascript program:
function isValid ( weight , n , D , mx ) { let st = 1 ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += weight [ i ] ; if ( sum > mx ) { st ++ ; sum = weight [ i ] ; } if ( st > D ) return false ; } return true ; } function shipWithinDays ( weight , D , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += weight [ i ] ; let s = weight [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { s = Math . max ( s , weight [ i ] ) ; } let e = sum ; let res = - 1 ; while ( s <= e ) { let mid = s + Math . floor ( ( e - s ) / 2 ) ; if ( isValid ( weight , n , D , mid ) ) { res = mid ; e = mid - 1 ; } else s = mid + 1 ; } document . write ( res ) ; } let weight = [ 9 , 8 , 10 ] ; let D = 3 ; let N = weight . length ; shipWithinDays ( weight , D , N ) ;

Index/key variables: i
Accumulator variables: i, st, sum
Iterator variables: i
Javascript program:
function findSum ( arr , N , pt ) { var sum = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { sum += Math . abs ( arr [ i ] - pt ) ; } return sum ; } function findPoint ( arr , N , K ) { var left ; if ( N % 2 == 1 ) { left = arr [ parseInt ( N / 2 ) ] ; } else { left = arr [ parseInt ( N / 2 ) - 1 ] + 1 ; } var right = arr [ N - 1 ] ; while ( left <= right ) { var mid = parseInt ( ( left + right ) / 2 ) ; var temp = findSum ( arr , N , mid ) ; if ( temp == K ) { document . write ( mid ) ; return ; } else if ( K < temp ) { right = mid - 1 ; } else { left = mid + 1 ; } } left = arr [ 0 ] ; right = arr [ parseInt ( N / 2 ) ] - 1 ; while ( left <= right ) { var mid = parseInt ( ( left + right ) / 2 ) ; var temp = findSum ( arr , N , mid ) ; if ( temp == K ) { document . write ( mid ) ; return ; } else if ( K > temp ) { right = mid - 1 ; } else { left = mid + 1 ; } } document . write ( " " ) ; } var arr = [ 1 , 3 , 6 , 7 , 11 ] ; var K = 18 ; var N = arr . length ; findPoint ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findArray ( arr , n ) { let v = new Array ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let ans = - 1 , old_c = 0 ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { let curr_c = 0 ; arr . slice ( j , n ) . forEach ( ( item ) => { if ( item == arr [ j ] ) { curr_c ++ } } ) if ( curr_c == old_c ) { if ( arr [ j ] < ans ) ans = arr [ j ] ; } if ( curr_c > old_c ) { ans = arr [ j ] ; old_c = curr_c ; } } } v . push ( ans ) ; } for ( let i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + " " ) ; } let arr = [ 4 , 5 , 2 , 25 , 10 , 5 , 10 , 3 , 10 , 5 ] ; let size = arr . length findArray ( arr , size ) ;

Index/key variables: i, j
Accumulator variables: curr_c, i, j
Iterator variables: i, j
Javascript program:
function prodEquilibrium ( arr , N ) { let product = 1 ; for ( let i = 0 ; i < N ; i ++ ) { product *= arr [ i ] ; } let left = 1 ; let right = product ; for ( let i = 0 ; i < N ; i ++ ) { left = left * arr [ i ] ; right = right / arr [ i ] ; if ( left == right ) { document . write ( ( i + 1 ) + " " ) ; return ; } } document . write ( ( - 1 ) + " " ) ; } let arr = [ 1 , 2 , 3 , 3 , 2 , 1 ] ; let N = arr . length ; prodEquilibrium ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
Javascript program:
function countTriplets ( D , arr ) { var freq = new Map ( ) ; var ans = 0 ; var i ; for ( i = 0 ; i < arr . length ; i ++ ) { if ( freq . has ( arr [ i ] - D ) && freq . has ( arr [ i ] - 2 * D ) ) { ans += freq . get ( arr [ i ] - D ) * freq . get ( arr [ i ] - 2 * D ) ; } freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } return ans ; } var arr = [ 1 , 2 , 4 , 5 , 7 , 8 , 10 ] ; var D = 1 ; document . write ( countTriplets ( D , arr ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function find_index ( arr , N ) { let max_value = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { max_value = Math . max ( max_value , arr [ i ] ) ; } let store = new Map ( ) ; for ( let i = 1 ; i <= max_value ; i ++ ) { if ( ! store . has ( i ) ) store . set ( i , 0 ) ; store . set ( i , store . get ( i ) + 1 ) ; } if ( store . has ( 1 ) ) { store . delete ( 1 ) ; } for ( let i = 2 ; i <= Math . sqrt ( max_value ) ; i ++ ) { let multiple = 2 ; while ( ( i * multiple ) <= max_value ) { if ( store . has ( i * multiple ) ) { store . delete ( i * multiple ) ; } multiple ++ ; } } let prime_sum_from_left = 0 ; let first_array = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { first_array [ i ] = prime_sum_from_left ; if ( store . has ( arr [ i ] ) ) { prime_sum_from_left += arr [ i ] ; } } let prime_sum_from_right = 0 ; let second_array = new Array ( N ) ; for ( let i = N - 1 ; i >= 0 ; i -- ) { second_array [ i ] = prime_sum_from_right ; if ( store . has ( arr [ i ] ) ) { prime_sum_from_right += arr [ i ] ; } } for ( let i = 0 ; i < N ; i ++ ) { if ( first_array [ i ] == second_array [ i ] ) { return i ; } } return - 1 ; } let arr = [ 11 , 4 , 7 , 6 , 13 , 1 , 5 ] ; let N = arr . length ; document . write ( find_index ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, multiple, prime_sum_from_left, prime_sum_from_right
Iterator variables: i
Javascript program:
function convert ( arr , n ) { var brr = Array ( n ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; brr . sort ( ) ; for ( i = 0 ; i < n ; i ++ ) { var l = 0 , r = n - 1 , mid ; while ( l <= r ) { mid = parseInt ( ( l + r ) / 2 , 10 ) ; if ( brr [ mid ] == arr [ i ] ) { document . write ( mid + ' ' ) ; break ; } else if ( brr [ mid ] < arr [ i ] ) { l = mid + 1 ; } else { r = mid - 1 ; } } } } var arr = [ 10 , 20 , 15 , 12 , 11 , 50 ] ; var N = arr . length ; convert ( arr , N ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function findIndex ( arr , N ) { let maxValue = Number . MIN_VALUE ; ; for ( let i = 0 ; i < N ; i ++ ) { maxValue = Math . max ( maxValue , arr [ i ] ) ; } var St = new Map ( ) ; for ( let i = 1 ; i <= maxValue ; i ++ ) { St . set ( i , 1 ) ; } if ( St . has ( 1 ) ) { St . delete ( 1 ) ; } for ( let i = 2 ; i <= Math . sqrt ( maxValue ) ; i ++ ) { let j = 2 ; while ( ( i * j ) <= maxValue ) { if ( St . has ( i * j ) ) { St . delete ( i * j ) ; } j ++ ; } } let LeftCount = 0 ; let Prefix = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { Prefix [ i ] = LeftCount ; if ( St . has ( arr [ i ] ) ) { LeftCount ++ ; } } let RightCount = 0 ; let Suffix = new Array ( N ) ; for ( let i = N - 1 ; i >= 0 ; i -- ) { Suffix [ i ] = RightCount ; if ( St . has ( arr [ i ] ) ) { RightCount ++ ; } } for ( let i = 0 ; i < N ; i ++ ) { if ( Prefix [ i ] == Suffix [ i ] ) { return i ; } } return - 1 ; } let arr = [ 2 , 3 , 4 , 7 , 5 , 10 , 1 , 8 ] ; let N = arr . length ; document . write ( findIndex ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: LeftCount, RightCount, i, j
Iterator variables: i
Javascript program:
function getCountPairs ( arr , N , S ) { let count = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { for ( let j = i + 1 ; j < arr . length ; j ++ ) { if ( ( arr [ i ] + arr [ j ] ) == S ) count ++ ; } } return count ; } function countPairs ( arr , N ) { let count = 0 ; let S = [ ] ; for ( let i = 0 ; i < N ; i ++ ) S . push ( arr [ i ] ) ; for ( let ele in S ) { let sum = 2 * ele ; count += getCountPairs ( arr , N , sum ) ; } return count ; } let arr = [ 4 , 2 , 5 , 1 , 3 , 5 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: ele, i, j
Javascript program:
function isPowerOfTwo ( n ) { if ( n == 0 ) return false ; return ( Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) == Math . floor ( Math . log ( n ) / Math . log ( 2 ) ) ) ; } function printArray ( res ) { res . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < res . length ; i ++ ) { document . write ( res [ i ] + " " ) ; } } function sortedStrings ( s , N ) { let freq = new Map ( ) ; let res = new Array ( ) ; for ( let i = 0 ; i < N ; i ++ ) { let st = " " ; for ( let j = 0 ; j < s [ i ] . length ; j ++ ) { if ( freq . has ( s [ i ] [ j ] ) ) { freq . set ( s [ i ] [ j ] , freq . get ( s [ i ] [ j ] ) + 1 ) } else { freq . set ( s [ i ] [ j ] , 1 ) } } for ( let ch of freq . keys ( ) ) { if ( isPowerOfTwo ( freq . get ( ch ) ) ) { for ( let j = 0 ; j < freq . get ( ch ) ; j ++ ) { st += ch ; } } } freq . clear ( ) ; if ( st . length == 0 ) continue ; let myCharArr = st . split ( " " ) ; myCharArr . sort ( ) ; let ns = " " ; for ( let j = myCharArr . length - 1 ; j >= 0 ; -- j ) ns += myCharArr [ j ] ; res . push ( ns ) ; } printArray ( res ) ; } let arr = [ " " , " " , " " ] ; let N = arr . length ; sortedStrings ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, ns, st
Iterator variables: ch, i, j
Javascript program:
function replaceCharacters ( s , p ) { var n = s . length , k = p . length ; var arr = new Array ( 26 ) . fill ( 0 ) ; var brr = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { arr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = s [ i ] ; brr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = s [ i ] ; } for ( var j = 0 ; j < k ; j ++ ) { var a = p [ j ] [ 0 ] , b = p [ j ] [ 1 ] ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( arr [ i ] === a ) { brr [ i ] = b ; } } } for ( var i = 0 ; i < n ; i ++ ) { document . write ( brr [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ) ; } } var S = " " ; var P = [ [ " " , " " ] , [ " " , " " ] , [ " " , " " ] , ] ; replaceCharacters ( S , P ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 100001 ; function SieveOfEratosthenes ( prime ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i < MAX ; i += p ) prime [ i ] = false ; } } } function smallestSemiPrime ( n ) { let prime = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } SieveOfEratosthenes ( prime ) ; let num1 = n + 1 ; while ( prime [ num1 ] != true ) { num1 ++ ; } let num2 = num1 + n ; while ( prime [ num2 ] != true ) { num2 ++ ; } document . write ( num1 * num2 ) ; } let N = 2 ; smallestSemiPrime ( N ) ;

Index/key variables: i, num1, num2, p
Accumulator variables: i, num1, num2, p
Iterator variables: i, p
Javascript program:
function productOfTwoPerfectCubes ( N ) { let cubes = new Map ( ) ; for ( let i = 1 ; i * i * i <= N ; i ++ ) cubes . set ( i * i * i , i ) ; for ( let [ key , value ] of cubes . entries ( ) ) { let firstNumber = key ; if ( N % key == 0 ) { let secondNumber = N / key ; if ( cubes . has ( secondNumber ) ) { document . write ( " " ) ; return ; } } } document . write ( " " ) ; } let N = 216 ; productOfTwoPerfectCubes ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printNumberOfPairs ( N ) { var st = new Set ( ) ; for ( let i = 2 ; i * i <= N ; i ++ ) { let x = i ; while ( x <= N ) { x *= i ; if ( x <= N ) { st . add ( x ) ; } } } document . write ( st . size ) ; } let N = 10000 ; printNumberOfPairs ( N ) ;

Accumulator variables: i, x
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function maximumProduct ( words ) { let bits = new Array ( words . length ) . fill ( 0 ) ; for ( let i = 0 ; i < words . length ; i ++ ) { for ( let j = 0 ; j < words [ i ] . length ; j ++ ) { bits [ i ] = bits [ i ] | 1 << ( words [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; } } let result = 0 ; for ( let i = 0 ; i < bits . length ; i ++ ) { for ( let j = i + 1 ; j < bits . length ; j ++ ) { if ( ( bits [ i ] & bits [ j ] ) == 0 ) { let L = countSetBits ( bits [ i ] ) ; let R = countSetBits ( bits [ j ] ) ; result = Math . max ( L * R , result ) ; } } } document . write ( result ) ; } let arr = [ " " , " " , " " , " " , " " , " " ] ; maximumProduct ( arr ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function palindrome ( str ) { var st = 0 ; var ed = str . length - 1 ; while ( st < ed ) { if ( str [ st ] == str [ ed ] ) { st ++ ; ed -- ; } else return false ; } return true ; } function printReverse ( sentence ) { var newlist = [ ] ; var lis = [ ] ; var temp = " " ; for ( var i = 0 ; i < sentence . length ; i ++ ) { if ( sentence [ i ] == ' ' ) { lis . push ( temp ) ; temp = " " ; } else temp += sentence [ i ] ; } lis . push ( temp ) ; for ( var i = 0 ; i < lis . length ; i ++ ) { if ( palindrome ( lis [ i ] ) ) newlist . push ( lis [ i ] ) ; } newlist . reverse ( ) ; var j = 0 ; for ( var i = 0 ; i < lis . length ; i ++ ) { if ( palindrome ( lis [ i ] ) ) { lis [ i ] = newlist [ j ] ; j = j + 1 ; } } for ( var i = 0 ; i < lis . length ; i ++ ) { document . write ( lis [ i ] + " " ) ; } } var sentence = " " ; printReverse ( sentence ) ;

Index/key variables: ed, i, j, st
Accumulator variables: ed, i, st, temp
Iterator variables: i
Javascript program:
function minCount ( A , B , N ) { var i = 0 for ( let j = 0 ; j < N ; j ++ ) { if ( A [ i ] == B [ j ] ) i += 1 } return N - i } var A = [ 1 , 2 , 3 , 4 , 5 ] var B = [ 1 , 5 , 2 , 3 , 4 ] N = A . length document . write ( minCount ( A , B , N ) )

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function possible ( A , N , mid , K ) { var count = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { count += Math . floor ( ( A [ i ] - 1 ) / mid ) ; } if ( count <= K ) return true ; else return false } function minimumMaximum ( A , N , K ) { var lo = 1 ; var hi = Math . max . apply ( Math , A ) ; var mid ; while ( lo < hi ) { mid = Math . floor ( ( lo + hi ) / 2 ) ; if ( possible ( A , N , mid , K ) ) { hi = mid ; } else { lo = mid + 1 ; } } return hi ; } var arr = [ 2 , 4 , 8 , 2 ] ; var K = 4 ; var N = arr . length ; document . write ( minimumMaximum ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function maximumNumber ( arr , N , K ) { let minimum = Math . min ( ... arr ) let ans = minimum + K ; for ( let i = 0 ; i < N ; i ++ ) { if ( Math . abs ( arr [ i ] - ans ) > K ) { ans = - 1 ; break ; } } document . write ( ans ) } let arr = [ 1 , 2 , 5 ] let K = 2 let N = arr . length maximumNumber ( arr , N , K ) ;

Index/key variables: i
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 ( let i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } function sumOfPrimeSquare ( n ) { let i = 0 ; let squares = [ ] ; while ( i * i < n ) { squares . push ( i * i ) ; i ++ ; } let flag = false ; for ( i = 0 ; i < squares . length ; i ++ ) { let difference = n - squares [ i ] ; if ( isPrime ( difference ) ) { flag = true ; break ; } } if ( flag ) { document . write ( " " ) ; } else document . write ( " " ) ; } let N = 27 ; sumOfPrimeSquare ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function SieveOfEratosthenes ( prime , n ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) { prime [ i ] = false ; } } } } function sumOfPrimeSquare ( n ) { let flag = false ; let prime = new Array ( n + 1 ) . fill ( true ) ; SieveOfEratosthenes ( prime , n ) ; for ( let i = 0 ; i <= n ; i ++ ) { if ( ! prime [ i ] ) continue ; let dif = n - i ; if ( Math . ceil ( Math . sqrt ( dif ) ) == Math . floor ( Math . sqrt ( dif ) ) ) { flag = true ; break ; } } if ( flag ) { document . write ( " " ) ; } else document . write ( " " ) ; } let N = 27 ; sumOfPrimeSquare ( N ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Boolean variables: flag
Javascript program:
function check ( arr , M , K , ind ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 1 ; j < K ; j ++ ) { if ( arr [ ind + i ] != arr [ ind + i + j * M ] ) { return false ; } } } return true ; } function SubarrayRepeatsKorMore ( arr , N , M , K ) { for ( let ind = 0 ; ind <= N - M * K ; ind ++ ) { if ( check ( arr , M , K , ind ) ) { return true ; } } return false ; } let arr = [ 2 , 1 , 2 , 1 , 1 , 1 , 3 ] ; let M = 2 , K = 2 ; let N = arr . length ; if ( SubarrayRepeatsKorMore ( arr , N , M , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: i, ind, j
Iterator variables: i, ind, j