dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function lexicographicRank ( s ) { var n = s . length ; var alphaIndex = Array . from ( Array ( 26 ) , ( ) => new Array ( ) ) ; for ( var i = 0 ; i < s . length ; i ++ ) { var x = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; alphaIndex [ x ] . push ( i ) ; } var rank = 0 ; for ( var i = 0 ; i < 26 && ' ' . charCodeAt ( 0 ) + i < s [ 0 ] . charCodeAt ( 0 ) ; i ++ ) { if ( alphaIndex [ i ] . length > 0 ) { for ( var j = 0 ; j < alphaIndex [ i ] . length ; j ++ ) { rank = rank + ( n - alphaIndex [ i ] [ j ] ) ; } } } var str = [ ] ; for ( var i = 0 ; i < alphaIndex [ s [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] . length ; i ++ ) { var substring = " " ; var j = alphaIndex [ s [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] [ i ] ; for ( ; j < n ; j ++ ) { substring += ( s [ j ] ) ; str . push ( substring ) ; } } str . sort ( ) ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] != s ) { rank ++ ; } else { break ; } } return rank + 1 ; } var str = " " ; document . write ( lexicographicRank ( str ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, j, rank, substring
Iterator variables: i, j
Javascript program:
function hIndex ( citations , n ) { let hindex = 0 ; let low = 0 , high = n - 1 ; while ( low <= high ) { let mid = ( low + high ) / 2 ; if ( citations [ mid ] >= ( mid + 1 ) ) { low = mid + 1 ; hindex = mid + 1 ; } else { high = mid - 1 ; } } document . write ( hindex ) ; return hindex ; } let n = 5 ; let citations = [ 5 , 3 , 3 , 2 , 2 ] ; hIndex ( citations , n )

Index/key variables: mid
Javascript program:
function checkEqual ( arr , N ) { var hash = Array ( 256 ) . fill ( 0 ) ; var M = arr [ 0 ] . length ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] ] ++ ; } } for ( var i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } var arr = [ " " , " " ] ; var N = arr . length ; if ( checkEqual ( arr , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp = [ ] ; for ( let i = 0 ; i < 100 ; i ++ ) { dp [ i ] = [ ] ; for ( let j = 0 ; j < 100 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } function maxweight ( s , e , pre ) { if ( s == e ) return 0 ; if ( dp [ s ] [ e ] != - 1 ) return dp [ s ] [ e ] ; let ans = 0 ; for ( let i = s ; i < e ; i ++ ) { let left = pre [ i ] - pre [ s - 1 ] ; let right = pre [ e ] - pre [ i ] ; if ( left < right ) ans = Math . max ( ans , Number ( left + maxweight ( s , i , pre ) ) ) ; if ( left == right ) ans = Math . max ( ans , Math . max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; if ( left > right ) ans = Math . max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; dp [ s ] [ e ] = ans ; } return dp [ s ] [ e ] ; } function maxSum ( arr , n ) { let pre = new Map ( ) ; pre [ - 1 ] = 0 ; pre [ 0 ] = arr [ 0 ] ; for ( let i = 0 ; i < 100 ; i ++ ) { for ( let j = 0 ; j < 100 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( let i = 0 ; i < n ; i ++ ) pre [ i ] = pre [ i - 1 ] + arr [ i ] ; document . write ( maxweight ( 0 , n - 1 , pre ) ) ; } let arr = [ 6 , 2 , 3 , 4 , 5 , 5 ] ; maxSum ( arr , 6 ) ;

Index/key variables: e, i, j, s
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function storeLeaf ( root , arr ) { if ( root == null ) return arr ; if ( root . left == null && root . right == null ) { arr . push ( root . data ) ; return arr ; } arr = storeLeaf ( root . left , arr ) ; arr = storeLeaf ( root . right , arr ) ; return arr ; } function KSmallest ( root , k ) { let arr = [ ] ; arr = storeLeaf ( root , arr ) ; arr . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < k ; i ++ ) { if ( i < arr . length ) { document . write ( arr [ i ] + " " ) ; } else { break ; } } } let root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . left . left = newNode ( 21 ) ; root . left . right = newNode ( 5 ) ; root . left . right . right = newNode ( 8 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 19 ) ; KSmallest ( root , 3 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function gcd ( a , b ) { if ( ! b ) { return a ; } return gcd ( b , a % b ) ; } function allCoprime ( A , n ) { var all_coprime = true ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( gcd ( A [ i ] , A [ j ] ) != 1 ) { all_coprime = false ; break ; } } } return all_coprime ; } var A = [ 3 , 5 , 11 , 7 , 19 ] ; var arr_size = A . length ; if ( allCoprime ( A , arr_size ) ) { console . log ( " " ) ; } else { console . log ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: all_coprime
Javascript program:
function findString ( s , k ) { var n = s . length ; var ans = " " ; var st = [ ] ; var vis = new Array ( n ) ; List < bool > vis ( n , false ) ; var count = 0 ; for ( var i = 0 ; i < n ; ++ i ) { if ( s [ i ] === " " ) { st . push ( i ) ; } if ( count < k && s [ i ] === " " ) { vis [ st [ st . length - 1 ] ] = true ; st . pop ( ) ; vis [ i ] = true ; count += 2 ; } } for ( var i = 0 ; i < n ; ++ i ) { if ( vis [ i ] === true ) { ans += s [ i ] ; } } return ans ; } var s = " " ; var K = 2 ; document . write ( findString ( s , K ) ) ;

Index/key variables: i
Accumulator variables: ans, count
Iterator variables: i
Javascript program:
let mp = new Map ( ) ; let max_v , rootIndex ; class Node { constructor ( key ) { this . left = null ; this . right = null ; this . key = key ; } } function newNode ( key ) { let temp = new Node ( key ) ; return ( temp ) ; } function findNodes ( root ) { if ( root == null ) { return [ ] ; } let left = findNodes ( root . left ) ; let right = findNodes ( root . right ) ; let combined = [ ] ; let count = 0 ; for ( let i = 0 ; i < left . length ; i ++ ) { if ( left [ i ] < root . key ) { count += 1 ; } combined . push ( left [ i ] ) ; } for ( let i = 0 ; i < right . length ; i ++ ) { if ( right [ i ] < root . key ) { count += 1 ; } combined . push ( right [ i ] ) ; } combined . push ( root . key ) ; if ( count > max_v ) { rootIndex = root . key ; max_v = count ; } return combined ; } let root = newNode ( 3 ) ; root . left = newNode ( 4 ) ; root . right = newNode ( 6 ) ; root . right . left = newNode ( 4 ) ; root . right . right = newNode ( 5 ) ; root . left . left = newNode ( 10 ) ; root . left . right = newNode ( 2 ) ; max_v = 0 ; rootIndex = - 1 ; findNodes ( root ) ; document . write ( rootIndex ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Node
Javascript program:
function MaximumPath ( grid ) { let N = grid . length ; let M = grid [ 0 ] . length ; let sum = new Array ( N + 1 ) ; for ( var i = 0 ; i < sum . length ; i ++ ) { sum [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < sum . length ; i ++ ) { for ( var j = 0 ; j < sum . length ; j ++ ) { sum [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= M ; j ++ ) { sum [ i ] [ j ] = Math . max ( sum [ i - 1 ] [ j ] , sum [ i ] [ j - 1 ] ) + grid [ i - 1 ] [ j - 1 ] ; } } return sum [ N ] [ M ] ; } let grid = [ [ 1 , 2 ] , [ 3 , 5 ] ] ; document . write ( MaximumPath ( grid ) ) ;

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function Maxcost ( s , cost ) { let maxcost = 0 ; let i = 0 ; while ( i < s . length - 1 ) { if ( s [ i ] == s [ i + 1 ] ) { if ( cost [ i ] > cost [ i + 1 ] ) maxcost += cost [ i ] ; else { maxcost += cost [ i + 1 ] ; cost [ i + 1 ] = cost [ i ] ; } } i ++ ; } return maxcost ; } let s = " " ; let cost = [ 1 , 2 , 3 , 4 , 5 ] ; document . write ( Maxcost ( s , cost ) ) ;

Index/key variables: i
Accumulator variables: i, maxcost
Javascript program:
let dp = new Map ( ) ; function countMagicNumbers ( idx , sum , a , n , m , l , r ) { if ( idx == n ) { let temp = sum % m ; if ( temp == l || temp == r || ( temp > l && temp < r ) ) return dp [ [ idx , sum ] ] = 1 ; else return dp [ [ idx , sum ] ] = 0 ; } let curr = [ idx , sum ] ; if ( dp . has ( curr ) ) return dp [ curr ] ; let ls = countMagicNumbers ( idx + 1 , sum + a [ idx ] , a , n , m , l , r ) ; let rs = countMagicNumbers ( idx + 1 , sum + ( a [ idx ] - 1 ) , a , n , m , l , r ) ; let temp1 = Math . max ( ls , rs ) ; let temp = sum % m ; if ( ( temp == l || temp == r || ( temp > l && temp < r ) ) && idx != 0 ) { temp1 += 1 ; } dp [ [ idx , sum ] ] = temp1 ; return dp [ [ idx , sum ] ] ; } let N = 5 , M = 22 , L = 14 , R = 16 ; let arr = [ 17 , 11 , 10 , 8 , 15 ] ; document . write ( countMagicNumbers ( 0 , 0 , arr , N , M , L , R ) ) ;

Index/key variables: curr, idx
Accumulator variables: temp1
Javascript program:
function reachesBottom ( a ) { var n = a . length ; var m = a [ 0 ] . length ; var q = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] == 1 ) { q . slice ( 0 , 0 , [ i , j , 1 ] ) ; } else if ( a [ i ] [ j ] == 2 ) { q . push ( [ i , j , 2 ] ) ; } a [ i ] [ j ] = 0 ; } } var dx = [ - 1 , 0 , 1 , 0 ] ; var dy = [ 0 , 1 , 0 , - 1 ] ; while ( ! q . length ) { var front = q [ 0 ] ; q . shift ( ) ; var i = front [ 0 ] , j = front [ 1 ] ; var t = front [ 2 ] ; if ( a [ i ] [ j ] ) continue ; a [ i ] [ j ] = 1 ; if ( t == 1 && ( i == n - 1 && j == m - 1 ) ) { return true ; } for ( var d = 0 ; d < 4 ; d ++ ) { var ni = i + dx [ d ] ; var nj = j + dy [ d ] ; if ( ni >= 0 && ni < n && nj >= 0 && nj < m ) { q . push ( [ ni , nj , t ] ) ; } } } return false ; } var matrix = [ [ 0 , 2 , 0 ] , [ 0 , 1 , 0 ] , [ 0 , 2 , 0 ] ] ; if ( reachesBottom ( matrix ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: d, i, j
Accumulator variables: d, i, j
Iterator variables: d, i, j
Javascript program:
function matrixMinimum ( nums , K ) { let N = nums . length ; let M = nums [ 0 ] . length ; let res = new Array ( N - K + 1 ) ; for ( var i = 0 ; i < res . length ; i ++ ) { res [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M - K + 1 ; j ++ ) { let min = Number . MAX_VALUE ; for ( let k = j ; k < j + K ; k ++ ) { min = Math . min ( min , nums [ i ] [ k ] ) ; } nums [ i ] [ j ] = min ; } } for ( let j = 0 ; j < M ; j ++ ) { for ( let i = 0 ; i < N - K + 1 ; i ++ ) { let min = Number . MAX_VALUE ; for ( let k = i ; k < i + K ; k ++ ) { min = Math . min ( min , nums [ k ] [ j ] ) ; } nums [ i ] [ j ] = min ; } } for ( let i = 0 ; i < N - K + 1 ; i ++ ) for ( let j = 0 ; j < M - K + 1 ; j ++ ) res [ i ] [ j ] = nums [ i ] [ j ] ; return res ; } function smallestinKsubmatrices ( arr , K ) { let res = matrixMinimum ( arr , K ) ; for ( let i = 0 ; i < res . length ; i ++ ) { for ( let j = 0 ; j < res [ 0 ] . length ; j ++ ) { document . write ( res [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let arr = [ [ - 1 , 5 , 4 , 1 , - 3 ] , [ 4 , 3 , 1 , 1 , 6 ] , [ 2 , - 2 , 5 , 3 , 1 ] , [ 8 , 5 , 1 , 9 , - 4 ] , [ 12 , 3 , 5 , 8 , 1 ] ] ; let K = 3 ; smallestinKsubmatrices ( arr , K ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function find_kth_largest ( str , k ) { str . sort ( ) ; reverse ( str ) ; return str [ k - 1 ] ; } function reverse ( a ) { let i , n = a . length ; let t ; for ( i = 0 ; i < Math . floor ( n / 2 ) ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } function printCharacter ( str , l , r , k ) { l = l - 1 ; r = r - 1 ; let temp = str . substring ( l , r - l + 1 ) ; let ans = find_kth_largest ( temp . split ( " " ) , k ) ; return ans ; } function updateString ( str , pos , s ) { let index = pos - 1 ; let c = s ; str [ index ] = c ; } let str = " " ; let Q = 3 ; document . write ( printCharacter ( str , 1 , 2 , 2 ) + " " ) ; updateString ( str . split ( " " ) , 4 , ' ' ) ; document . write ( printCharacter ( str , 1 , 5 , 4 ) + " " ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function minDiffSubArray ( arr , n ) { var total_sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) total_sum += arr [ i ] ; var prefix_sum = 0 ; var minDiff = 1000000000 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { prefix_sum += arr [ i ] ; var diff = Math . abs ( ( total_sum - prefix_sum ) - prefix_sum ) ; if ( diff < minDiff ) minDiff = diff ; } return minDiff ; } var arr = [ 7 , 9 , 5 , 10 ] ; var n = arr . length ; document . write ( minDiffSubArray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, prefix_sum, total_sum
Iterator variables: i
Javascript program:
function CtSubarr ( arr , N , K ) { var st = new Set ( ) ; var prefixSum = 0 ; st . add ( prefixSum ) ; var res = 0 ; for ( var i = 0 ; i < N ; i ++ ) { prefixSum += arr [ i ] ; if ( st . has ( prefixSum - K ) ) { res += 1 ; prefixSum = 0 ; st = new Set ( ) ; st . add ( 0 ) ; } st . add ( prefixSum ) ; } return res ; } var arr = [ - 2 , 6 , 6 , 3 , 5 , 4 , 1 , 2 , 8 ] ; var N = arr . length ; var K = 10 ; document . write ( CtSubarr ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i, prefixSum, res
Iterator variables: i
Javascript program:
function is_prime ( n ) { if ( n <= 1 ) return 0 ; for ( var i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return 0 ; } return 1 ; } function count_prime_subarrays ( ar , n ) { var ans = 0 ; var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( is_prime ( ar [ i ] ) ) count ++ ; else { if ( count ) { ans += ( count * ( count + 1 ) ) / 2 ; count = 0 ; } } } if ( count ) ans += ( count * ( count + 1 ) ) / 2 ; return ans ; } var N = 10 ; var ar = [ 2 , 3 , 5 , 6 , 7 , 11 , 3 , 5 , 9 , 3 ] ; document . write ( count_prime_subarrays ( ar , N ) ) ;

Index/key variables: i
Accumulator variables: ans, count, i
Iterator variables: i
Javascript program:
function minSteps ( arr , n , k ) { let i , cnt = 0 ; let flag ; if ( k == 1 ) flag = 0 ; else flag = 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == flag ) { cnt ++ ; flag = ( flag + 1 ) % 2 ; } } return cnt ; } let arr = [ 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 ] ; let n = arr . length ; let k = 1 ; document . write ( minSteps ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function minSum ( a , n , k ) { let maxheap = [ ] ; for ( let i = 0 ; i < n ; i ++ ) maxheap . push ( a [ i ] ) ; maxheap . sort ( function ( a , b ) { return a - b ; } ) ; while ( maxheap . length > 0 && k > 0 ) { let max_ele = maxheap . pop ( ) ; maxheap . push ( Math . floor ( max_ele / 2 ) ) ; k -= 1 ; maxheap . sort ( function ( a , b ) { return a - b ; } ) ; } let sum = 0 ; while ( maxheap . length > 0 ) sum += maxheap . shift ( ) ; return sum ; } let n = 4 ; let k = 3 ; let a = [ 20 , 7 , 5 , 4 ] ; document . write ( minSum ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k, sum
Iterator variables: i
Javascript program:
function add_seg ( seg , start , end , current , index ) { if ( index > end index < start ) return ; if ( start == end ) { seg [ current ] = 1 ; return ; } let mid = parseInt ( ( start + end ) / 2 , 10 ) ; add_seg ( seg , start , mid , 2 * current + 1 , index ) ; add_seg ( seg , mid + 1 , end , 2 * current + 2 , index ) ; seg [ current ] = seg [ 2 * current + 1 ] + seg [ 2 * current + 2 ] ; } function deleted ( seg , l , r , start , end , current ) { if ( end < l start > r ) return 0 ; if ( start >= l && end <= r ) return seg [ current ] ; let mid = parseInt ( ( start + end ) / 2 , 10 ) ; return deleted ( seg , l , r , start , mid , 2 * current + 1 ) + deleted ( seg , l , r , mid + 1 , end , 2 * current + 2 ) ; } function sumOfIndices ( s ) { let N = s . length ; let x = ( Math . ceil ( Math . log ( N ) / Math . log ( 2 ) ) ) ; let seg_size = 2 * Math . pow ( 2 , x ) - 1 ; let segment = new Array ( seg_size ) ; segment . fill ( 0 ) ; let count = 41 ; let fre = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { let key = s [ i ] . charCodeAt ( ) ; let que = [ ] ; if ( fre . has ( key ) ) { que = fre [ key ] ; } que . push ( i ) ; fre [ key ] = que ; } let array = Array . from ( fre . keys ( ) ) ; while ( array . length > 0 ) { let a = Array . from ( fre . keys ( ) ) ; let it = a [ 0 ] ; if ( fre [ it ] . length == 0 ) fre . delete ( it ) ; else { let que = fre [ it ] ; let original_index = que [ 0 ] ; let curr_index = deleted ( segment , 0 , original_index - 1 , 0 , N - 1 , 0 ) ; let new_index = original_index - curr_index ; count += new_index + 1 ; add_seg ( segment , 0 , N - 1 , 0 , original_index ) ; que . shift ( ) ; fre [ it ] = que ; } } document . write ( count ) ; } let s = " " ; sumOfIndices ( s ) ;

Index/key variables: current, i, it, key
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let spf = Array . from ( { length : 100005 } , ( _ , i ) => 0 ) ; let prime = Array . from ( { length : 100005 } , ( _ , i ) => 0 ) ; let dp = Array . from ( { length : 100005 } , ( _ , i ) => 0 ) ; function sieve ( ) { prime [ 0 ] = prime [ 1 ] = false ; for ( let i = 2 ; i < 100005 ; i ++ ) prime [ i ] = true ; for ( let i = 2 ; i * i < 100005 ; i ++ ) { if ( prime [ i ] ) { for ( let j = i * i ; j < 100005 ; j += i ) { prime [ j ] = false ; } } } } function smallestPrimeFactors ( ) { for ( let i = 0 ; i < 100005 ; i ++ ) spf [ i ] = - 1 ; for ( let i = 2 ; i * i < 100005 ; i ++ ) { for ( let j = i ; j < 100005 ; j += i ) { if ( spf [ j ] == - 1 ) { spf [ j ] = i ; } } } } function sumOfPrimeFactors ( n ) { let ans = 0 ; while ( n > 1 ) { ans += spf [ n ] ; n /= spf [ n ] ; } return ans ; } function findLength ( n ) { if ( prime [ n ] ) { return 1 ; } if ( dp [ n ] != 0 ) { return dp [ n ] ; } let sum = sumOfPrimeFactors ( n ) ; return dp [ n ] = 1 + findLength ( sum ) ; } function maxLength ( n , m ) { sieve ( ) ; smallestPrimeFactors ( ) ; let ans = Number . MIN_VALUE ; for ( let i = n ; i <= m ; i ++ ) { if ( i == 4 ) { continue ; } ans = Math . max ( ans , findLength ( i ) ) ; } return ans ; } let n = 2 , m = 14 ; document . write ( maxLength ( n , m ) ) ;

Index/key variables: i, j, n
Accumulator variables: ans, i, j, n
Iterator variables: i, j
Javascript program:
function largest_subarray ( a , n ) { let index = new Map ( ) ; let ans = 0 ; for ( let i = 0 , j = 0 ; i < n ; i ++ ) { j = Math . max ( index . has ( a [ i ] ) ? index . get ( a [ i ] ) : 0 , j ) ; ans = Math . max ( ans , i - j + 1 ) ; index . set ( a [ i ] , i + 1 ) ; } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 ] ; let n = arr . length ; document . write ( largest_subarray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findWays ( nums , S ) { return dfs ( nums , S , 0 , 0 ) ; } function dfs ( nums , S , curr_sum , index ) { if ( index == nums . length ) { if ( S == curr_sum ) return 1 ; else return 0 ; } return dfs ( nums , S , curr_sum + nums [ index ] , index + 1 ) + dfs ( nums , S , curr_sum - nums [ index ] , index + 1 ) ; } let S = 3 ; let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let answer = findWays ( arr , S ) ; document . write ( answer ) ;

Index/key variables: index
Javascript program:
class Node { constructor ( key ) { this . key = key ; this . left = this . right = null ; } } function newNode ( key ) { let temp = new Node ( key ) ; return ( temp ) ; } function frequencyCounts ( map , root ) { if ( root == null ) return ; if ( map . has ( root . key ) ) map . set ( root . key , map . get ( root . key ) + 1 ) ; else map . set ( root . key , 1 ) ; frequencyCounts ( map , root . left ) ; frequencyCounts ( map , root . right ) ; } function computeDistance ( root , value ) { if ( root == null ) { return - 1 ; } let left = computeDistance ( root . left , value ) ; let right = computeDistance ( root . right , value ) ; if ( left == - 1 && right == - 1 ) { if ( root . key == value ) { return 1 ; } else return - 1 ; } if ( left == - 1 ) { return right + 1 ; } if ( right == - 1 ) { return left + 1 ; } else { return 1 + Math . max ( left , right ) ; } } function solve ( root , dist ) { let map = new Map ( ) ; frequencyCounts ( map , root ) ; let flag = 0 ; map . forEach ( ( values , keys ) => { if ( values > 1 ) { let result = computeDistance ( root , keys ) ; if ( result > dist result == - 1 ) { flag = 1 ; map . clear ( ) ; } } } ) if ( flag == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } let root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . right = newNode ( 4 ) ; root . right . left = newNode ( 4 ) ; let dist = 7 ; solve ( root , dist ) ;

Class/struct names: Node
Javascript program:
function findMinSum ( A , K , n ) { let minimum_sum = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let mini = Number . MAX_VALUE ; for ( let j = i + K ; j < n ; j ++ ) mini = Math . min ( mini , A [ j ] ) ; if ( mini == Number . MAX_VALUE ) continue ; minimum_sum = Math . min ( minimum_sum , A [ i ] + mini ) ; } document . write ( minimum_sum ) ; } let A = [ 4 , 2 , 5 , 4 , 3 , 2 , 5 ] ; let K = 3 ; let n = A . length ; findMinSum ( A , K , 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 lcm ( a , b ) { return ( a * b ) / __gcd ( a , b ) ; } function countPair ( N ) { var count = 0 ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { if ( __gcd ( i , j ) + lcm ( i , j ) == N ) { count ++ ; } } } return count ; } var N = 14 ; document . write ( countPair ( N ) ) ;

Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
var MAX = 10 var adj = Array . from ( Array ( MAX ) , ( ) => Array ( ) ) ; function addEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function dfs ( v , cost , vis , min_cost_node ) { vis [ v ] = true ; min_cost_node = Math . min ( min_cost_node , cost [ v - 1 ] ) ; for ( var i = 0 ; i < adj [ v ] . length ; i ++ ) { if ( vis [ adj [ v ] [ i ] ] == false ) { min_cost_node = dfs ( adj [ v ] [ i ] , cost , vis , min_cost_node ) ; } } return min_cost_node ; } function minimumCost ( V , cost ) { var vis = Array ( V + 1 ) . fill ( false ) ; var min_cost = 0 ; for ( var i = 1 ; i <= V ; i ++ ) { if ( ! vis [ i ] ) { var min_cost_node = 1000000000 ; min_cost_node = dfs ( i , cost , vis , min_cost_node ) ; min_cost += min_cost_node ; } } return min_cost ; } var V = 6 , E = 5 ; var cost = [ 12 , 25 , 8 , 11 , 10 , 7 ] ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 2 ) ; addEdge ( 2 , 5 ) ; addEdge ( 4 , 6 ) ; var min_cost = minimumCost ( V , cost ) ; document . write ( min_cost ) ;

Index/key variables: i, u, v
Accumulator variables: i, min_cost
Iterator variables: i
Javascript program:
let maxm = 0 ; class Node { constructor ( x ) { this . val = x ; this . left = null ; this . right = null ; } } var root ; function maxm_setbits ( root , ans ) { if ( ! root ) return ; if ( root . left == null && root . right == null ) { ans += ( root . val ) . toString ( 2 ) . split ( ' ' ) . filter ( y => y == ' ' ) . length ; maxm = Math . max ( ans , maxm ) ; return ; } maxm_setbits ( root . left , ans + ( root . val ) . toString ( 2 ) . split ( ' ' ) . filter ( y => y == ' ' ) . length ) ; maxm_setbits ( root . right , ans + ( root . val ) . toString ( 2 ) . split ( ' ' ) . filter ( y => y == ' ' ) . length ) ; } root = new Node ( 15 ) ; root . left = new Node ( 3 ) ; root . right = new Node ( 7 ) ; root . left . left = new Node ( 5 ) ; root . left . right = new Node ( 1 ) ; root . right . left = new Node ( 31 ) ; root . right . right = new Node ( 9 ) ; maxm_setbits ( root , 0 ) ; document . write ( maxm ) ;

Accumulator variables: ans
Class/struct names: Node