dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
const MAX = 26 ; function findCount ( a , b , n , m ) { var freq = new Array ( MAX ) . fill ( 0 ) ; var smallestFreq = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { var s = a [ i ] ; for ( var l = 0 ; l < freq . length ; l ++ ) freq [ l ] = 0 ; for ( var j = 0 ; j < s . length ; j ++ ) { freq [ s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } for ( var j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { smallestFreq . push ( freq [ j ] ) ; break ; } } } smallestFreq . sort ( ) ; var ans = [ ] ; for ( var i = 0 ; i < m ; i ++ ) { var s = b [ i ] ; for ( var l = 0 ; l < freq . length ; l ++ ) freq [ l ] = 0 ; for ( var j = 0 ; j < s . length ; j ++ ) { freq [ s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var frequency = 0 ; for ( var j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { frequency = freq [ j ] ; break ; } } var array = new Array ( smallestFreq . length ) . fill ( 0 ) ; var k = 0 ; for ( const val of smallestFreq ) { array [ k ] = val ; k ++ ; } var ind = lower_bound ( array , 0 , smallestFreq . length , frequency ) ; ans . push ( ind ) ; } return ans ; } function lower_bound ( a , low , high , element ) { while ( low < high ) { var middle = low + parseInt ( ( high - low ) / 2 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function printAnswer ( a , b , n , m ) { var ans = findCount ( a , b , n , m ) ; for ( const it of ans ) { document . write ( it + " " ) ; } } var A = [ " " , " " , " " ] ; var B = [ " " , " " ] ; var n = A . length ; var m = B . length ; printAnswer ( A , B , n , m ) ;

Index/key variables: i, j, k, l, middle
Accumulator variables: i, j, k, l
Iterator variables: i, it, j, l, val
Javascript program:
function LeftRightNode ( preorder , n ) { var min = 1000000000 , max = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { if ( min > preorder [ i ] ) min = preorder [ i ] ; if ( max < preorder [ i ] ) max = preorder [ i ] ; } document . write ( " " + min + " " ) ; document . write ( " " + max ) ; } var preorder = [ 3 , 2 , 1 , 5 , 4 ] ; var n = 5 ; LeftRightNode ( preorder , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var m = 6 , n = 4 ; function compareRow ( a1 , a2 ) { for ( var i = 0 ; i < n ; i ++ ) { if ( a1 [ i ] < a2 [ i ] ) return 1 ; else if ( a1 [ i ] > a2 [ i ] ) return - 1 ; } return 0 ; } function binaryCheck ( ar , arr ) { var l = 0 , r = m - 1 ; while ( l <= r ) { var mid = parseInt ( ( l + r ) / 2 ) ; var temp = compareRow ( ar [ mid ] , arr ) ; if ( temp == 0 ) return mid + 1 ; else if ( temp == 1 ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } var mat = [ [ 0 , 0 , 1 , 0 ] , [ 10 , 9 , 22 , 23 ] , [ 40 , 40 , 40 , 40 ] , [ 43 , 44 , 55 , 68 ] , [ 81 , 73 , 100 , 132 ] , [ 100 , 75 , 125 , 133 ] ] ; var row = [ 10 , 9 , 22 , 23 ] ; document . write ( binaryCheck ( mat , row ) ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
var maxLen = 30 ; function upper_bound ( a , low , high , element ) { while ( low < high ) { var middle = low + parseInt ( ( high - low ) / 2 ) ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } function findCnt ( arr , n , k ) { var ans = 0 ; for ( var i = 1 ; i < n ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; if ( arr [ i ] > k arr [ i ] < - 1 * k ) ans ++ ; } if ( arr [ 0 ] > k arr [ 0 ] < - 1 * k ) ans ++ ; arr . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < n ; i ++ ) ans += ( n - upper_bound ( arr , 0 , n , arr [ i ] + k ) ) ; return ans ; } var arr = [ - 1 , 4 , - 5 , 6 ] ; var n = arr . length ; var k = 0 ; document . write ( findCnt ( arr , n , k ) ) ;

Index/key variables: i, middle
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function upperBound ( a , low , high , element ) { while ( low < high ) { let middle = low + Math . floor ( ( high - low ) / 2 ) ; if ( a [ middle ] > element ) { high = middle ; } else { low = middle + 1 ; } } return low ; } function FindIntersection ( type1 , n , type2 , m ) { let ans = n * m ; let start = [ ] ; let end = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { start . push ( type1 [ i ] [ 0 ] ) ; end . push ( type1 [ i ] [ 1 ] ) ; } start . sort ( function ( a , b ) { return a - b ; } ) ; end . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < m ; i ++ ) { let L = type2 [ i ] [ 0 ] ; let R = type2 [ i ] [ 1 ] ; ans -= start . length - upperBound ( start , 0 , start . length , R ) ; ans -= upperBound ( end , 0 , end . length , L - 1 ) ; } return ans ; } let type1 = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 4 , 5 ] , [ 6 , 7 ] ] ; let type2 = [ [ 1 , 5 ] , [ 2 , 3 ] , [ 4 , 7 ] , [ 5 , 7 ] ] ; let n = type1 . length ; let m = type2 . length ; document . write ( FindIntersection ( type1 , n , type2 , m ) ) ;

Index/key variables: i, middle
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function check ( mid , array , n , K ) { var count = 0 ; var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( array [ i ] > mid ) return false ; sum += array [ i ] ; if ( sum > mid ) { count ++ ; sum = array [ i ] ; } } count ++ ; if ( count <= K ) return true ; return false ; } function solve ( array , n , K ) { var max = array . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var end = 0 ; for ( var i = 0 ; i < n ; i ++ ) { } var answer = 0 ; while ( start <= end ) { var mid = parseInt ( ( start + end ) / 2 ) ; if ( check ( mid , array , n , K ) ) { answer = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } return answer ; } var array = [ 1 , 2 , 3 , 4 ] ; var n = array . length ; var K = 3 ; document . write ( solve ( array , n , K ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function createSorted ( a , n ) { var b = [ ] ; for ( var j = 0 ; j < n ; j ++ ) { if ( b . length == 0 ) b . push ( a [ j ] ) ; else { var start = 0 , end = b . length - 1 ; var pos = 0 ; while ( start <= end ) { var mid = start + parseInt ( ( end - start ) / 2 ) ; if ( b [ mid ] === a [ j ] ) { b . insert ( Math . max ( 0 , mid + 1 ) , a [ j ] ) ; break ; } else if ( b [ mid ] > a [ j ] ) pos = end = mid - 1 ; else pos = start = mid + 1 ; if ( start > end ) { pos = start ; b . insert ( Math . max ( 0 , pos ) , a [ j ] ) ; break ; } } } } for ( var i = 0 ; i < n ; i ++ ) document . write ( b [ i ] + " " ) ; } Array . prototype . insert = function ( index , item ) { this . splice ( index , 0 , item ) ; } ; var a = [ 2 , 5 , 4 , 9 , 8 ] ; var n = a . length ; createSorted ( a , n ) ;

Index/key variables: i, j, mid
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var MAX = 26 ; function atLeastK ( freq , k ) { for ( var i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] != 0 && freq [ i ] < k ) return false ; } return true ; } function setZero ( freq ) { for ( var i = 0 ; i < MAX ; i ++ ) freq [ i ] = 0 ; } function findlength ( str , n , k ) { var maxLen = 0 ; var freq = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { setZero ( freq ) ; for ( var j = i ; j < n ; j ++ ) { freq [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; if ( atLeastK ( freq , k ) ) { maxLen = Math . max ( maxLen , j - i + 1 ) ; } } } return maxLen ; } var str = " " ; var n = str . length ; var k = 2 ; document . write ( findlength ( str , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function check ( m , n , arr ) { var desired = Array ( n ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = m ; m -- ; } for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > desired [ i ] desired [ i ] < 1 ) { return false ; } } return true ; } function minOperations ( arr , n ) { var start = arr [ n - 1 ] ; var end = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) + n ; var max_arr = 0 ; while ( start <= end ) { var mid = parseInt ( ( start + end ) / 2 ) ; if ( check ( mid , n , arr ) ) { max_arr = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } var desired = Array ( n ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = max_arr ; max_arr -- ; } var operations = 0 ; for ( var i = 0 ; i < n ; i ++ ) { operations += ( desired [ i ] - arr [ i ] ) ; } return operations ; } var arr = [ 4 , 4 , 5 , 5 , 7 ] ; var n = arr . length ; document . write ( minOperations ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, m, max_arr, operations
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } ; function insert ( head , item ) { var temp = new Node ( ) ; temp . data = item ; temp . next = head ; head = temp ; return head ; } function countNode ( head ) { if ( head == null ) return 0 ; ; var s = new Set ( ) ; s . add ( head . data ) ; var count = 0 ; for ( var curr = head . next ; curr != null ; curr = curr . next ) { if ( s . has ( curr . data ) ) count ++ ; s . add ( curr . data ) ; } return count ; } var head = null ; head = insert ( head , 5 ) ; head = insert ( head , 7 ) ; head = insert ( head , 5 ) ; head = insert ( head , 1 ) ; head = insert ( head , 7 ) ; document . write ( countNode ( head ) ) ;

Accumulator variables: count
Iterator variables: curr
Class/struct names: Node
Javascript program:
function minSteps ( arr , n ) { var v = Array ( n ) . fill ( 0 ) ; var q = [ ] ; q . push ( 0 ) ; var depth = 0 ; while ( q . length != 0 ) { var x = q . length ; while ( x -- ) { var i = q [ 0 ] ; q . shift ( ) ; if ( v [ i ] ) continue ; if ( i == n - 1 ) return depth ; v [ i ] = 1 ; if ( i + arr [ i ] < n ) q . push ( i + arr [ i ] ) ; if ( i - arr [ i ] >= 0 ) q . push ( i - arr [ i ] ) ; } depth ++ ; } return - 1 ; } var arr = [ 1 , 1 , 1 , 1 , 1 , 1 ] ; var n = arr . length ; document . write ( minSteps ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: depth, x
Javascript program:
function divisorcount ( elem ) { let ans = 0 ; for ( let i = 1 ; i <= Math . sqrt ( elem ) ; i ++ ) { if ( elem % i == 0 ) { if ( i * i == elem ) ans ++ ; else ans += 2 ; } } return ans ; } function findwinner ( A , B , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { A [ i ] = divisorcount ( A [ i ] ) ; } for ( let i = 0 ; i < M ; i ++ ) { B [ i ] = divisorcount ( B [ i ] ) ; } A . sort ( function ( a , b ) { return a - b ; } ) ; B . sort ( function ( a , b ) { return a - b ; } ) ; let winA = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let val = A [ i ] ; let start = 0 ; let end = M - 1 ; let index = - 1 ; while ( start <= end ) { let mid = Math . floor ( ( start + end ) / 2 ) ; if ( B [ mid ] <= val ) { index = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } winA += ( index + 1 ) ; } let winB = N * M - winA ; if ( winA > winB ) { return " " ; } else if ( winB > winA ) { return " " ; } return " " ; } let A = [ 4 , 12 , 24 ] ; let N = A . length ; let B = [ 25 , 28 , 13 , 45 ] ; let M = B . length ; document . write ( findwinner ( A , B , N , M ) ) ;

Index/key variables: i, mid
Accumulator variables: ans, i, winA
Iterator variables: i
Javascript program:
function isPossible ( box , truck , n , m , min_time ) { let temp = 0 ; let count = 0 ; while ( count < m ) { for ( let j = 0 ; j < min_time && temp < n && truck [ count ] >= box [ temp ] ; j += 2 ) temp ++ ; count ++ ; } if ( temp == n ) return true ; return false ; } function minTime ( box , truck , n , m ) { box . sort ( function ( a , b ) { return a - b } ) ; truck . sort ( function ( a , b ) { return a - b } ) ; let l = 0 ; let h = 2 * n ; let min_time = 0 ; while ( l <= h ) { let mid = Math . floor ( ( l + h ) / 2 ) ; if ( isPossible ( box , truck , n , m , mid ) ) { min_time = mid ; h = mid - 1 ; } else l = mid + 1 ; } return min_time ; } let box = [ 10 , 2 , 16 , 19 ] ; let truck = [ 29 , 25 ] ; let n = box . length ; let m = truck . length ; document . write ( minTime ( box , truck , n , m ) ) ;

Index/key variables: count, temp
Accumulator variables: count, j, temp
Iterator variables: j
Javascript program:
function solve ( interval , N , Q ) { var Mark = Array ( Q ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { var l = interval [ i ] [ 0 ] - 1 ; var r = interval [ i ] [ 1 ] - 1 ; for ( var j = l ; j <= r ; j ++ ) Mark [ j ] ++ ; } var count = 0 ; for ( var i = 0 ; i < Q ; i ++ ) { if ( Mark [ i ] ) count ++ ; } var count1 = Array ( Q ) . fill ( 0 ) ; if ( Mark [ 0 ] == 1 ) count1 [ 0 ] = 1 ; for ( var i = 1 ; i < Q ; i ++ ) { if ( Mark [ i ] == 1 ) count1 [ i ] = count1 [ i - 1 ] + 1 ; else count1 [ i ] = count1 [ i - 1 ] ; } var maxindex ; var maxcoverage = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var l = interval [ i ] [ 0 ] - 1 ; var r = interval [ i ] [ 1 ] - 1 ; var elem1 ; if ( l != 0 ) elem1 = count1 [ r ] - count1 [ l - 1 ] ; else elem1 = count1 [ r ] ; if ( count - elem1 >= maxcoverage ) { maxcoverage = count - elem1 ; maxindex = i ; } } document . write ( " " + maxcoverage + " " + maxindex ) ; } var interval = [ [ 1 , 4 ] , [ 4 , 5 ] , [ 5 , 6 ] , [ 6 , 7 ] , [ 3 , 5 ] ] ; var N = interval . length ; var Q = 7 ; solve ( interval , N , Q ) ;

Index/key variables: i, j, r
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function isPossible ( arr , n , dist , k ) { let req = 0 ; let curr = 0 ; let prev = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( curr != n && arr [ curr ] - arr [ prev ] <= dist ) { curr ++ ; } req ++ ; if ( curr == n ) { break ; } prev = curr - 1 ; } if ( curr != n ) { return false ; } if ( req <= k ) { return true ; } return false ; } function minDistance ( arr , n , k ) { let l = 0 ; let h = arr [ n - 1 ] ; let ans = 0 ; while ( l <= h ) { let m = Math . floor ( ( l + h ) / 2 ) ; if ( isPossible ( arr , n , m , k ) ) { ans = m ; h = m - 1 ; } else { l = m + 1 ; } } return ans ; } let arr = [ 2 , 15 , 36 , 43 ] ; let n = arr . length ; let k = 2 ; document . write ( minDistance ( arr , n , k ) ) ;

Index/key variables: curr, prev
Accumulator variables: curr, i, req
Iterator variables: i
Javascript program:
function getKthElement ( n , k , L , R ) { let l = 1 ; let h = n ; let total = new Array ( n + 1 ) ; total [ 0 ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) { total [ i + 1 ] = total [ i ] + ( R [ i ] - L [ i ] ) + 1 ; } let index = - 1 ; while ( l <= h ) { let m = Math . floor ( ( l + h ) / 2 ) ; if ( total [ m ] > k ) { index = m ; h = m - 1 ; } else if ( total [ m ] < k ) l = m + 1 ; else { index = m ; break ; } } l = L [ index - 1 ] ; h = R [ index - 1 ] ; let x = k - total [ index - 1 ] ; while ( l <= h ) { let m = Math . floor ( ( l + h ) / 2 ) ; if ( ( m - L [ index - 1 ] ) + 1 == x ) { return m ; } else if ( ( m - L [ index - 1 ] ) + 1 > x ) h = m - 1 ; else l = m + 1 ; } return k ; } let L = [ 1 , 8 , 21 ] ; let R = [ 4 , 10 , 23 ] ; let n = L . length ; let k = 6 ; document . write ( getKthElement ( n , k , L , R ) ) ;

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

Index/key variables: mid
Javascript program:
function maxSum ( arr , n , K ) { var maximum = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { var sumk = 0 ; for ( var j = i ; j < n ; j += K ) sumk = sumk + arr [ j ] ; maximum = Math . max ( maximum , sumk ) ; } return maximum ; } var arr = [ 3 , 6 , 4 , 7 , 2 ] ; var n = arr . length ; var K = 2 ; document . write ( maxSum ( arr , n , K ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countGreater ( arr , n , k ) { var l = 0 ; var r = n - 1 ; var leftGreater = n ; while ( l <= r ) { var m = l + parseInt ( ( r - l ) / 2 ) ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return ( n - leftGreater ) ; } var arr = [ 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 ] ; var n = arr . length ; var k = 7 ; document . write ( countGreater ( arr , n , k ) ) ;

Index/key variables: m
Javascript program:
function operations ( op , n , k ) { let i , count = 0 ; let nVal = 0 ; let min = Number . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { nVal += op [ i ] ; min = Math . min ( min , nVal ) ; if ( ( k + nVal ) <= 0 ) return ( i + 1 ) ; } if ( nVal >= 0 ) return - 1 ; let times = Math . floor ( ( k - Math . abs ( min ) ) / Math . abs ( nVal ) ) ; k = ( k - ( times * Math . abs ( nVal ) ) ) ; count = ( times * n ) ; while ( k > 0 ) { for ( i = 0 ; i < n ; i ++ ) { k = k + op [ i ] ; count ++ ; if ( k <= 0 ) break ; } } return count ; } let op = [ - 60 , 65 , - 1 , 14 , - 25 ] ; let n = op . length ; let k = 100000 ; document . write ( operations ( op , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i, nVal
Iterator variables: i
Javascript program:
let MAX_SIZE = 1000 ; let lookup_table = new Array ( MAX_SIZE ) ; lookup_table . fill ( 0 ) ; function create_table ( n ) { let pow = 1 ; let co = 0 ; while ( true ) { pow <<= 1 ; lookup_table [ co ] = parseInt ( ( n + ( pow >> 1 ) ) / pow , 10 ) ; if ( lookup_table [ co ++ ] == 0 ) { break ; } } } function binary ( arr , v ) { let index = lookup_table [ 0 ] - 1 ; let co = 0 ; while ( lookup_table [ co ] != 0 ) { if ( v == arr [ index ] ) return index ; else if ( v < arr [ index ] ) { index -= lookup_table [ ++ co ] ; return index ; } else { index += lookup_table [ ++ co ] ; return index ; } } return index ; } let arr = [ 1 , 3 , 5 , 6 , 7 , 8 , 9 ] ; let n = arr . length ; create_table ( n ) ; document . write ( " " + binary ( arr , 3 ) ) ;

Index/key variables: co, index
Accumulator variables: co, index
Javascript program:
function findNumber ( a , n , K ) { for ( var i = 0 ; i < n ; i ++ ) { if ( K >= a [ i ] [ 0 ] && K <= a [ i ] [ 1 ] ) return i ; } return - 1 ; } var a = [ [ 1 , 3 ] , [ 4 , 7 ] , [ 8 , 11 ] ] ; var n = a . length ; var k = 6 ; var index = findNumber ( a , n , k ) ; if ( index != - 1 ) document . write ( index ) ; else document . write ( - 1 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function findNumber ( a , n , K ) { var low = 0 , high = n - 1 ; while ( low <= high ) { var mid = ( low + high ) >> 1 ; if ( K >= a [ mid ] . first && K <= a [ mid ] . second ) return mid ; else if ( K < a [ mid ] . first ) high = mid - 1 ; else low = mid + 1 ; } return - 1 ; } var a = [ new pair ( 1 , 3 ) , new pair ( 4 , 7 ) , new pair ( 8 , 11 ) ] ; var n = a . length ; var k = 6 ; var index = findNumber ( a , n , k ) ; if ( index != - 1 ) document . write ( index ) ; else document . write ( - 1 ) ;

Index/key variables: mid
Class/struct names: pair
Javascript program:
function prefixSum ( p_arr , arr , n ) { p_arr [ 0 ] = arr [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) p_arr [ i ] = arr [ i ] + p_arr [ i - 1 ] ; } function hashPrefixSum ( p_arr , n , q ) { for ( var i = 0 ; i < n ; i ++ ) q . add ( p_arr [ i ] ) ; } function canDivide ( p_arr , n , q , l , r ) { var sum ; if ( l == 0 ) sum = p_arr [ r ] ; else sum = p_arr [ r ] - p_arr [ l - 1 ] ; if ( sum % 2 == 1 ) { document . write ( " " ) ; return ; } var beg = 0 ; if ( l != 0 ) beg = p_arr [ l - 1 ] ; if ( q . has ( ( beg + sum / 2 ) ) ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 1 , 1 , 2 , 3 ] ; var n = arr . length ; var p_arr = Array ( n ) ; prefixSum ( p_arr , arr , n ) ; var q = new Set ( ) ; hashPrefixSum ( p_arr , n , q ) ; canDivide ( p_arr , n , q , 0 , 1 ) ; canDivide ( p_arr , n , q , 1 , 3 ) ; canDivide ( p_arr , n , q , 1 , 2 ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
var n = 4 ; function findRing ( arr , x ) { if ( arr [ 0 ] [ 0 ] > x ) return - 1 ; var l = 0 , r = parseInt ( ( n + 1 ) / 2 ) - 1 ; if ( n % 2 == 1 && arr [ r ] [ r ] < x ) return - 1 ; if ( n % 2 == 0 && arr [ r + 1 ] [ r ] < x ) return - 1 ; while ( l < r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( arr [ mid ] [ mid ] <= x ) if ( mid == ( n + 1 ) / 2 - 1 arr [ mid + 1 ] [ mid + 1 ] > x ) return mid ; else l = mid + 1 ; else r = mid - 1 ; } return r ; } function binarySearchRowInc ( arr , row , l , r , x ) { while ( l <= r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( arr [ row ] [ mid ] == x ) return mid ; if ( arr [ row ] [ mid ] < x ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } function binarySearchColumnInc ( arr , col , t , b , x ) { while ( t <= b ) { var mid = parseInt ( ( t + b ) / 2 ) ; if ( arr [ mid ] [ col ] == x ) return mid ; if ( arr [ mid ] [ col ] < x ) t = mid + 1 ; else b = mid - 1 ; } return - 1 ; } function binarySearchRowDec ( arr , row , l , r , x ) { while ( l <= r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( arr [ row ] [ mid ] == x ) return mid ; if ( arr [ row ] [ mid ] < x ) r = mid - 1 ; else l = mid + 1 ; } return - 1 ; } function binarySearchColumnDec ( arr , col , t , b , x ) { while ( t <= b ) { var mid = parseInt ( ( t + b ) / 2 ) ; if ( arr [ mid ] [ col ] == x ) return mid ; if ( arr [ mid ] [ col ] < x ) b = mid - 1 ; else t = mid + 1 ; } return - 1 ; } function spiralBinary ( arr , x ) { var f1 = findRing ( arr , x ) ; var r , c ; if ( f1 == - 1 ) { document . write ( " " ) ; return ; } if ( n % 2 == 1 && f1 == ( n + 1 ) / 2 - 1 ) { document . write ( f1 + " " + f1 + " " ) ; return ; } if ( x < arr [ f1 ] [ n - f1 - 1 ] ) { c = binarySearchRowInc ( arr , f1 , f1 , n - f1 - 2 , x ) ; r = f1 ; } else if ( x < arr [ n - f1 - 1 ] [ n - f1 - 1 ] ) { c = n - f1 - 1 ; r = binarySearchColumnInc ( arr , n - f1 - 1 , f1 , n - f1 - 2 , x ) ; } else if ( x < arr [ n - f1 - 1 ] [ f1 ] ) { c = binarySearchRowDec ( arr , n - f1 - 1 , f1 + 1 , n - f1 - 1 , x ) ; r = n - f1 - 1 ; } else { r = binarySearchColumnDec ( arr , f1 , f1 + 1 , n - f1 - 1 , x ) ; c = f1 ; } if ( c == - 1 r == - 1 ) document . write ( " " ) ; else document . write ( r + " " + c ) ; return ; } var arr = [ [ 1 , 2 , 3 , 4 ] , [ 12 , 13 , 14 , 5 ] , [ 11 , 16 , 15 , 6 ] , [ 10 , 9 , 8 , 7 ] ] ; spiralBinary ( arr , 7 ) ;

Index/key variables: col, f1, mid, r, row
Javascript program:
function costToPanagram ( str , cost ) { var i , n = str . length ; var occurrences = Array ( 26 ) . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) occurrences [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var gain = 0 ; for ( i = 0 ; i < 26 ; i ++ ) { if ( occurrences [ i ] == 0 ) gain -= ( 2 * cost [ i ] ) ; else if ( occurrences [ i ] > 1 ) gain += ( cost [ i ] * ( occurrences [ i ] - 1 ) ) ; } if ( gain >= 0 ) return 0 ; return ( gain * - 1 ) ; } var cost = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ; var str = " " ; document . write ( costToPanagram ( str , cost ) ) ;

Index/key variables: i
Accumulator variables: gain, i
Iterator variables: i
Javascript program:
function strScore ( str , s , n ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) m . set ( str [ i ] , i + 1 ) ; if ( ! m . has ( s ) ) return 0 ; let score = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) score += s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ; score = score * m . get ( s ) ; return score ; } let str = [ " " , " " , " " ] ; let s = " " ; let n = str . length ; document . write ( strScore ( str , s , n ) ) ;

Index/key variables: i
Accumulator variables: i, score
Iterator variables: i
Javascript program:
function countSubArrays ( arr , n , K ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let bitwise_or = 0 ; for ( let k = i ; k <= j ; k ++ ) { bitwise_or = bitwise_or | arr [ k ] ; } if ( bitwise_or >= K ) count ++ ; } } return count ; } let arr = [ 3 , 4 , 5 ] ; let n = arr . length ; let k = 6 ; document . write ( countSubArrays ( arr , n , k ) ) ;

Index/key variables: k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k