dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let N = 100005 ; let n , k ; let al = new Array ( N ) . fill ( 0 ) . map ( ( t ) => [ ] ) ; let Ideal_pair ; let bit = new Array ( N ) ; let root_node = new Array ( N ) ; function bit_q ( i , j ) { let sum = 0 ; while ( j > 0 ) { sum += bit [ j ] ; j -= ( j & ( j * - 1 ) ) ; } i -- ; while ( i > 0 ) { sum -= bit [ i ] ; i -= ( i & ( i * - 1 ) ) ; } return sum ; } function bit_up ( i , diff ) { while ( i <= n ) { bit [ i ] += diff ; i += i & - i ; } } function dfs ( node ) { Ideal_pair += bit_q ( Math . max ( 1 , node - k ) , Math . min ( n , node + k ) ) ; bit_up ( node , 1 ) ; for ( let i = 0 ; i < al [ node ] . length ; i ++ ) dfs ( al [ node ] [ i ] ) ; bit_up ( node , - 1 ) ; } function initialise ( ) { Ideal_pair = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { root_node [ i ] = true ; bit [ i ] = 0 ; } } function Add_Edge ( x , y ) { al [ x ] . push ( y ) ; root_node [ y ] = false ; } function Idealpairs ( ) { let r = - 1 ; for ( let i = 1 ; i <= n ; i ++ ) if ( root_node [ i ] ) { r = i ; break ; } dfs ( r ) ; return Ideal_pair ; } n = 6 , k = 3 ; initialise ( ) ; Add_Edge ( 1 , 2 ) ; Add_Edge ( 1 , 3 ) ; Add_Edge ( 3 , 4 ) ; Add_Edge ( 3 , 5 ) ; Add_Edge ( 3 , 6 ) ; document . write ( Idealpairs ( ) ) ;

Index/key variables: i, j, node, x, y
Accumulator variables: Ideal_pair, i, j, sum
Iterator variables: i
Javascript program:
function printSubsets ( n ) { for ( let i = n ; i > 0 ; i = ( i - 1 ) & n ) document . write ( i + " " ) ; document . write ( " " + " " ) ; } let n = 9 ; printSubsets ( n ) ;

Iterator variables: i
Javascript program:
function answer ( n ) { let m = 2 ; let ans = 1 ; let r = 1 ; while ( r < n ) { r = ( Math . pow ( 2 , m ) - 1 ) * ( Math . pow ( 2 , m - 1 ) ) ; if ( r < n ) ans = r ; m ++ ; } return ans ; } let n = 7 ; document . write ( answer ( n ) ) ;

Accumulator variables: m
Javascript program:
function setBitNumber ( n ) { if ( n == 0 ) return 0 ; let msb = 0 ; n = n / 2 ; while ( n != 0 ) { n = $n / 2 ; msb ++ ; } return ( 1 << msb ) ; } let n = 0 ; document . write ( setBitNumber ( n ) ) ;

Accumulator variables: msb
Javascript program:
function setBitNumber ( n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; n = n + 1 ; return ( n >> 1 ) ; } let n = 273 ; document . write ( setBitNumber ( n ) ) ;

Accumulator variables: n
Javascript program:
function countTrailingZero ( x ) { let count = 0 ; while ( ( x & 1 ) == 0 ) { x = x >> 1 ; count ++ ; } return count ; } document . write ( countTrailingZero ( 11 ) ) ;

Accumulator variables: count
Javascript program:
function search ( list , num ) { var low = 0 , high = list . length - 1 ; var ans = - 1 ; while ( low <= high ) { var mid = low + ( high - low ) / 2 ; if ( list [ mid ] <= num ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } return ans ; } function isPalindrome ( n ) { var rev = 0 ; var temp = n ; while ( n > 0 ) { rev = rev * 10 + n % 10 ; n = parseInt ( n / 10 ) ; } return rev == temp ; } function countNumbers ( L , R , K ) { var list = [ ] ; for ( var i = L ; i <= R ; i ++ ) { if ( isPalindrome ( i ) ) { list . push ( i ) ; } } var count = 0 ; for ( var i = 0 ; i < list . length ; i ++ ) { var right_index = search ( list , list [ i ] + K - 1 ) ; if ( right_index != - 1 ) count = Math . max ( count , right_index - i + 1 ) ; } return count ; } var L = 98 , R = 112 ; var K = 13 ; document . write ( countNumbers ( L , R , K ) ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaximumSum ( a , n ) { var prev_smaller = findPrevious ( a , n ) ; var next_smaller = findNext ( a , n ) ; var max_value = 0 ; for ( var i = 0 ; i < n ; i ++ ) { max_value = Math . max ( max_value , a [ i ] * ( next_smaller [ i ] - prev_smaller [ i ] - 1 ) ) ; } return max_value ; } function findPrevious ( a , n ) { var ps = Array ( n ) . fill ( 0 ) ; ps [ 0 ] = - 1 ; let stack = Array ( ) ; stack . push ( 0 ) ; for ( var i = 1 ; i < a . length ; i ++ ) { while ( stack . length > 0 && a [ stack [ stack . length - 1 ] ] >= a [ i ] ) stack . pop ( ) ; ps [ i ] = stack . length > 0 ? stack [ stack . length - 1 ] : - 1 ; stack . push ( i ) ; } return ps ; } function findNext ( a , n ) { var ns = Array ( n ) . fill ( 0 ) ; ns [ n - 1 ] = n ; var stack = Array ( ) ; stack . push ( n - 1 ) ; for ( var i = n - 2 ; i >= 0 ; i -- ) { while ( stack . length > 0 && a [ stack [ stack . length - 1 ] ] >= a [ i ] ) stack . pop ( ) ; ns [ i ] = stack . length > 0 ? stack [ stack . length - 1 ] : a . length ; stack . push ( i ) ; } return ns ; } var n = 3 ; var a = [ 80 , 48 , 82 ] ; document . write ( findMaximumSum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function compare ( arr1 , arr2 ) { for ( let i = 0 ; i < 256 ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } function search ( pat , txt ) { let M = pat . length ; let N = txt . length ; let countP = new Array ( 256 ) ; let countTW = new Array ( 256 ) ; for ( let i = 0 ; i < 256 ; i ++ ) { countP [ i ] = 0 ; countTW [ i ] = 0 ; } for ( let i = 0 ; i < 256 ; i ++ ) { countP [ i ] = 0 ; countTW [ i ] = 0 ; } for ( let i = 0 ; i < M ; i ++ ) { ( countP [ pat [ i ] . charCodeAt ( 0 ) ] ) ++ ; ( countTW [ txt [ i ] . charCodeAt ( 0 ) ] ) ++ ; } for ( let i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) return true ; ( countTW [ txt [ i ] . charCodeAt ( 0 ) ] ) ++ ; countTW [ txt [ i - M ] . charCodeAt ( 0 ) ] -- ; } if ( compare ( countP , countTW ) ) return true ; return false ; } let txt = " " ; let pat = " " ; if ( search ( pat , txt ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function binarySearch ( a , item , low , high ) { while ( low <= high ) { var mid = low + ( high - low ) / 2 ; if ( item == a [ mid ] ) return mid + 1 ; else if ( item > a [ mid ] ) low = mid + 1 ; else high = mid - 1 ; } return low ; } function insertionSort ( a , n ) { var i , loc , j , k , selected ; for ( i = 1 ; i < n ; ++ i ) { j = i - 1 ; selected = a [ i ] ; loc = binarySearch ( a , selected , 0 , j ) ; while ( j >= loc ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = selected ; } } var a = [ 37 , 23 , 0 , 17 , 12 , 72 , 31 , 46 , 100 , 88 , 54 ] ; var n = a . length , i ; insertionSort ( a , n ) ; document . write ( " " + " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ;

Index/key variables: i, j, mid
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function insertionSort ( arr , n ) { let i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = key ; } } function printArray ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 12 , 11 , 13 , 5 , 6 ] ; let n = arr . length ; insertionSort ( arr , n ) ; printArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function validPermutations ( str ) { let m = new Map ( ) ; let count = str . length , ans = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( m . has ( str [ i ] ) ) { m . set ( str [ i ] , m . get ( str [ i ] ) + 1 ) ; } else { m . set ( str [ i ] , 1 ) ; } } for ( let i = 0 ; i < str . length ; i ++ ) { ans += count - m . get ( str [ i ] ) ; m . set ( str [ i ] , m . get ( str [ i ] ) - 1 ) ; count -- ; } return ans + 1 ; } let str = " " ; document . write ( validPermutations ( str ) ) ;

Index/key variables: i
Accumulator variables: ans, count, i
Iterator variables: i
Javascript program:
function countPaths ( n , m ) { var dp = Array ( n + 1 ) . fill ( 0 ) . map ( x => Array ( m + 1 ) . fill ( 0 ) ) ; for ( i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( i = 0 ; i <= m ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( i = 1 ; i <= n ; i ++ ) for ( j = 1 ; j <= m ; j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] ; return dp [ n ] [ m ] ; } var n = 3 , m = 2 ; document . write ( " " + countPaths ( n , m ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function replaceConsonants ( str ) { var res = " " ; var i = 0 , count = 0 ; while ( i < str . length ) { if ( str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " ) { i ++ ; count ++ ; } else { if ( count > 0 ) res += count . toString ( ) ; res += str [ i ] ; i ++ ; count = 0 ; } } if ( count > 0 ) res += count . toString ( ) ; return res ; } var str = " " ; document . write ( replaceConsonants ( str ) ) ;

Index/key variables: i
Accumulator variables: count, i, res
Javascript program:
function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function encryptString ( s , n , k ) { var countVowels = 0 ; var countConsonants = 0 ; var ans = " " ; for ( var l = 0 ; l <= n - k ; l ++ ) { countVowels = 0 ; countConsonants = 0 ; for ( var r = l ; r <= l + k - 1 ; r ++ ) { if ( isVowel ( s [ r ] ) == true ) countVowels ++ ; else countConsonants ++ ; } ans += ( countVowels * countConsonants ) . toString ( ) ; } return ans ; } var s = " " ; var n = s . length ; var k = 2 ; document . write ( encryptString ( s , n , k ) ) ;

Index/key variables: r
Accumulator variables: ans, countConsonants, countVowels, l, r
Iterator variables: l, r
Javascript program:
var charBuffer = " " ; function processWords ( input ) { var s = input . split ( ' ' ) ; s . forEach ( element => { charBuffer += element [ 0 ] ; } ) ; return charBuffer ; } var input = " " ; document . write ( processWords ( input ) ) ;

Accumulator variables: charBuffer
Javascript program:
function generateAllStringsUtil ( K , str , n ) { if ( n == K ) { str [ n ] = ' \0 ' ; document . write ( str . join ( " " ) + " " ) ; return ; } if ( str [ n - 1 ] == ' ' ) { str [ n ] = ' ' ; generateAllStringsUtil ( K , str , n + 1 ) ; } if ( str [ n - 1 ] == ' ' ) { str [ n ] = ' ' ; generateAllStringsUtil ( K , str , n + 1 ) ; str [ n ] = ' ' ; generateAllStringsUtil ( K , str , n + 1 ) ; } } function generateAllStrings ( K ) { if ( K <= 0 ) return ; var str = new Array ( K ) ; str [ 0 ] = ' ' ; generateAllStringsUtil ( K , str , 1 ) ; str [ 0 ] = ' ' ; generateAllStringsUtil ( K , str , 1 ) ; } var K = 3 ; generateAllStrings ( K ) ;

Index/key variables: n
Javascript program:
function delCost ( s , cost ) { var ans = 0 ; var forMax = new Map ( ) ; var forTot = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( ! forMax . has ( s [ i ] ) ) { forMax . set ( s [ i ] , cost [ i ] ) ; } else { forMax . set ( s [ i ] , Math . max ( forMax . get ( s [ i ] ) , cost [ i ] ) ) } if ( ! forTot . has ( s [ i ] ) ) { forTot . set ( s [ i ] , cost [ i ] ) ; } else { forTot . set ( s [ i ] , forTot . get ( s [ i ] ) + cost [ i ] ) } } forMax . forEach ( ( value , key ) => { ans += forTot . get ( key ) - value ; } ) ; return ans ; } var s = " " ; var cost = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; document . write ( delCost ( s , cost ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let MAX = 10000 ; let divisors = new Array ( MAX + 1 ) ; function computeDivisors ( ) { for ( let i = 1 ; i <= MAX ; i ++ ) { for ( let j = i ; j <= MAX ; j += i ) { divisors [ j ] . push ( i ) ; } } } function getClosest ( val1 , val2 , target ) { if ( target - val1 >= val2 - target ) return val2 ; else return val1 ; } function findClosest ( arr , n , target ) { if ( target <= arr [ 0 ] ) return arr [ 0 ] ; if ( target >= arr [ n - 1 ] ) return arr [ n - 1 ] ; let i = 0 , j = n , mid = 0 ; while ( i < j ) { mid = Math . floor ( ( i + j ) / 2 ) ; if ( arr [ mid ] == target ) return arr [ mid ] ; if ( target < arr [ mid ] ) { if ( mid > 0 && target > arr [ mid - 1 ] ) return getClosest ( arr [ mid - 1 ] , arr [ mid ] , target ) ; j = mid ; } else { if ( mid < n - 1 && target < arr [ mid + 1 ] ) return getClosest ( arr [ mid ] , arr [ mid + 1 ] , target ) ; i = mid + 1 ; } } return arr [ mid ] ; } function printClosest ( N , X ) { computeDivisors ( ) ; let ans = findClosest ( divisors [ N ] , divisors [ N ] . length , X ) ; document . write ( ans ) ; } let N = 16 , X = 5 ; for ( let i = 0 ; i < divisors . length ; i ++ ) divisors [ i ] = [ ] ; printClosest ( N , X ) ;

Index/key variables: N, i, j, mid
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxMatch ( A , B ) { var Aindex = { } ; var diff = { } ; for ( var i = 0 ; i < A . length ; i ++ ) { Aindex [ A [ i ] ] = i ; } for ( var i = 0 ; i < B . length ; i ++ ) { if ( i - Aindex [ B [ i ] ] < 0 ) { if ( ! diff . hasOwnProperty ( A . length + i - Aindex [ B [ i ] ] ) ) { diff [ A . length + i - Aindex [ B [ i ] ] ] = 1 ; } else { diff [ A . length + i - Aindex [ B [ i ] ] ] += 1 ; } } else { if ( ! diff . hasOwnProperty ( i - Aindex [ B [ i ] ] ) ) { diff [ i - Aindex [ B [ i ] ] ] = 1 ; } else { diff [ i - Aindex [ B [ i ] ] ] += 1 ; } } } var max = 0 ; for ( const [ key , value ] of Object . entries ( diff ) ) { if ( value > max ) { max = value ; } } return max ; } var A = [ 5 , 3 , 7 , 9 , 8 ] ; var B = [ 8 , 7 , 3 , 5 , 9 ] ; document . write ( maxMatch ( A , B ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var N = 9 ; function isinRange ( board ) { for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { if ( board [ i ] [ j ] <= 0 board [ i ] [ j ] > 9 ) { return false ; } } } return true ; } function isValidSudoku ( board ) { if ( isinRange ( board ) == false ) { return false ; } var unique = Array ( N + 1 ) . fill ( false ) ; for ( var i = 0 ; i < N ; i ++ ) { unique = Array ( N + 1 ) . fill ( false ) ; unique = Array ( N + 1 ) . fill ( false ) ; for ( var j = 0 ; j < N ; j ++ ) { var Z = board [ i ] [ j ] ; if ( unique [ Z ] ) { return false ; } unique [ Z ] = true ; } } for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { var Z = board [ j ] [ i ] ; if ( unique [ Z ] ) { return false ; } unique [ Z ] = true ; } } for ( var i = 0 ; i < N - 2 ; i += 3 ) { for ( var j = 0 ; j < N - 2 ; j += 3 ) { unique = Array ( N + 1 ) . fill ( false ) ; for ( var k = 0 ; k < 3 ; k ++ ) { for ( var l = 0 ; l < 3 ; l ++ ) { var X = i + k ; var Y = j + l ; var Z = board [ X ] [ Y ] ; if ( unique [ Z ] ) { return false ; } unique [ Z ] = true ; } } } } return true ; } var board = [ [ 7 , 9 , 2 , 1 , 5 , 4 , 3 , 8 , 6 ] , [ 6 , 4 , 3 , 8 , 2 , 7 , 1 , 5 , 9 ] , [ 8 , 5 , 1 , 3 , 9 , 6 , 7 , 2 , 4 ] , [ 2 , 6 , 5 , 9 , 7 , 3 , 8 , 4 , 1 ] , [ 4 , 8 , 9 , 5 , 6 , 1 , 2 , 7 , 3 ] , [ 3 , 1 , 7 , 4 , 8 , 2 , 9 , 6 , 5 ] , [ 1 , 3 , 6 , 7 , 4 , 8 , 5 , 9 , 2 ] , [ 9 , 7 , 4 , 2 , 1 , 5 , 6 , 3 , 8 ] , [ 5 , 2 , 8 , 6 , 3 , 9 , 4 , 1 , 7 ] ] ; if ( isValidSudoku ( board ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: X, Y, Z, i, j
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function palindrome ( a , i , j ) { while ( i < j ) { if ( a [ i ] != a [ j ] ) return false ; i ++ ; j -- ; } return true ; } function findSubArray ( arr , k ) { let n = arr . length ; for ( let i = 0 ; i <= n - k ; i ++ ) { if ( palindrome ( arr , i , i + k - 1 ) ) return i ; } return - 1 ; } let arr = [ 2 , 3 , 5 , 1 , 3 ] ; let k = 4 ; let ans = findSubArray ( arr , k ) ; if ( ans == - 1 ) document . write ( - 1 + " " ) ; else { for ( let i = ans ; i < ans + k ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function isCrossed ( path ) { if ( path . length == 0 ) return ; let ans = false ; let mySet = new Set ( ) ; let x = 0 , y = 0 ; mySet . add ( [ x , y ] ) ; for ( let i = 0 ; i < path . length ; i ++ ) { if ( path [ i ] == ' ' ) mySet . add ( [ x , y ++ ] ) ; if ( path [ i ] == ' ' ) mySet . add ( [ x , y -- ] ) ; if ( path [ i ] == ' ' ) mySet . add ( [ x ++ , y ] ) ; if ( path [ i ] == ' ' ) mySet . add ( [ x -- , y ] ) ; if ( ! mySet . has ( [ x , y ] ) ) { ans = true ; break ; } } if ( ans ) document . write ( " " ) ; else document . write ( " " ) ; } let path = " " ; isCrossed ( path ) ;

Index/key variables: i
Accumulator variables: i, x, y
Iterator variables: i
Boolean variables: ans
Javascript program:
function maxWidth ( N , M , cost , s ) { let adj = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { adj . push ( [ ] ) ; } for ( let i = 0 ; i < M ; i ++ ) { adj [ s [ i ] [ 0 ] ] . push ( s [ i ] [ 1 ] ) ; } let result = 0 ; let q = [ ] ; q . push ( 0 ) ; while ( q . length != 0 ) { let count = q . length ; result = Math . max ( count , result ) ; while ( count -- > 0 ) { let temp = q . shift ( ) ; for ( let i = 0 ; i < adj [ temp ] . length ; i ++ ) { q . push ( adj [ temp ] [ i ] ) ; } } } return result ; } let N = 11 , M = 10 ; let edges = [ ] ; edges . push ( [ 0 , 1 ] ) ; edges . push ( [ 0 , 2 ] ) ; edges . push ( [ 0 , 3 ] ) ; edges . push ( [ 1 , 4 ] ) ; edges . push ( [ 1 , 5 ] ) ; edges . push ( [ 3 , 6 ] ) ; edges . push ( [ 4 , 7 ] ) ; edges . push ( [ 6 , 10 ] ) ; edges . push ( [ 6 , 8 ] ) ; edges . push ( [ 6 , 9 ] ) ; let cost = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 2 , 6 , 12 , 7 ] ; document . write ( maxWidth ( N , M , cost , edges ) ) ;

Index/key variables: i, temp
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let MAX = 10000000 ; let isPrime = new Array ( MAX ) ; let primes = new Array ( ) ; function SieveOfEratosthenes ( ) { isPrime . fill ( true ) ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * p ; i <= MAX ; i += p ) isPrime [ i ] = false ; } } for ( let p = 2 ; p <= MAX ; p ++ ) if ( isPrime [ p ] ) primes . push ( p ) ; } function prime_search ( primes , diff ) { let low = 0 ; let high = primes . length - 1 ; let res = 0 ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( primes [ mid ] == diff ) { return primes [ mid ] ; } else if ( primes [ mid ] < diff ) { low = mid + 1 ; } else { res = primes [ mid ] ; high = mid - 1 ; } } return res ; } function minCost ( arr , n ) { SieveOfEratosthenes ( ) ; let res = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { let diff = arr [ i - 1 ] - arr [ i ] ; let closest_prime = prime_search ( primes , diff ) ; res += closest_prime ; arr [ i ] += closest_prime ; } } return res ; } let arr = [ 2 , 1 , 5 , 4 , 3 ] ; let n = 5 ; document . write ( minCost ( arr , n ) )

Index/key variables: i, mid, p
Accumulator variables: i, p, res
Iterator variables: i, p
Javascript program:
function count ( s ) { var cnt = 0 ; s . split ( ' ' ) . forEach ( c => { cnt += ( c == ' ' ) ? 1 : 0 ; } ) ; if ( cnt % 3 != 0 ) return 0 ; var res = 0 , k = parseInt ( cnt / 3 ) , sum = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) { sum += ( s [ i ] == ' ' ) ? 1 : 0 ; if ( sum == 2 * k && mp . has ( k ) && i < s . length - 1 && i > 0 ) { res += mp . get ( k ) ; } if ( mp . has ( sum ) ) mp . set ( sum , mp . get ( sum ) + 1 ) else mp . set ( sum , 1 ) ; } return res ; } var str = " " ; document . write ( count ( str ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, res, sum
Iterator variables: i
Javascript program:
function splitstring ( s ) { let n = s . length ; let zeros = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( s [ i ] == ' ' ) zeros ++ ; if ( zeros % 3 != 0 ) return 0 ; if ( zeros == 0 ) return parseInt ( ( ( n - 1 ) * ( n - 2 ) ) / 2 , 10 ) ; let zerosInEachSubstring = parseInt ( zeros / 3 , 10 ) ; let waysOfFirstCut = 0 ; let waysOfSecondCut = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) count ++ ; if ( count == zerosInEachSubstring ) waysOfFirstCut ++ ; else if ( count == 2 * zerosInEachSubstring ) waysOfSecondCut ++ ; } return waysOfFirstCut * waysOfSecondCut ; } let s = " " ; document . write ( " " + " " + splitstring ( s ) ) ;

Index/key variables: i
Accumulator variables: count, i, waysOfFirstCut, waysOfSecondCut, zeros
Iterator variables: i
Javascript program:
function canTransform ( str1 , str2 ) { var s1 = " " ; var s2 = " " ; for ( const c of str1 ) { if ( c !== " " ) { s1 += c ; } } for ( const c of str2 ) { if ( c !== " " ) { s2 += c ; } } if ( s1 !== s2 ) return false ; var i = 0 ; var j = 0 ; var n = str1 . length ; while ( i < n && j < n ) { if ( str1 [ i ] === " " ) { i ++ ; } else if ( str2 [ j ] === " " ) { j ++ ; } else { if ( ( str1 [ i ] === " " && i < j ) || ( str1 [ i ] === " " && i > j ) ) { return false ; } i ++ ; j ++ ; } } return true ; } var str1 = " " ; var str2 = " " ; if ( canTransform ( str1 . split ( " " ) , str2 . split ( " " ) ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j, s1, s2
Iterator variables: c
Javascript program:
function maxsubStringLength ( S , N ) { let arr = Array . from ( { length : N } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) if ( S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' ) arr [ i ] = 1 ; else arr [ i ] = - 1 ; let maxLen = 0 ; let curr_sum = 0 ; let hash = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { curr_sum += arr [ i ] ; if ( curr_sum == 0 ) maxLen = Math . max ( maxLen , i + 1 ) ; if ( hash . has ( curr_sum ) ) maxLen = Math . max ( maxLen , i - hash . get ( curr_sum ) ) ; else hash . set ( curr_sum , i ) ; } return maxLen ; } let S = " " ; let n = S . length ; document . write ( maxsubStringLength ( S . split ( ' ' ) , n ) ) ;

Index/key variables: i
Accumulator variables: curr_sum, i
Iterator variables: i
Javascript program:
let mat = new Array ( 1001 ) ; for ( let i = 0 ; i < 1001 ; i ++ ) { mat [ i ] = new Array ( 1001 ) ; for ( let j = 0 ; j < 1001 ; j ++ ) { mat [ i ] [ j ] = 0 ; } } let r , c , x , y ; let dx = [ 0 , - 1 , - 1 , - 1 , 0 , 1 , 1 , 1 ] ; let dy = [ 1 , 1 , 0 , - 1 , - 1 , - 1 , 0 , 1 ] ; function FindMinimumDistance ( ) { let q = [ ] ; q . push ( [ x , y ] ) ; mat [ x ] [ y ] = 0 ; while ( q . length > 0 ) { x = q [ 0 ] [ 0 ] ; y = q [ 0 ] [ 1 ] ; q . shift ( ) ; for ( let i = 0 ; i < 8 ; i ++ ) { let a = x + dx [ i ] ; let b = y + dy [ i ] ; if ( a < 0 a >= r b >= c b < 0 ) continue ; if ( mat [ a ] [ b ] == 0 ) { mat [ a ] [ b ] = mat [ x ] [ y ] + 1 ; q . push ( [ a , b ] ) ; } } } } r = 5 , c = 5 , x = 1 , y = 1 ; let t = x ; let l = y ; mat [ x ] [ y ] = 0 ; FindMinimumDistance ( ) ; mat [ t ] [ l ] = 0 ; for ( let i = 0 ; i < r ; i ++ ) { for ( let j = 0 ; j < c ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; }

Index/key variables: a, b, i, j, l, t, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minOperations ( S , K ) { var ans = 0 ; for ( var i = 0 ; i < K ; i ++ ) { var zero = 0 , one = 0 ; for ( var j = i ; j < S . length ; j += K ) { if ( S [ j ] === " " ) zero ++ ; else one ++ ; } ans += Math . min ( zero , one ) ; } return ans ; } var S = " " ; var K = 3 ; document . write ( minOperations ( S , K ) ) ;

Index/key variables: j
Accumulator variables: ans, i, j, one, zero
Iterator variables: i, j
Javascript program:
function missingElement ( arr , n ) { let max_ele = arr [ 0 ] ; let min_ele = arr [ 0 ] ; let x = 0 ; let d ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max_ele ) max_ele = arr [ i ] ; if ( arr [ i ] < min_ele ) min_ele = arr [ i ] ; } d = parseInt ( ( max_ele - min_ele ) / n , 10 ) ; for ( let i = 0 ; i < n ; i ++ ) { x = x ^ arr [ i ] ; } for ( let i = 0 ; i <= n ; i ++ ) { x = x ^ ( min_ele + ( i * d ) ) ; } return x ; } let arr = [ 12 , 3 , 6 , 15 , 18 ] ; let n = arr . length ; let element = missingElement ( arr , n ) ; document . write ( element ) ;

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