dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Solution ( A ) { let ans = 2 ; let n = A . length ; if ( n <= 2 ) { return n ; } let llap = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { llap [ i ] = 2 ; } A . sort ( function ( a , b ) { return a - b } ) ; for ( let j = n - 2 ; j >= 0 ; j -- ) { let i = j - 1 ; let k = j + 1 ; while ( i >= 0 && k < n ) { if ( A [ i ] + A [ k ] == ( 2 * A [ j ] ) ) { llap [ j ] = Math . max ( ( llap [ k ] + 1 ) , llap [ j ] ) ; ans = Math . max ( ans , llap [ j ] ) ; i -= 1 ; k += 1 ; } else if ( A [ i ] + A [ k ] < 2 * A [ j ] ) k += 1 ; else i -= 1 ; } } return ans ; } let a = [ 9 , 4 , 7 , 2 , 10 ] ; document . write ( Solution ( a ) + " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
function minumumOperation ( N , arr ) { let sum_arr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum_arr = sum_arr + arr [ i ] ; } if ( sum_arr >= N ) document . write ( sum_arr - N + " " ) ; else document . write ( 1 + " " ) ; } let N = 4 ; let arr = [ 8 , 4 , 6 , 2 ] ; minumumOperation ( N , arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
< ! -- Javascript program for the above approach -- > function Substr ( s2 , s1 ) { var i = 0 ; for ( ; i < s1 . length ; i ++ ) { if ( counter == s2 . length ) { break ; } if ( s2 [ counter ] == s1 [ i ] ) { counter ++ ; } else { if ( counter > 0 ) { i -= counter ; } counter = 0 ; } } return counter < s2 . length ? - 1 : i - counter ; } var s1 = " " ; document . write ( Substr ( " " , s1 ) ) ; < ! -- this code is contributed by Nirajgusain5 -- >

Index/key variables: counter, i
Accumulator variables: Nirajgusain5, approach, counter, i
Javascript program:
function countSmaller ( str ) { var n = str . length ; var arr = Array ( 26 ) . fill ( 0 ) ; var ans = Array ( n ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { arr [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var ct = 0 ; for ( var j = 0 ; j < str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; j ++ ) { ct += arr [ j ] ; } ans [ i ] = ct ; } for ( var i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } var str = " " ; countSmaller ( str ) ;

Index/key variables: i, j
Accumulator variables: ct, i, j
Iterator variables: i, j
Javascript program:
function isFrequencyEqual ( str , len ) { if ( len % 2 == 1 ) return false ; var i , freq = Array ( 26 ) . fill ( 0 ) ; for ( i = 0 ; i < len ; i ++ ) freq [ str [ i ] - ' ' ] ++ ; for ( i = 0 ; i < 26 ; i ++ ) if ( freq [ i ] == parseInt ( len / 2 ) ) return true ; return false ; } var str = " " ; var len = str . length ; if ( isFrequencyEqual ( str , len ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countMinimalReplacements ( s ) { var n = s . length ; var cnt = 0 ; var str = " " ; for ( var i = 1 ; i < n ; i ++ ) { if ( s [ i ] === s [ i - 1 ] ) { cnt += 1 ; if ( i !== n - 1 ) { for ( var it = 0 ; it < str . length ; it ++ ) { if ( str [ it ] !== s [ i + 1 ] && str [ it ] !== s [ i - 1 ] ) { s [ i ] = str [ it ] ; break ; } } else { for ( var it = 0 ; it < str . length ; it ++ ) { if ( str [ it ] !== s [ i - 1 ] ) { s [ i ] = str [ it ] ; break ; } } } } } return cnt ; } var s = " " ; document . write ( countMinimalReplacements ( s ) ) ;

Index/key variables: i, it
Accumulator variables: cnt, i, it
Iterator variables: i, it
Javascript program:
function nextIndex ( str , start , c ) { for ( let i = start ; i < str . length ; i ++ ) { if ( str [ i ] == c ) return i ; } return - 1 ; } function countSubStrings ( str ) { let i , n = str . length ; let countX = new Array ( n ) ; let count = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) count ++ ; countX [ i ] = count ; } let nextIndexX = nextIndex ( str , 0 , ' ' ) ; let nextIndexY = nextIndex ( str , 0 , ' ' ) ; count = 0 ; while ( nextIndexX != - 1 && nextIndexY != - 1 ) { if ( nextIndexX > nextIndexY ) { nextIndexY = nextIndex ( str , nextIndexY + 1 , ' ' ) ; continue ; } else { count += countX [ nextIndexY ] ; nextIndexX = nextIndex ( str , nextIndexX + 1 , ' ' ) ; } } return count ; } let s = " " ; document . write ( countSubStrings ( s ) ) ;

Index/key variables: i, nextIndexY
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isPrime ( n ) { var i ; if ( n == 1 ) return false ; for ( i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function check_frequency ( s ) { var m = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) if ( m . has ( s [ i ] ) ) { m . set ( s [ i ] , m . get ( s [ i ] ) + 1 ) ; } else { m . set ( s [ i ] , 1 ) ; } for ( var ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) if ( m . get ( String . fromCharCode ( ch ) ) > 0 && ! isPrime ( m . get ( String . fromCharCode ( ch ) ) ) ) return false ; return true ; } var s = " " ; if ( check_frequency ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

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

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
class Pair { constructor ( c , ctr ) { this . c = c ; this . ctr = ctr ; } } function reduced_String ( k , s ) { if ( k == 1 ) { let ans = " " ; return ans ; } let st = [ ] ; let l = s . length ; let ctr = 0 ; for ( let i = 0 ; i < l ; i ++ ) { if ( st . length == 0 ) { st . push ( new Pair ( s [ i ] , 1 ) ) ; continue ; } if ( st [ st . length - 1 ] . c == s [ i ] ) { let p = st [ st . length - 1 ] ; st . pop ( ) ; p . ctr += 1 ; if ( p . ctr == k ) { continue ; } else { st . push ( p ) ; } } else { st . push ( new Pair ( s [ i ] , 1 ) ) ; } } let ans = " " ; while ( st . length > 0 ) { let c = st [ st . length - 1 ] . c ; let cnt = st [ st . length - 1 ] . ctr ; while ( cnt -- > 0 ) ans = c + ans ; st . pop ( ) ; } return ans ; } let k = 2 ; let st = " " ; let ans = reduced_String ( k , st ) ; document . write ( ans + " " ) ;

Index/key variables: i
Accumulator variables: cnt, ctr, i
Iterator variables: i
Class/struct names: Pair
Javascript program:
function firstNonRepeating ( str ) { let NO_OF_CHARS = 256 ; let arr = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) arr [ i ] = - 1 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( arr [ str [ i ] . charCodeAt ( 0 ) ] == - 1 ) arr [ str [ i ] . charCodeAt ( 0 ) ] = i ; else arr [ str [ i ] . charCodeAt ( 0 ) ] = - 2 ; } let res = Number . MAX_VALUE ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( arr [ i ] >= 0 ) res = Math . min ( res , arr [ i ] ) ; return res ; } let str = " " ; let index = firstNonRepeating ( str ) ; if ( index == Number . MAX_VALUE ) document . write ( " " + " " ) ; else document . write ( " " + " " + str [ index ] ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimize ( str ) { let mstr = " " ; let l , i , flagchar = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { flagchar [ i ] = 0 ; } let ch ; l = str . length ; for ( i = 0 ; i < str . length ; i ++ ) { ch = str [ i ] ; if ( flagchar [ ch . charCodeAt ( 0 ) - 97 ] == 0 ) { mstr = mstr + ch ; flagchar [ ch . charCodeAt ( 0 ) - 97 ] = 1 ; } } return mstr ; } function replaceMinimizeUtil ( str ) { let minimizedStr , finalStr = " " ; let i , index , l ; let ch ; l = str . length ; minimizedStr = minimize ( str ) ; for ( i = 0 ; i < minimizedStr . length ; i ++ ) { ch = minimizedStr [ i ] . charCodeAt ( 0 ) ; index = ( ch * ch ) % l ; finalStr = finalStr + str [ index ] ; } document . write ( " " + finalStr ) ; } let str = " " ; replaceMinimizeUtil ( str ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function cipher ( str ) { for ( var i = 0 ; i < str . length ; i ++ ) { if ( ! isLetter ( str [ i ] ) && str [ i ] !== " " ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= " " && str [ i ] <= " " ) { document . write ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 + " " ) ; } else if ( str [ i ] >= " " && str [ i ] <= " " ) { document . write ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 + " " ) ; } if ( str [ i ] == " " ) document . write ( str [ i ] ) ; } document . write ( " " ) ; } function isLetter ( str ) { return str . length === 1 && str . match ( / [a-z] / i ) ; } var str = " " ; cipher ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkPalin ( word ) { var n = word . length word = word . toLowerCase ( ) ; for ( var i = 0 ; i < n ; i ++ , n -- ) if ( word [ i ] != word [ n - 1 ] ) return false ; return true ; } function countPalin ( str ) { str = str + " " ; var word = " " ; var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { var ch = str [ i ] ; if ( ch != ' ' ) word = word + ch ; else { if ( checkPalin ( word ) ) count ++ ; word = " " ; } } return count ; } document . write ( countPalin ( " " ) + " " ) ; document . write ( countPalin ( " " ) ) ;

Index/key variables: i
Accumulator variables: count, i, n
Iterator variables: i
Javascript program:
function countOccurrences ( s , K ) { let n = s . length ; let C = 0 , c1 = 0 , c2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) c1 ++ ; if ( s [ i ] == ' ' ) { c2 ++ ; C += c1 ; } } return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ; } let S = " " ; let k = 2 ; document . write ( countOccurrences ( S , k ) ) ;

Index/key variables: i
Accumulator variables: C, c1, c2, i
Iterator variables: i
Javascript program:
function findString ( n , k ) { let res = " " ; for ( let i = 0 ; i < k ; i ++ ) res = res + String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; let count = 0 ; for ( let i = 0 ; i < n - k ; i ++ ) { res = res + String . fromCharCode ( ' ' . charCodeAt ( 0 ) + count ) ; count ++ ; if ( count == k ) count = 0 ; } return res ; } let n = 5 , k = 2 ; document . write ( findString ( n , k ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isVowel ( x ) { return ( x == ' ' x == ' ' x == ' ' x == ' ' x == ' ' ) ; } function findSubstring ( str ) { let hash = new Set ( ) ; let start = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( isVowel ( str [ i ] ) == true ) { hash . add ( str [ i ] ) ; if ( hash . size == 5 ) document . write ( str . substring ( start , i + 1 ) + " " ) ; } else { start = i + 1 ; hash . clear ( ) ; } } } let str = " " ; findSubstring ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function decode ( str ) { let res = " " ; let found = false ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { found = false ; continue ; } if ( ! found ) { if ( ( str [ i ] >= ' ' && str [ i ] <= ' ' ) || ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ) { res += ( str [ i ] ) ; found = true ; } } } return res . toLowerCase ( ) ; } let In = " " ; document . write ( " " + decode ( In ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Boolean variables: found
Javascript program:
function printRotatedString ( str ) { var n = str . length ; var sb = str ; sb += ( str ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j != n ; j ++ ) document . write ( sb . charAt ( i + j ) ) ; document . write ( ' ' ) ; } } var str = " " ; printRotatedString ( str ) ;

Accumulator variables: i, j, sb
Iterator variables: i, j
Javascript program:
let M = 26 ; function getIdx ( ch ) { return ( ch - ' ' ) ; } function allSame ( freq , N ) { let same = 0 ; let i ; for ( i = 0 ; i < N ; i ++ ) { if ( freq [ i ] > 0 ) { same = freq [ i ] ; break ; } } for ( let j = i + 1 ; j < N ; j ++ ) if ( freq [ j ] > 0 && freq [ j ] != same ) return false ; return true ; } function possibleSameCharFreqByOneRemoval ( str ) { let l = str . length ; let freq = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < l ; i ++ ) freq [ getIdx ( str [ i ] ) ] ++ ; if ( allSame ( freq , M ) ) return true ; for ( let c = ' ' ; c <= ' ' ; c ++ ) { let i = getIdx ( c ) ; if ( freq [ i ] > 0 ) { freq [ i ] -- ; if ( allSame ( freq , M ) ) return true ; freq [ i ] ++ ; } } return false ; } let str = " " ; if ( possibleSameCharFreqByOneRemoval ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: c, i, j
Javascript program:
function check ( str ) { let n = str . length ; let oddDigSum = 0 , evenDigSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - ' ' ) ; else evenDigSum += ( str [ i ] - ' ' ) ; } return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ; } let str = " " ; if ( check ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: evenDigSum, i, oddDigSum
Iterator variables: i
Javascript program:
function hammingDist ( str1 , str2 ) { let i = 0 , count = 0 ; while ( i < str1 . length ) { if ( str1 [ i ] != str2 [ i ] ) count ++ ; i ++ ; } return count ; } let str1 = " " ; let str2 = " " ; document . write ( hammingDist ( str1 , str2 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Javascript program:
let MAX_CHAR = 26 ; function arekAnagrams ( str1 , str2 , k ) { let n = str1 . length ; if ( str2 . length != n ) return false ; let count1 = new Array ( MAX_CHAR ) ; let count2 = new Array ( MAX_CHAR ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) count1 [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < n ; i ++ ) count2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] > count2 [ i ] ) count = count + Math . abs ( count1 [ i ] - count2 [ i ] ) ; return ( count <= k ) ; } let str1 = " " ; let str2 = " " ; let k = 2 ; if ( arekAnagrams ( str1 , str2 , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function removeSpaces ( str ) { var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) if ( str [ i ] !== " " ) str [ count ++ ] = str [ i ] ; return count ; } var str = " " . split ( " " ) ; var i = removeSpaces ( str ) ; document . write ( str . join ( " " ) . substring ( 0 , i ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countSubStr ( str , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) m ++ ; } return m * Math . floor ( ( m - 1 ) / 2 ) ; } let str = " " ; let n = str . length ; document . write ( countSubStr ( str , n ) ) ;

Index/key variables: i
Accumulator variables: i, m
Iterator variables: i
Javascript program:
function count9s ( number ) { let count = 0 ; let n = ( number . length ) ; for ( let i = 0 ; i < n ; i ++ ) { let sum = number [ i ] - ' ' ; if ( number [ i ] == ' ' ) { count ++ ; } for ( let j = i + 1 ; j < n ; j ++ ) { sum = ( sum + number [ j ] - ' ' ) % 9 ; if ( sum == 0 ) { count ++ ; } } } return count ; } document . write ( count9s ( " " ) ) ; document . write ( " " ) ; document . write ( count9s ( " " ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function generateGrayarr ( n ) { if ( n <= 0 ) return ; let arr = [ ] ; arr . push ( " " ) ; arr . push ( " " ) ; let i , j ; for ( i = 2 ; i < ( 1 << n ) ; i = i << 1 ) { for ( j = i - 1 ; j >= 0 ; j -- ) arr . push ( arr [ j ] ) ; for ( j = 0 ; j < i ; j ++ ) arr [ j ] = " " + arr [ j ] ; for ( j = i ; j < 2 * i ; j ++ ) arr [ j ] = " " + arr [ j ] ; } for ( i = 0 ; i < arr . length ; i ++ ) document . write ( arr [ i ] + " " ) ; } generateGrayarr ( 3 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let possiblePaths = [ ] ; let path = " " ; let MAX = 5 ; function isSafe ( row , col , m , n , visited ) { if ( row == - 1 row == n col == - 1 col == n visited [ row ] [ col ] m [ row ] [ col ] == 0 ) return false ; return true ; } function printPathUtil ( row , col , m , n , visited ) { if ( row == - 1 row == n col == - 1 col == n visited [ row ] [ col ] m [ row ] [ col ] == 0 ) return ; if ( row == n - 1 && col == n - 1 ) { possiblePaths . push ( path ) ; return ; } visited [ row ] [ col ] = true ; if ( isSafe ( row + 1 , col , m , n , visited ) ) { path += ' ' ; printPathUtil ( row + 1 , col , m , n , visited ) ; path = path . substring ( 0 , path . length - 1 ) ; } if ( isSafe ( row , col - 1 , m , n , visited ) ) { path += ' ' ; printPathUtil ( row , col - 1 , m , n , visited ) ; path = path . substring ( 0 , path . length - 1 ) ; } if ( isSafe ( row , col + 1 , m , n , visited ) ) { path += ' ' ; printPathUtil ( row , col + 1 , m , n , visited ) ; path = path . substring ( 0 , path . length - 1 ) ; } if ( isSafe ( row - 1 , col , m , n , visited ) ) { path += ' ' ; printPathUtil ( row - 1 , col , m , n , visited ) ; path = path . substring ( 0 , path . length - 1 ) ; } visited [ row ] [ col ] = false ; } function printPath ( m , n ) { let visited = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { visited [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) visited [ i ] [ j ] = false ; } printPathUtil ( 0 , 0 , m , n , visited ) ; for ( let i = 0 ; i < possiblePaths . length ; i ++ ) document . write ( possiblePaths [ i ] + " " ) ; } let m = [ [ 1 , 0 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 0 , 1 ] ] ; let n = m . length ; printPath ( m , n ) ;

Index/key variables: col, i, j, row
Accumulator variables: i, j, path
Iterator variables: i, j
Javascript program:
function breakLine ( ) { document . write ( " " ) ; document . write ( " " ) ; document . write ( " " ) ; } let MAX = 10 ; let arr = [ ] ; let no = 0 ; function nQueens ( k , n ) { for ( let i = 1 ; i <= n ; i ++ ) { if ( canPlace ( k , i ) ) { arr [ k ] = i ; if ( k == n ) { display ( n ) ; } else { nQueens ( k + 1 , n ) ; } } } } function canPlace ( k , i ) { for ( let j = 1 ; j <= k - 1 ; j ++ ) { if ( arr [ j ] == i || ( Math . abs ( arr [ j ] - i ) == Math . abs ( j - k ) ) ) { return false ; } } return true ; } function display ( n ) { breakLine ( ) ; document . write ( " " + ++ no ) ; breakLine ( ) ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( arr [ i ] != j ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } document . write ( " " ) ; } breakLine ( ) ; } let n = 4 ; nQueens ( 1 , n ) ;

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minStepsRecur ( height , l , r , h ) { if ( l >= r ) return 0 ; let m = l ; for ( let i = l ; i < r ; i ++ ) if ( height [ i ] < height [ m ] ) m = i ; return Math . min ( r - l , minStepsRecur ( height , l , m , height [ m ] ) + minStepsRecur ( height , m + 1 , r , height [ m ] ) + height [ m ] - h ) ; } function minSteps ( height , N ) { return minStepsRecur ( height , 0 , N , 0 ) ; } let height = [ 2 , 1 , 2 , 5 , 1 ] ; let N = height . length ; document . write ( minSteps ( height , N ) ) ;

Index/key variables: i, m
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSegment ( n , m , segment_length ) { let meet_point = ( 1.0 * n ) / 2.0 ; let sum = 0 ; let segment_number = 0 , i ; for ( i = 0 ; i < m ; i ++ ) { sum += segment_length [ i ] ; if ( sum == meet_point ) { segment_number = - 1 ; break ; } if ( sum > meet_point ) { segment_number = i + 1 ; break ; } } return segment_number ; } let n = 13 ; let m = 3 ; let segment_length = [ 3 , 2 , 8 ] ; let ans = findSegment ( n , m , segment_length ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countLattice ( r ) { if ( r <= 0 ) return 0 ; var result = 4 ; for ( x = 1 ; x < r ; x ++ ) { var ySquare = r * r - x * x ; var y = parseInt ( Math . sqrt ( ySquare ) ) ; if ( y * y == ySquare ) result += 4 ; } return result ; } var r = 5 ; document . write ( countLattice ( r ) ) ;

Accumulator variables: result, x
Iterator variables: x
Javascript program:
function countSubArrays ( arr , N , K , M ) { let count = 0 ; let sum = 0 ; for ( let i = 0 ; i < K ; i ++ ) { sum += arr [ i ] ; } if ( sum >= K * M ) count ++ ; for ( let i = K ; i < N ; i ++ ) { sum += ( arr [ i ] - arr [ i - K ] ) ; if ( sum >= K * M ) count ++ ; } return count ; } let arr = [ 3 , 6 , 3 , 2 , 1 , 3 , 9 ] ; let K = 2 , M = 4 ; let N = arr . length ; document . write ( countSubArrays ( arr , N , K , M ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function performQueries ( n , q , k , arr , query ) { = for ( let i = 1 ; i <= q ; i ++ ) { let count = 0 ; if ( query [ i - 1 ] [ 0 ] == 1 ) { for ( let j = query [ i - 1 ] [ 1 ] ; j <= query [ i - 1 ] [ 2 ] ; j ++ ) { if ( arr [ j ] == k ) count ++ ; } document . write ( count + " " ) ; } else { arr [ query [ i - 1 ] [ 1 ] ] = query [ i - 1 ] [ 2 ] ; } } } let arr = [ 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 ] ; let Q = 5 ; let query = [ [ 1 , 5 , 14 ] , [ 2 , 6 , 1 ] , [ 1 , 0 , 8 ] , [ 2 , 13 , 0 ] , [ 1 , 6 , 18 ] , ] ; let N = arr . length ; let K = 0 ; performQueries ( N , Q , K , arr , query ) ;

Index/key variables: j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function findSmallestNumK ( n ) { let cummAnd = n ; let i = n - 1 ; while ( cummAnd != 0 ) { cummAnd = cummAnd & i ; if ( cummAnd == 0 ) { return i ; } i -- ; } return - 1 ; } let N = 17 ; let lastNum = findSmallestNumK ( N ) ; let K = lastNum == - 1 ? lastNum : N - lastNum ; document . write ( K + " " ) ;

Accumulator variables: i
Javascript program:
function fact ( n ) { if ( n == 1 n == 0 ) return 1 ; else return n * fact ( n - 1 ) ; } function findValue ( n , r , a ) { let k = ( a - 1 ) / fact ( n ) ; let answer = k ; for ( let i = 1 ; i < n + 1 ; i ++ ) answer = answer * ( n + r - i ) ; answer = answer + 1 ; return answer ; } let N = 1 ; let A = 2 ; let R = 3 ; document . write ( findValue ( N , R , A ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function compute ( query ) { var v = Array ( 100001 ) . fill ( 0 ) ; var dp = Array ( 100001 ) . fill ( 0 ) ; v [ 1 ] = 1 , v [ 2 ] = 0 ; dp [ 1 ] = 0 , dp [ 2 ] = 0 ; for ( var i = 3 ; i < 100001 ; i ++ ) { if ( i % 2 != 0 ) { if ( parseInt ( i / 2 ) % 2 == 0 ) { v [ i ] = 1 ; dp [ i ] = dp [ i - 1 ] ; } else { v [ i ] = v [ parseInt ( i / 2 ) ] + 1 ; dp [ i ] = dp [ i - 1 ] + v [ i ] - 1 ; } } else { v [ i ] = 0 ; dp [ i ] = dp [ i - 1 ] ; } } query . forEach ( x => { document . write ( dp [ x ] + " " ) ; } ) ; } var query = [ 5 , 2 ] ; compute ( query ) ;

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i
Javascript program:
function find ( a , n , k ) { var v = [ ] ; for ( i = 1 ; i < n ; ++ i ) { v . push ( a [ i - 1 ] - a [ i ] ) ; } v . sort ( ( a , b ) => a - b ) ; var res = a [ n - 1 ] - a [ 0 ] ; for ( i = 0 ; i < k - 1 ; ++ i ) { res += v [ i ] ; } return res ; } var arr = [ 4 , 8 , 15 , 16 , 23 , 42 ] ; var N = arr . length ; var K = 3 ; document . write ( find ( arr , N , K ) + " " ) ;

Index/key variables: i
Accumulator variables: res
Iterator variables: i