dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isCheck ( str ) { var len = str . length ; var lowerStr = " " , upperStr = " " ; for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] < ' ' ) upperStr = upperStr + str [ i ] ; else lowerStr = lowerStr + str [ i ] ; } lowerStr = lowerStr . toUpperCase ( ) ; console . log ( lowerStr ) ; return lowerStr === upperStr ; } var str = " " ; isCheck ( str ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function encode ( s , k ) { let newS = " " ; for ( let i = 0 ; i < s . length ; ++ i ) { let val = s [ i ] . charCodeAt ( 0 ) ; let dup = k ; if ( val + k > 122 ) { k -= ( 122 - val ) ; k = k % 26 ; newS += String . fromCharCode ( 96 + k ) ; } else { newS += String . fromCharCode ( val + k ) ; } k = dup ; } document . write ( newS ) ; } let str = " " ; let k = 28 ; encode ( str , k ) ;

Index/key variables: i
Accumulator variables: k, newS
Iterator variables: i
Javascript program:
function isVowel ( x ) { if ( x === " " x === " " x === " " x === " " x === " " ) return true ; else return false ; } function updateSandwichedVowels ( a ) { var n = a . length ; var updatedString = " " ; for ( var i = 0 ; i < n ; i ++ ) { if ( i === 0 i === n - 1 ) { updatedString += a [ i ] ; continue ; } if ( isVowel ( a [ i ] ) === true && isVowel ( a [ i - 1 ] ) === false && isVowel ( a [ i + 1 ] ) === false ) { continue ; } updatedString += a [ i ] ; } return updatedString ; } var str = " " ; var updatedString = updateSandwichedVowels ( str ) ; document . write ( updatedString ) ;

Index/key variables: i
Accumulator variables: i, updatedString
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . left = null ; this . right = null ; } } ; var ans = 0 ; function newNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; newNode . left = newNode . right = null ; return ( newNode ) ; } function findPathUtil ( root , k , path , flag ) { if ( root == null ) return ; if ( root . data >= k ) flag = 1 ; if ( root . left == null && root . right == null ) { if ( flag == 1 ) { ans = 1 ; document . write ( " " ) ; for ( var i = 0 ; i < path . length ; i ++ ) { document . write ( path [ i ] + " " ) ; } document . write ( root . data + " " ) ; } return ; } path . push ( root . data ) ; findPathUtil ( root . left , k , path , flag ) ; findPathUtil ( root . right , k , path , flag ) ; path . pop ( ) ; } function findPath ( root , k ) { var flag = 0 ; ans = 0 ; var v = [ ] ; findPathUtil ( root , k , v , flag ) ; if ( ans == 0 ) document . write ( " " ) ; } var K = 25 ; var root = newNode ( 10 ) ; root . left = newNode ( 5 ) ; root . right = newNode ( 8 ) ; root . left . left = newNode ( 29 ) ; root . left . right = newNode ( 2 ) ; root . right . right = newNode ( 98 ) ; root . right . left = newNode ( 1 ) ; root . right . right . right = newNode ( 50 ) ; root . left . left . left = newNode ( 20 ) ; findPath ( root , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function MaximumHeight ( a , n ) { let result = 1 ; for ( i = 1 ; i <= n ; ++ i ) { let y = ( i * ( i + 1 ) ) / 2 ; if ( y < n ) result = i ; else break ; } return result ; } let arr = [ 40 , 100 , 20 , 30 ] ; let n = arr . length ; document . write ( MaximumHeight ( arr , n ) ) ;

Iterator variables: i
Javascript program:
function findK ( n , k ) { let a = [ ] ; for ( let i = 1 ; i < n ; i ++ ) if ( i % 2 == 1 ) a . push ( i ) ; for ( let i = 1 ; i < n ; i ++ ) if ( i % 2 == 0 ) a . push ( i ) ; return ( a [ k - 1 ] ) ; } let n = 10 , k = 3 ; document . write ( findK ( n , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function pell ( n ) { if ( n <= 2 ) return n ; let a = 1 ; let b = 2 ; let c ; for ( let i = 3 ; i <= n ; i ++ ) { c = 2 * b + a ; a = b ; b = c ; } return b ; } let n = 4 ; document . write ( pell ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countOddPrimeFactors ( n ) { let result = 1 ; while ( n % 2 == 0 ) n /= 2 ; for ( let i = 3 ; i * i <= n ; i += 2 ) { let divCount = 0 ; while ( n % i == 0 ) { n /= i ; ++ divCount ; } result *= divCount + 1 ; } if ( n > 2 ) result *= 2 ; return result ; } function politness ( n ) { return countOddPrimeFactors ( n ) - 1 ; } let n = 90 ; document . write ( " " + n + " " + politness ( n ) + " " ) ; n = 15 ; document . write ( " " + n + " " + politness ( n ) ) ;

Accumulator variables: i, n, result
Iterator variables: i
Javascript program:
var primes = [ ] ; var MAX = 1000000 ; function Sieve ( ) { let n = MAX ; let nNew = parseInt ( Math . sqrt ( n ) ) ; var marked = new Array ( n / 2 + 500 ) . fill ( 0 ) ; for ( let i = 1 ; i <= parseInt ( ( nNew - 1 ) / 2 ) ; i ++ ) for ( let j = ( i * ( i + 1 ) ) << 1 ; j <= parseInt ( n / 2 ) ; j = j + 2 * i + 1 ) marked [ j ] = 1 ; primes . push ( 2 ) ; for ( let i = 1 ; i <= parseInt ( n / 2 ) ; i ++ ) if ( marked [ i ] == 0 ) primes . push ( 2 * i + 1 ) ; } function binarySearch ( left , right , n ) { if ( left <= right ) { let mid = parseInt ( ( left + right ) / 2 ) ; if ( mid == 0 mid == primes . length - 1 ) return primes [ mid ] ; if ( primes [ mid ] == n ) return primes [ mid - 1 ] ; if ( primes [ mid ] < n && primes [ mid + 1 ] > n ) return primes [ mid ] ; if ( n < primes [ mid ] ) return binarySearch ( left , mid - 1 , n ) ; else return binarySearch ( mid + 1 , right , n ) ; } return 0 ; } Sieve ( ) ; let n = 17 ; document . write ( binarySearch ( 0 , primes . length - 1 , n ) ) ;

Index/key variables: i, j, mid
Accumulator variables: i
Iterator variables: i, j
Javascript program:
function FlipBits ( n ) { return n -= ( n & ( - n ) ) ; } let N = 12 ; document . write ( " " ) ; document . write ( " " + FlipBits ( N ) ) ;

Accumulator variables: n
Javascript program:
function Maximum_xor_Triplet ( n , a ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { s . add ( a [ i ] ^ a [ j ] ) ; } } let ans = 0 ; for ( let i of s . values ( ) ) { for ( let j = 0 ; j < n ; j ++ ) { ans = Math . max ( ans , i ^ a [ j ] ) ; } } document . write ( ans , " " ) ; } let a = [ 1 , 3 , 8 , 15 ] ; let n = a . length ; Maximum_xor_Triplet ( n , a ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function prletMissing ( arr , low , high ) { let polets_of_range = Array ( high - low + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( low <= arr [ i ] && arr [ i ] <= high ) polets_of_range [ arr [ i ] - low ] = true ; } for ( let x = 0 ; x <= high - low ; x ++ ) { if ( polets_of_range [ x ] == false ) document . write ( ( low + x ) + " " ) ; } } let arr = [ 1 , 3 , 5 , 4 ] ; let low = 1 , high = 10 ; prletMissing ( arr , low , high ) ;

Index/key variables: i, x
Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
function find ( a , b , k , n1 , n2 ) { var s = new Set ( ) ; for ( var i = 0 ; i < n2 ; i ++ ) s . add ( b [ i ] ) ; var missing = 0 ; for ( var i = 0 ; i < n1 ; i ++ ) { if ( ! s . has ( a [ i ] ) ) missing ++ ; if ( missing == k ) return a [ i ] ; } return - 1 ; } var a = [ 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 15 ] ; var b = [ 4 , 10 , 6 , 8 , 12 ] ; var n1 = a . length ; var n2 = b . length ; var k = 3 ; document . write ( find ( a , b , k , n1 , n2 ) ) ;

Index/key variables: i
Accumulator variables: i, missing
Iterator variables: i
Javascript program:
function findString ( S , N ) { let amounts = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { amounts [ i ] = 0 ; } for ( let i = 0 ; i < S . length ; i ++ ) { amounts [ S [ i ] . charCodeAt ( 0 ) - 97 ] ++ ; } let count = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( amounts [ i ] > 0 ) count ++ ; } if ( count > N ) { document . write ( " " ) ; } else { let ans = " " ; let high = 100001 ; let low = 0 ; let mid , total ; while ( high - low > 1 ) { total = 0 ; mid = Math . floor ( ( high + low ) / 2 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( amounts [ i ] > 0 ) { total += Math . floor ( ( amounts [ i ] - 1 ) / mid + 1 ) ; } } if ( total <= N ) { high = mid ; } else { low = mid ; } } document . write ( high + " " ) ; total = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( amounts [ i ] > 0 ) { total += Math . floor ( ( amounts [ i ] - 1 ) / high + 1 ) ; for ( let j = 0 ; j < Math . floor ( ( amounts [ i ] - 1 ) / high + 1 ) ; j ++ ) { ans += String . fromCharCode ( i + 97 ) ; } } } for ( let i = total ; i < N ; i ++ ) { ans += " " ; } ans = ans . split ( " " ) . reverse ( ) . join ( " " ) ; document . write ( ans ) ; } } let S = " " ; let K = 4 ; findString ( S , K ) ;

Index/key variables: i
Accumulator variables: ans, count, i, j, total
Iterator variables: i, j
Javascript program:
function printFirstRepeating ( arr ) { let min = - 1 ; let set = new Set ( ) ; for ( let i = arr . length - 1 ; i >= 0 ; i -- ) { if ( set . has ( arr [ i ] ) ) min = i ; else set . add ( arr [ i ] ) ; } if ( min != - 1 ) document . write ( " " + arr [ min ] ) ; else document . write ( " " ) ; } let arr = [ 10 , 5 , 3 , 4 , 3 , 5 , 6 ] ; printFirstRepeating ( arr ) ;

Index/key variables: i, min
Accumulator variables: i
Iterator variables: i
Javascript program:
function printFirstRepeating ( arr , n ) { var k = 0 ; var max = n ; for ( i = 0 ; i < n ; i ++ ) if ( max < arr [ i ] ) max = arr [ i ] ; var a = Array ( max + 1 ) . fill ( 0 ) ; var b = Array ( max + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ arr [ i ] ] != 0 ) { b [ arr [ i ] ] = 1 ; k = 1 ; continue ; } else a [ arr [ i ] ] = i ; } if ( k == 0 ) document . write ( " " ) ; else { var min = max + 1 ; for ( i = 0 ; i < max + 1 ; i ++ ) if ( a [ i ] != 0 && min > a [ i ] && b [ i ] != 0 ) min = a [ i ] ; document . write ( arr [ min ] ) ; } document . write ( " " ) ; } var arr = [ 10 , 5 , 3 , 4 , 3 , 5 , 6 ] ; var n = arr . length ; printFirstRepeating ( arr , n ) ;

Index/key variables: i, min
Accumulator variables: i
Iterator variables: i
Javascript program:
function printKDistinct ( arr , n , k ) { var dist_count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var j ; for ( j = 0 ; j < n ; j ++ ) if ( i != j && arr [ j ] == arr [ i ] ) break ; if ( j == n ) dist_count ++ ; if ( dist_count == k ) return arr [ i ] ; } return - 1 ; } var ar = [ 1 , 2 , 1 , 3 , 4 , 2 ] ; var n = ar . length ; var k = 2 ; document . write ( printKDistinct ( ar , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: dist_count, i, j
Iterator variables: i, j
Javascript program:
function countSubarrays ( A , N ) { var res = 0 ; var curr = A [ 0 ] ; var cnt = [ ] ; cnt . fill ( 1 ) for ( var c = 1 ; c < N ; c ++ ) { if ( A == curr ) cnt [ cnt . length - 1 ] ++ ; else curr = A ; cnt . push ( 1 ) ; } for ( var i = 1 ; i < cnt . length ; i ++ ) { res += Math . min ( cnt [ i - 1 ] , cnt [ i ] ) ; } document . write ( res ) ; } var A = [ 1 , 1 , 0 , 0 , 1 , 0 ] ; var N = A . length ; countSubarrays ( A , N ) ;

Index/key variables: i
Accumulator variables: c, i, res
Iterator variables: c, i
Javascript program:
class Node { constructor ( data ) { this . left = null ; this . right = null ; this . val = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function isEvenOddBinaryTree ( root ) { if ( root == null ) return true ; let q = [ ] ; q . push ( root ) ; let level = 0 ; while ( q . length > 0 ) { let size = q . length ; for ( let i = 0 ; i < size ; i ++ ) { let node = q [ 0 ] ; q . shift ( ) ; if ( level % 2 == 0 ) { if ( node . val % 2 == 1 ) return false ; } else if ( level % 2 == 1 ) { if ( node . val % 2 == 0 ) return false ; } if ( node . left != null ) { q . push ( node . left ) ; } if ( node . right != null ) { q . push ( node . right ) ; } } level ++ ; } return true ; } let root = null ; root = newNode ( 2 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 9 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 10 ) ; root . right . right = newNode ( 6 ) ; if ( isEvenOddBinaryTree ( root ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: i, level
Iterator variables: i
Class/struct names: Node
Javascript program:
function findMaxLen ( a ) { var n = a . length ; var freq = Array ( n + 1 ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < n ; ++ i ) { freq [ a [ i ] ] ++ ; } var maxFreqElement = - 2147483648 ; var maxFreqCount = 1 ; for ( i = 1 ; i <= n ; ++ i ) { if ( freq [ i ] > maxFreqElement ) { maxFreqElement = freq [ i ] ; maxFreqCount = 1 ; } else if ( freq [ i ] == maxFreqElement ) maxFreqCount ++ ; } var ans ; if ( maxFreqElement == 1 ) ans = 0 ; else { ans = ( ( n - maxFreqCount ) / ( maxFreqElement - 1 ) ) ; } return ans ; } var a = [ 1 , 2 , 1 , 2 ] ; document . write ( findMaxLen ( a ) ) ;

Index/key variables: i
Accumulator variables: maxFreqCount
Iterator variables: i
Javascript program:
function getMid ( s , e ) { return ( s + Math . floor ( ( e - s ) / 2 ) ) ; } function MaxUtil ( st , ss , se , l , r , node ) { if ( l <= ss && r >= se ) return st [ node ] ; if ( se < l ss > r ) return - 1 ; let mid = getMid ( ss , se ) ; return Math . max ( MaxUtil ( st , ss , mid , l , r , 2 * node + 1 ) , MaxUtil ( st , mid + 1 , se , l , r , 2 * node + 2 ) ) ; } function getMax ( st , n , l , r ) { if ( l < 0 r > n - 1 l > r ) { document . write ( " " ) ; return - 1 ; } return MaxUtil ( st , 0 , n - 1 , l , r , 0 ) ; } function constructSTUtil ( arr , ss , se , st , si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return arr [ ss ] ; } let mid = getMid ( ss , se ) ; st [ si ] = Math . max ( constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) , constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ) ; return st [ si ] ; } function constructST ( arr , n ) { let x = ( Math . ceil ( Math . log ( n ) ) ) ; let max_size = 2 * Math . pow ( 2 , x ) - 1 ; let st = Array . from ( { length : max_size } , ( _ , i ) => 0 ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } let arr = [ 5 , 2 , 3 , 0 ] ; let n = arr . length ; let st = constructST ( arr , n ) ; let Q = [ [ 1 , 3 ] , [ 0 , 2 ] ] ; for ( let i = 0 ; i < Q . length ; i ++ ) { let max = getMax ( st , n , Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; let ok = 0 ; for ( let j = 30 ; j >= 0 ; j -- ) { if ( ( max & ( 1 << j ) ) != 0 ) ok = 1 ; if ( ok <= 0 ) continue ; max |= ( 1 << j ) ; } document . write ( max + " " ) ; }

Index/key variables: i, node, si, ss
Accumulator variables: i, j, max
Iterator variables: i, j
Javascript program:
function calculate ( a , n ) { a . sort ( ) ; let count = 1 ; let answer = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] == a [ i - 1 ] ) { count += 1 ; } else { answer = answer + Math . floor ( ( count * ( count - 1 ) ) / 2 ) ; count = 1 ; } } answer = answer + Math . floor ( ( count * ( count - 1 ) ) / 2 ) ; return answer ; } let a = [ 1 , 2 , 1 , 2 , 4 ] ; let n = a . length ; document . write ( calculate ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function calculate ( a , n ) { let maximum = Math . max ( ... a ) ; let frequency = new Array ( maximum + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { frequency [ a [ i ] ] += 1 ; } let answer = 0 ; for ( let i = 0 ; i < maximum + 1 ; i ++ ) { answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ; } return parseInt ( answer / 2 ) ; } let a = [ 1 , 2 , 1 , 2 , 4 ] ; let n = a . length ; document . write ( calculate ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSubArray ( arr , n ) { let sum = 0 ; let maxsize = - 1 , startindex = 0 ; let endindex = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { sum = ( arr [ i ] == 0 ) ? - 1 : 1 ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] == 0 ) sum += - 1 ; else sum += 1 ; if ( sum == 0 && maxsize < j - i + 1 ) { maxsize = j - i + 1 ; startindex = i ; } } } endindex = startindex + maxsize - 1 ; if ( maxsize == - 1 ) document . write ( " " ) ; else document . write ( startindex + " " + endindex ) ; return maxsize ; } let arr = [ 1 , 0 , 0 , 1 , 0 , 1 , 1 ] ; let size = arr . length ; findSubArray ( arr , size ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findMax ( arr , low , high ) { if ( high == low ) return arr [ low ] ; let mid = low + ( high - low ) / 2 ; if ( mid == 0 && arr [ mid ] > arr [ mid + 1 ] ) { return arr [ mid ] ; } if ( mid < high && arr [ mid + 1 ] < arr [ mid ] && mid > 0 && arr [ mid ] > arr [ mid - 1 ] ) { return arr [ mid ] ; } if ( arr [ low ] > arr [ mid ] ) { return findMax ( arr , low , mid - 1 ) ; } else { return findMax ( arr , mid + 1 , high ) ; } } let arr = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; let n = arr . length ; document . write ( findMax ( arr , 0 , n - 1 ) ) ;

Index/key variables: low, mid
Javascript program:
function ternarySearch ( l , r , key , ar ) { while ( r >= l ) { let mid1 = l + parseInt ( ( r - l ) / 3 , 10 ) ; let mid2 = r - parseInt ( ( r - l ) / 3 , 10 ) ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { r = mid1 - 1 ; } else if ( key > ar [ mid2 ] ) { l = mid2 + 1 ; } else { l = mid1 + 1 ; r = mid2 - 1 ; } } return - 1 ; } let l , r , p , key ; let ar = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; document . write ( " " + key + " " + p + " " ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; document . write ( " " + key + " " + p ) ;

Index/key variables: mid1, mid2
Javascript program:
function majorityNumber ( arr , n ) { let ans = - 1 ; let freq = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) } else { freq . set ( arr [ i ] , 1 ) } if ( freq . get ( arr [ i ] ) > n / 2 ) ans = arr [ i ] ; } return ans ; } let a = [ 2 , 2 , 1 , 1 , 1 , 2 , 2 ] ; let n = a . length ; document . write ( majorityNumber ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function search ( arr , l , h , key ) { if ( l > h ) return - 1 ; let mid = Math . floor ( ( l + h ) / 2 ) ; if ( arr [ mid ] == key ) return mid ; if ( arr [ l ] <= arr [ mid ] ) { if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ; return search ( arr , mid + 1 , h , key ) ; } if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ; return search ( arr , l , mid - 1 , key ) ; } let arr = [ 4 , 5 , 6 , 7 , 8 , 9 , 1 , 2 , 3 ] ; let n = arr . length ; let key = 6 ; let i = search ( arr , 0 , n - 1 , key ) ; if ( i != - 1 ) document . write ( " " + i + " " ) ; else document . write ( " " ) ;

Index/key variables: h, l, mid
Javascript program:
function findMin ( arr , low , high ) { if ( high < low ) return arr [ 0 ] ; if ( high == low ) return arr [ low ] ; let mid = low + Math . floor ( ( high - low ) / 2 ) ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ; if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ; if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ; return findMin ( arr , mid + 1 , high ) ; } let arr1 = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; let n1 = arr1 . length ; document . write ( " " + findMin ( arr1 , 0 , n1 - 1 ) + " " ) ; let arr2 = [ 1 , 2 , 3 , 4 ] ; let n2 = arr2 . length ; document . write ( " " + findMin ( arr2 , 0 , n2 - 1 ) + " " ) ; let arr3 = [ 1 ] ; let n3 = arr3 . length ; document . write ( " " + findMin ( arr3 , 0 , n3 - 1 ) + " " ) ; let arr4 = [ 1 , 2 ] ; let n4 = arr4 . length ; document . write ( " " + findMin ( arr4 , 0 , n4 - 1 ) + " " ) ; let arr5 = [ 2 , 1 ] ; let n5 = arr5 . length ; document . write ( " " + findMin ( arr5 , 0 , n5 - 1 ) + " " ) ; let arr6 = [ 5 , 6 , 7 , 1 , 2 , 3 , 4 ] ; let n6 = arr6 . length ; document . write ( " " + findMin ( arr6 , 0 , n6 - 1 ) + " " ) ; let arr7 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; let n7 = arr7 . length ; document . write ( " " + findMin ( arr7 , 0 , n7 - 1 ) + " " ) ; let arr8 = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 ] ; let n8 = arr8 . length ; document . write ( " " + findMin ( arr8 , 0 , n8 - 1 ) + " " ) ; let arr9 = [ 3 , 4 , 5 , 1 , 2 ] ; let n9 = arr9 . length ; document . write ( " " + findMin ( arr9 , 0 , n9 - 1 ) + " " ) ;

Index/key variables: high, low, mid
Javascript program:
function findMin ( arr , low , high ) { while ( low < high ) { let mid = Math . floor ( low + ( high - low ) / 2 ) ; if ( arr [ mid ] == arr [ high ] ) high -- ; else if ( arr [ mid ] > arr [ high ] ) low = mid + 1 ; else high = mid ; } return arr [ high ] ; } var arr1 = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; var n1 = arr1 . length ; document . write ( " " + findMin ( arr1 , 0 , n1 - 1 ) + " " ) ; var arr2 = [ 1 , 2 , 3 , 4 ] ; var n2 = arr2 . length ; document . write ( " " + findMin ( arr2 , 0 , n2 - 1 ) + " " ) ; var arr3 = [ 1 ] ; var n3 = arr3 . length ; document . write ( " " + findMin ( arr3 , 0 , n3 - 1 ) + " " ) ; var arr4 = [ 1 , 2 ] ; var n4 = arr4 . length ; document . write ( " " + findMin ( arr4 , 0 , n4 - 1 ) + " " ) ; var arr5 = [ 2 , 1 ] ; var n5 = arr5 . length ; document . write ( " " + findMin ( arr5 , 0 , n5 - 1 ) + " " ) ; var arr6 = [ 5 , 6 , 7 , 1 , 2 , 3 , 4 ] ; var n6 = arr6 . length ; document . write ( " " + findMin ( arr6 , 0 , n6 - 1 ) + " " ) ; var arr7 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; var n7 = arr7 . length ; document . write ( " " + findMin ( arr7 , 0 , n7 - 1 ) + " " ) ; var arr8 = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 ] ; var n8 = arr8 . length ; document . write ( " " + findMin ( arr8 , 0 , n8 - 1 ) + " " ) ; var arr9 = [ 3 , 4 , 5 , 1 , 2 ] ; var n9 = arr9 . length ; document . write ( " " + findMin ( arr9 , 0 , n9 - 1 ) + " " ) ;

Index/key variables: high, mid
Accumulator variables: high
Javascript program:
function print2Smallest ( arr , arr_size ) { let i , first , second ; if ( arr_size < 2 ) { document . write ( " " ) ; return ; } first = Number . MAX_VALUE ; second = Number . MAX_VALUE ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] < first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] < second && arr [ i ] != first ) second = arr [ i ] ; } if ( second == Number . MAX_VALUE ) document . write ( " " ) ; else document . write ( " " + first + " " + " " + second + ' ' ) ; } let arr = [ 12 , 13 , 1 , 10 , 34 , 1 ] ; let n = arr . length ; print2Smallest ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const MAX = 1000 var tree = new Array ( 4 * MAX ) ; var arr = new Array ( MAX ) ; function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function lcm ( a , b ) { return Math . floor ( a * b / gcd ( a , b ) ) ; } function build ( node , start , end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } let mid = Math . floor ( ( start + end ) / 2 ) ; build ( 2 * node , start , mid ) ; build ( 2 * node + 1 , mid + 1 , end ) ; let left_lcm = tree [ 2 * node ] ; let right_lcm = tree [ 2 * node + 1 ] ; tree [ node ] = lcm ( left_lcm , right_lcm ) ; } function query ( node , start , end , l , r ) { if ( end < l start > r ) return 1 ; if ( l <= start && r >= end ) return tree [ node ] ; let mid = Math . floor ( ( start + end ) / 2 ) ; let left_lcm = query ( 2 * node , start , mid , l , r ) ; let right_lcm = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return lcm ( left_lcm , right_lcm ) ; } arr [ 0 ] = 5 ; arr [ 1 ] = 7 ; arr [ 2 ] = 5 ; arr [ 3 ] = 2 ; arr [ 4 ] = 10 ; arr [ 5 ] = 12 ; arr [ 6 ] = 11 ; arr [ 7 ] = 17 ; arr [ 8 ] = 14 ; arr [ 9 ] = 1 ; arr [ 10 ] = 44 ; build ( 1 , 0 , 10 ) ; document . write ( query ( 1 , 0 , 10 , 2 , 5 ) + " " ) ; document . write ( query ( 1 , 0 , 10 , 5 , 10 ) + " " ) ; document . write ( query ( 1 , 0 , 10 , 0 , 10 ) + " " ) ;

Index/key variables: node, start