dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function checkPossible ( A , B , n ) { var values = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { values . add ( B [ i ] ) ; } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) { if ( values . has ( A [ i ] + A [ j ] ) ) { values . delete ( A [ i ] + A [ j ] ) ; if ( values . size == 0 ) break ; } } } if ( values . size == 0 ) return " " ; else return " " ; } var N = 5 ; var A = [ 3 , 5 , 1 , 4 , 2 ] ; var B = [ 3 , 4 , 5 , 6 , 7 ] ; document . write ( checkPossible ( A , B , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const N = 2e5 ; const V = 500 ; function solve ( n , d , input ) { let a = new Array ( N ) ; let cnt = new Array ( V + 1 ) ; for ( let i = 0 ; i < n ; ++ i ) a [ i ] = input [ i ] ; let answer = 0 ; for ( let i = 0 ; i < d ; ++ i ) cnt [ a [ i ] ] ++ ; for ( let i = d ; i <= n - 1 ; ++ i ) { let acc = 0 ; let low_median = - 1 , high_median = - 1 ; for ( let v = 0 ; v <= V ; ++ v ) { acc += cnt [ v ] ; if ( low_median == - 1 && acc >= parseInt ( Math . floor ( ( d + 1 ) / 2.0 ) ) ) low_median = v ; if ( high_median == - 1 && acc >= parseInt ( Math . ceil ( ( d + 1 ) / 2.0 ) ) ) high_median = v ; } let double_median = low_median + high_median ; if ( a [ i ] >= double_median ) answer ++ ; cnt [ a [ i - d ] ] -- ; cnt [ a [ i ] ] ++ ; } document . write ( answer ) ; } let input = [ 1 , 2 , 2 , 4 , 5 ] ; let n = input . length ; let k = 3 ; solve ( n , k , input ) ;

Index/key variables: i, v
Accumulator variables: acc, answer
Iterator variables: i, v
Javascript program:
function findMinSoln ( n , k ) { var minSoln = 1000000000 ; for ( var i = 1 ; i < k ; i ++ ) { if ( n % i == 0 ) minSoln = Math . min ( minSoln , ( n / i ) * k + i ) ; } return minSoln ; } var n = 4 , k = 6 ; document . write ( findMinSoln ( n , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getSum ( BITree , index ) { let ans = 0 ; index += 1 ; while ( index > 0 ) { ans += BITree [ index ] ; index -= index & ( - index ) ; } return ans ; } function updateBIT ( BITree , n , index , val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } function constructBITree ( arr , n ) { let BITree = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) BITree [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) updateBIT ( BITree , n , i , arr [ i ] ) ; return BITree ; } function getLowerBound ( BITree , arr , n , k ) { let lb = - 1 ; let l = 0 , r = n - 1 ; while ( l <= r ) { let mid = Math . floor ( l + ( r - l ) / 2 ) ; if ( getSum ( BITree , mid ) >= k ) { r = mid - 1 ; lb = mid ; } else l = mid + 1 ; } return lb ; } function performQueries ( A , n , q ) { let BITree = constructBITree ( A , n ) ; for ( let i = 0 ; i < q . length ; i ++ ) { let id = q [ i ] [ 0 ] ; if ( id == 1 ) { let idx = q [ i ] [ 1 ] ; let val = q [ i ] [ 2 ] ; A [ idx ] += val ; updateBIT ( BITree , n , idx , val ) ; } else { let k = q [ i ] [ 1 ] ; let lb = getLowerBound ( BITree , A , n , k ) ; document . write ( lb + " " ) ; } } } let A = [ 1 , 2 , 3 , 5 , 8 ] ; let n = A . length ; let q = [ [ 1 , 0 , 2 ] , [ 2 , 5 , 0 ] , [ 1 , 3 , 5 ] ] ; performQueries ( A , n , q ) ;

Index/key variables: i, idx, index
Accumulator variables: ans, i, index
Iterator variables: i
Javascript program:
var cnt = 0 ; function dfs ( val , cost , tr , u , s ) { s = s + cost [ u ] ; if ( s < 0 ) s = 0 ; if ( s > val [ u ] ) return ; cnt ++ ; for ( var i = 0 ; i < tr [ u ] . length ; i ++ ) { dfs ( val , cost , tr , tr [ u ] [ i ] , s ) ; } } var n = 9 ; var val = [ 88 , 22 , 83 , 14 , 95 , 91 , 98 , 53 , 11 ] ; var cost = [ - 1 , 24 , - 8 , 67 , 64 , 65 , 12 , - 80 , 8 ] ; var tr = Array . from ( Array ( n + 1 ) , ( ) => Array ( ) ) ; tr [ 0 ] . push ( 3 ) ; tr [ 0 ] . push ( 4 ) ; tr [ 4 ] . push ( 6 ) ; tr [ 6 ] . push ( 2 ) ; tr [ 2 ] . push ( 1 ) ; tr [ 2 ] . push ( 8 ) ; tr [ 8 ] . push ( 5 ) ; tr [ 5 ] . push ( 7 ) ; dfs ( val , cost , tr , 0 , 0 ) ; document . write ( n - cnt ) ;

Index/key variables: i, u
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function ContinuousElements ( a , n ) { if ( n == 1 ) return false ; let curr = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { if ( curr == 1 ) return false ; else curr = 0 ; } curr ++ ; } if ( curr == 1 ) return false ; return true ; } let a = [ 1 , 1 , 2 , 2 , 1 , 3 , 3 ] ; let n = a . length ; if ( ContinuousElements ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function BFS ( mat , row , col ) { var area = 0 ; var Q = [ ] ; Q . push ( new pair ( row , col ) ) ; while ( Q . length != 0 ) { var it = Q [ 0 ] ; Q . shift ( ) ; var r = it . first , c = it . second ; if ( r < 0 c < 0 r > 4 c > 4 ) continue ; if ( mat [ r ] [ c ] == 0 ) continue ; if ( mat [ r ] == 1 ) { mat [ r ] = 0 ; area ++ ; } Q . push ( new pair ( r + 1 , c ) ) ; Q . push ( new pair ( r - 1 , c ) ) ; Q . push ( new pair ( r , c + 1 ) ) ; Q . push ( new pair ( r , c - 1 ) ) ; } return area ; } function sizeOfConnections ( mat ) { var result = [ ] ; for ( var row = 0 ; row < 5 ; ++ row ) { for ( var col = 0 ; col < 5 ; ++ col ) { if ( mat [ row ] [ col ] == 1 ) { var area = BFS ( mat , row , col ) ; result . push ( area ) ; } } } for ( var val of result ) document . write ( val + " " ) ; } var mat = [ [ 1 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 1 ] , [ 1 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 1 , 1 ] ] ; sizeOfConnections ( mat ) ;

Index/key variables: c, col, r, row
Accumulator variables: area
Iterator variables: col, row, val
Class/struct names: pair
Javascript program:
function maxLen ( A , N ) { var v = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 1 ) { var s = i , len ; while ( A [ i ] == 1 && i < N ) { i ++ ; } len = i - s ; v . push ( [ len , s , i - 1 ] ) ; } } if ( v . length == 0 ) { return - 1 ; } var ans = 0 ; for ( var i = 0 ; i < v . length - 1 ; i ++ ) { ans = Math . max ( ans , v [ i ] [ 0 ] ) ; if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 2 ) { ans = Math . max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] ) ; } if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 1 ) { ans = Math . max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] - 1 ) ; } } ans = Math . max ( v [ v . length - 1 ] [ 0 ] , ans ) ; return ans ; } var arr = [ 1 , 0 , 1 , 0 , 0 , 1 ] ; var N = arr . length ; document . write ( maxLen ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var t , n , m , a ; var s = [ ] ; var tsort = [ ] ; var adj = Array . from ( Array ( 100001 ) , ( ) => Array ( ) ) ; var visited = Array ( 100001 ) . fill ( 0 ) ; function dfs ( u ) { visited [ u ] = 1 ; adj [ u ] . forEach ( it => { if ( visited [ it ] == 0 ) dfs ( it ) ; } ) ; s . push ( u ) ; } function check_cycle ( ) { var pos = new Map ( ) ; var ind = 0 ; while ( s . length != 0 ) { pos . set ( s [ s . length - 1 ] , ind ) ; tsort . push ( s [ s . length - 1 ] ) ; ind += 1 ; s . pop ( ) ; } var ans = false ; for ( var i = 0 ; i < n ; i ++ ) { adj [ i ] . forEach ( it => { if ( ( pos . has ( i ) ? pos . get ( i ) : 0 ) > ( pos . has ( it ) ? pos . get ( it ) : 0 ) ) { ans = true ; } } ) ; } ; return ans ; } function addEdge ( u , v ) { adj [ u ] . push ( v ) ; } n = 4 , m = 5 ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 0 ) ; addEdge ( 2 , 3 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == 0 ) { dfs ( i ) ; } } if ( check_cycle ( ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, it, u
Accumulator variables: i, ind
Iterator variables: i
Boolean variables: ans
Javascript program:
function printNewArray ( a , n ) { var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { v . push ( [ a [ i ] , i ] ) ; } v . sort ( ) ; var ans = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { ans [ v [ ( i + 1 ) % n ] [ 1 ] ] = v [ i ] [ 0 ] ; } for ( var i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } var a = [ 4 , 1 , 2 , 5 , 3 ] ; var n = a . length ; printNewArray ( a , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function min_remove ( arr , n , k ) { arr . sort ( ) ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { if ( arr [ j ] - arr [ i ] <= k ) { ans = Math . min ( ans , n - j + i - 1 ) ; } } } return ans ; } let k = 3 ; let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( min_remove ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function solve ( arr , n ) { var countzeroes = 0 ; var countones = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) countzeroes ++ ; else countones ++ ; } if ( Math . abs ( countzeroes - countones ) == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 0 , 1 , 0 , 0 , 1 , 1 , 1 ] ; var n = arr . length ; solve ( arr , n ) ;

Index/key variables: i
Accumulator variables: countones, countzeroes, i
Iterator variables: i
Javascript program:
function bs ( ar , n , ele ) { let start = 0 ; let end = n - 1 ; let ch = ' ' ; while ( start <= end ) { let mid = start + Math . floor ( ( end - start ) / 2 ) ; if ( ar [ mid ] == ele ) end = mid - 1 ; else if ( ar [ mid ] < ele ) { ch = ar [ mid ] ; start = mid + 1 ; } else end = mid - 1 ; } return ch ; } let ar = [ ' ' , ' ' , ' ' , ' ' ] ; let n = ar . length ; let K = ' ' ; let ch = bs ( ar , n , K ) ; if ( ch == ' ' ) document . write ( " " ) ; else document . write ( ch ) ;

Index/key variables: mid
Javascript program:
function findMaxLen ( a , k ) { let n = a . length ; a . sort ( ) ; let vis = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mp . set ( a [ i ] , i ) ; } let c = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == false ) { let check = a [ i ] * k ; if ( mp . has ( check ) ) { c ++ ; vis [ mp . get ( check ) ] = true ; } } } return n - c ; } let K = 3 ; let arr = [ 1 , 4 , 3 , 2 ] ; document . write ( findMaxLen ( arr , K ) ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function getPrefixLength ( srcStr , targetStr ) { if ( targetStr . length === 0 ) return 0 ; srcStr = srcStr . toLowerCase ( ) ; targetStr = targetStr . toLowerCase ( ) ; var dictCount = { } ; var nUnique = 0 ; for ( const ch of targetStr ) { if ( dictCount . hasOwnProperty ( ch ) !== true ) { nUnique += 1 ; dictCount [ ch ] = 0 ; } dictCount [ ch ] += 1 ; } for ( var i = 0 ; i < srcStr . length ; i ++ ) { var ch = srcStr [ i ] ; if ( dictCount . hasOwnProperty ( ch ) !== true ) continue ; dictCount [ ch ] -= 1 ; if ( dictCount [ ch ] === 0 ) nUnique -= 1 ; if ( nUnique === 0 ) return i + 1 ; } return - 1 ; } var S = " " ; var T = " " ; document . write ( getPrefixLength ( S , T ) ) ;

Index/key variables: ch, i
Accumulator variables: i, nUnique
Iterator variables: ch, i
Javascript program:
function check ( str , mid , a ) { var n = str . length ; var previous = - 1 , i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] === a ) { if ( i - previous > mid ) { return false ; } previous = i ; } } if ( i - previous > mid ) return false ; else return true ; } function possible ( str , mid ) { for ( var i = 0 ; i < 26 ; ++ i ) { if ( check ( str , mid , String . fromCharCode ( i + " " . charCodeAt ( 0 ) ) ) ) return true ; } return false ; } function findMinLength ( str ) { var low = 1 , high = str . length ; while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( possible ( str , mid ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } function ifAllDistinct ( str ) { var s = new Array ( ) ; var temp = str . split ( " " ) ; for ( const c of temp ) { s . push ( c ) ; } var set = new Set ( s ) ; return set . size === str . length ; } var str = " " ; if ( ifAllDistinct ( str ) ) document . write ( - 1 + " " ) ; else document . write ( findMinLength ( str . split ( " " ) ) ) ;

Index/key variables: i
Iterator variables: c, i
Javascript program:
function solve ( A , N ) { let i = 0 ; let k = 0 ; for ( let j = 1 ; j < N ; j ++ ) { let tempK = Math . min ( A [ i ] , A [ j ] ) / ( j - i ) ; if ( tempK > k ) { k = tempK ; } if ( A [ j ] >= A [ i ] / ( j - i ) ) i = j ; } return k ; } let A = [ 10 , 5 , 12 , 15 , 8 ] ; let N = A . length ; document . write ( solve ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: j
Iterator variables: j
Javascript program:
function split ( arr , n ) { arr . sort ( ) ; let count = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] == 1 ) { count = 2 ; break ; } } document . write ( count ) ; } let arr = [ 2 , 4 , 6 ] ; let n = arr . length ; split ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( str1 , str2 ) { var mark = Array ( 26 ) . fill ( false ) ; var n = str1 . length , m = str2 . length ; for ( var i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' ' ] = true ; } for ( var i = 0 ; i < m ; i ++ ) { if ( mark [ str2 [ i ] - ' ' ] ) return true ; } return false ; } var str1 = " " , str2 = " " ; if ( check ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function FindPairs ( n , k ) { document . write ( 1 + " " + n + " " ) ; k -- ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { document . write ( 1 + " " + i + " " ) ; k -- ; if ( k == 0 ) break ; if ( i != n / i ) { document . write ( 1 + " " + n / i + " " ) ; k -- ; } if ( k == 0 ) break ; } } } let N = 100 ; let K = 5 ; FindPairs ( N , K ) ;

Accumulator variables: i, k
Iterator variables: i
Javascript program:
function dfs ( u , adj , vis , inDeg , outDeg ) { vis [ u ] = 1 ; for ( var v of adj [ u ] ) { outDeg [ u ] = 1 ; inDeg [ v ] = 1 ; if ( vis [ v ] == 0 ) { dfs ( v , adj , vis , inDeg , outDeg ) ; } } } function findMinimumEdges ( source , N , M , dest ) { var adj = Array . from ( Array ( N + 1 ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < M ; i ++ ) { adj ] . push ( dest [ i ] ) ; } var inDeg = Array ( N + 1 ) . fill ( 0 ) ; var outDeg = Array ( N + 1 ) . fill ( 0 ) ; var vis = Array ( N + 1 ) . fill ( 0 ) ; dfs ( 1 , adj , vis , inDeg , outDeg ) ; var minEdges = 0 ; var totalIndegree = 0 ; var totalOutdegree = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( inDeg [ i ] == 1 ) totalIndegree ++ ; if ( outDeg [ i ] == 1 ) totalOutdegree ++ ; } minEdges = Math . max ( N - totalIndegree , N - totalOutdegree ) ; return minEdges ; } var N = 5 , M = 5 ; var source = [ 1 , 3 , 1 , 3 , 4 ] ; var destination = [ 2 , 2 , 3 , 4 , 5 ] ; document . write ( findMinimumEdges ( source , N , M , destination ) ) ;

Index/key variables: i, u, v
Accumulator variables: i, totalIndegree, totalOutdegree
Iterator variables: i, v
Javascript program:
function PermuteTheArray ( A , n ) { var arr = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { arr [ A [ i ] - 1 ] = i ; } var mini = n , maxi = 0 ; var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { mini = Math . min ( mini , arr [ i ] ) ; maxi = Math . max ( maxi , arr [ i ] ) ; if ( maxi - mini == i ) count ++ ; } return count ; } var A = [ 4 , 5 , 1 , 3 , 2 , 6 ] ; document . write ( PermuteTheArray ( A , 6 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findLargest ( beg , end , arr , n ) { if ( beg == end ) { let compared = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) compared [ i ] = 0 ; compared [ 0 ] = 1 ; compared [ 1 ] = arr [ beg ] ; return compared ; } let compared1 = findLargest ( beg , Math . floor ( ( beg + end ) / 2 ) , arr , n ) ; let compared2 = findLargest ( Math . floor ( ( beg + end ) / 2 ) + 1 , end , arr , n ) ; if ( compared1 [ 1 ] > compared2 [ 1 ] ) { let k = compared1 [ 0 ] + 1 ; compared1 [ 0 ] = k ; compared1 [ k ] = compared2 [ 1 ] ; return compared1 ; } else { let k = compared2 [ 0 ] + 1 ; compared2 [ 0 ] = k ; compared2 [ k ] = compared1 [ 1 ] ; return compared2 ; } } function findSecondLargest ( end , arr ) { let compared1 = findLargest ( 0 , end - 1 , arr , end ) ; let compared2 = findLargest ( 2 , compared1 [ 0 ] + 2 , compared1 , compared1 [ 0 ] ) ; document . write ( compared2 [ 1 ] ) ; } let N = 10 ; let arr = [ 20 , 1990 , 12 , 1110 , 1 , 59 , 12 , 15 , 120 , 1110 ] ; findSecondLargest ( N , arr ) ;

Index/key variables: beg, i, k
Accumulator variables: i
Iterator variables: i
Javascript program:
function CountsubString ( str , n ) { var c = 0 ; for ( var len = 1 ; len <= n ; len ++ ) { for ( var i = 0 ; i <= n - len ; i ++ ) { var j = i + len - 1 ; var temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } var k = i + 1 ; while ( temp > str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp < str [ k ] && k <= j && f != 2 ) { temp = str [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } return c ; } var str = " " . split ( ' ' ) ; document . write ( CountsubString ( str , str . length ) ) ;

Index/key variables: i, k
Accumulator variables: c, i, k, len
Iterator variables: i, len
Javascript program:
function isSubsetSum ( arr , n , sum ) { let subset = new Array ( n + 1 ) ; for ( var i = 0 ; i < subset . length ; i ++ ) { subset [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( let i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= sum ; j ++ ) { if ( j < arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - arr [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } function findSum ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } let val = Math . floor ( Math . sqrt ( sum ) ) ; for ( let i = val ; i >= 0 ; i -- ) { if ( isSubsetSum ( arr , n , i * i ) ) { return i * i ; } } return 0 ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let n = arr . length ; document . write ( findSum ( arr , n ) ) ;

Index/key variables: i, j, n, sum
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findsubArray ( arr , N , K ) { var res = N + 1 ; for ( i = 0 ; i < N ; i ++ ) { var curr_prod = 1 ; for ( j = i ; j < N ; j ++ ) { curr_prod = curr_prod * arr [ j ] ; if ( curr_prod % N == K && res > ( j - i + 1 ) ) { res = Math . min ( res , j - i + 1 ) ; break ; } } } return ( res == N + 1 ) ? 0 : res ; } var arr = [ 2 , 2 , 3 ] ; var N = arr . length ; var K = 1 ; var answer = findsubArray ( arr , N , K ) ; if ( answer != 0 ) document . write ( answer ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumCount ( A , B , n ) { var q = [ ] ; var s = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { s . add ( B [ i ] ) ; q . push ( B [ i ] ) ; } var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s . has ( A [ i ] ) ) { while ( q . length != 0 && q [ 0 ] != A [ i ] ) { s . delete ( q [ 0 ] ) ; q . shift ( ) ; count ++ ; } if ( A [ i ] == q [ 0 ] ) { q . shift ( ) ; s . delete ( A [ i ] ) ; } if ( q . length == 0 ) break ; } } document . write ( count ) ; } var N = 4 ; var A = [ 1 , 2 , 3 , 4 ] ; var B = [ 1 , 2 , 4 , 3 ] ; maximumCount ( A , B , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let N = 3 , M = 3 ; function checkBitonic ( arr , n ) { let i , j , f = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { f = 1 ; break ; } } if ( i == n ) return true ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < arr [ j - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { if ( f == 1 ) return false ; } } return true ; } function check ( arr ) { let f = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! checkBitonic ( arr [ i ] , M ) ) { document . write ( " " ) ; return ; } } for ( let i = 0 ; i < N ; i ++ ) { let temp = [ N ] ; for ( let j = 0 ; j < N ; j ++ ) { temp [ j ] = arr [ j ] [ i ] ; } if ( ! checkBitonic ( temp , N ) ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let m = [ [ 1 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 2 , 6 , 4 ] ] ; check ( m ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function getMaxGcd ( N ) { var maxGcd = Number . MIN_VALUE , A , B ; for ( i = 1 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { A = i ; B = N / i ; maxGcd = Math . max ( maxGcd , gcd ( A , B ) ) ; } } return maxGcd ; } var N = 18 ; document . write ( getMaxGcd ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function can_place ( A , n , B , mid ) { let count = 1 ; let last_position = A [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( A [ i ] - last_position >= mid ) { last_position = A [ i ] ; count ++ ; if ( count == B ) { return true ; } } } return false ; } function find_min_difference ( A , n , B ) { A . sort ( ) ; let s = 0 ; let e = A [ n - 1 ] - A [ 0 ] ; let ans = 0 ; while ( s <= e ) { let mid = parseInt ( ( s + e ) / 2 , 10 ) ; if ( can_place ( A , n , B , mid ) ) { ans = mid ; s = mid + 1 ; } else { e = mid - 1 ; } } return ans ; } let A = [ 1 , 2 , 3 , 5 ] ; let n = A . length ; let B = 3 ; let min_difference = find_min_difference ( A , n , B ) ; document . write ( min_difference ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countTriplets ( A , N ) { let ans = 0 ; let map = new Map ( ) ; for ( let j = N - 2 ; j >= 1 ; j -- ) { if ( map . has ( A [ j + 1 ] ) ) map . set ( A [ j + 1 ] , map . get ( A [ j + 1 ] ) + 1 ) ; else map . set ( A [ j + 1 ] , 1 ) ; for ( let i = 0 ; i < j ; i ++ ) { let target = A [ i ] * A [ j ] ; if ( map . has ( target ) ) ans += map . get ( target ) ; } } return ans ; } let N = 5 ; let A = [ 2 , 3 , 4 , 6 , 12 ] ; document . write ( countTriplets ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function sign ( x ) { if ( x > 0 ) return 1 ; else return - 1 ; } function findMaxSum ( arr , size ) { let max_sum = 0 , pres , i , j ; for ( i = 0 ; i < size ; i ++ ) { pres = arr [ i ] ; j = i ; while ( j < size && sign ( arr [ i ] ) == sign ( arr [ j ] ) ) { pres = Math . max ( pres , arr [ j ] ) ; j ++ ; } max_sum = max_sum + pres ; i = j - 1 ; } return max_sum ; } let arr = [ - 2 , 8 , 3 , 8 , - 4 , - 15 , 5 , - 2 , - 3 , 1 ] ; let size = arr . length ; document . write ( findMaxSum ( arr , size ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function groupInKConsecutive ( arr , K ) { var count = new Map ( ) ; arr . forEach ( element => { if ( count . has ( element ) ) count . set ( element , count . get ( element ) + 1 ) else count . set ( element , 1 ) } ) ; count . forEach ( ( value , key ) => { var cur = key ; var n = value ; if ( n > 0 ) { for ( var i = 1 ; i < K ; ++ i ) { if ( ! count . has ( cur + i ) ) { return false ; } count . set ( cur + i , count . get ( cur + i ) - n ) ; if ( count . get ( cur + i ) < 0 ) return false ; } } } ) ; return true ; } var arr = [ 1 , 2 , 3 , 6 , 2 , 3 , 4 , 7 , 8 ] ; var k = 3 ; if ( groupInKConsecutive ( arr , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Iterator variables: i