dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findMin ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( sum + 1 ) ; for ( let j = 0 ; j <= sum ; j ++ ) { if ( j == 0 ) dp [ i ] [ j ] = true ; } } for ( let i = 1 ; i <= sum ; i ++ ) dp [ 0 ] [ i ] = false ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= sum ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; if ( arr [ i - 1 ] <= j ) dp [ i ] [ j ] |= dp [ i - 1 ] [ j - arr [ i - 1 ] ] ; } } let diff = Number . MAX_VALUE ; for ( let j = Math . floor ( sum / 2 ) ; j >= 0 ; j -- ) { if ( dp [ n ] [ j ] == true ) { diff = sum - 2 * j ; break ; } } return diff ; } let arr = [ 3 , 1 , 4 , 2 , 2 , 1 ] ; let n = arr . length ; document . write ( " " + findMin ( arr , n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
let MAX = 1000 ; let dp = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = 0 ; } } function minSizeRec ( arr , low , high , k ) { if ( dp [ low ] [ high ] != - 1 ) { return dp [ low ] [ high ] ; } if ( ( high - low + 1 ) < 3 ) { return high - low + 1 ; } let res = 1 + minSizeRec ( arr , low + 1 , high , k ) ; for ( let i = low + 1 ; i <= high - 1 ; i ++ ) { for ( let j = i + 1 ; j <= high ; j ++ ) { if ( arr [ i ] == ( arr [ low ] + k ) && arr [ j ] == ( arr [ low ] + 2 * k ) && minSizeRec ( arr , low + 1 , i - 1 , k ) == 0 && minSizeRec ( arr , i + 1 , j - 1 , k ) == 0 ) { res = Math . min ( res , minSizeRec ( arr , j + 1 , high , k ) ) ; } } } return ( dp [ low ] [ high ] = res ) ; } function minSize ( arr , n , k ) { for ( let i = 0 ; i < MAX ; i ++ ) { for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return minSizeRec ( arr , 0 , n - 1 , k ) ; } let arr = [ 2 , 3 , 4 , 5 , 6 , 4 ] ; let n = arr . length ; let k = 1 ; document . write ( minSize ( arr , n , k ) ) ;

Index/key variables: high, i, j, low
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countSol ( coeff , start , end , rhs ) { if ( rhs == 0 ) return 1 ; let result = 0 ; for ( let i = start ; i <= end ; i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ; return result ; } let coeff = [ 2 , 2 , 5 ] ; let rhs = 4 ; let n = coeff . length ; document . write ( countSol ( coeff , 0 , n - 1 , rhs ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function getMaxRec ( str , i , n , lookup ) { if ( i >= n ) { return 0 ; } if ( lookup [ i ] != - 1 ) { return lookup [ i ] ; } let ans = 1 + getMaxRec ( str , i + 1 , n , lookup ) ; if ( i + 1 < n ) { if ( str [ i ] != str [ i + 1 ] ) { ans = Math . max ( 4 + getMaxRec ( str , i + 2 , n , lookup ) , ans ) ; } else { ans = Math . max ( 3 + getMaxRec ( str , i + 2 , n , lookup ) , ans ) ; } } return lookup [ i ] = ans ; } function getMaxWeight ( str ) { let n = str . length ; let lookup = new Array ( n ) ; lookup . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { lookup [ i ] = - 1 ; } return getMaxRec ( str , 0 , str . length , lookup ) ; } let str = " " ; document . write ( " " + " " + str + " " + getMaxWeight ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function possibleEqualArray ( A , N ) { var tot_XOR = 0 ; for ( var i = 0 ; i < N ; i ++ ) { tot_XOR ^= A [ i ] ; } if ( tot_XOR == 0 ) { document . write ( " " ) ; return ; } var cur_XOR = 0 ; var cnt = 0 ; for ( var i = 0 ; i < N ; i ++ ) { cur_XOR ^= A [ i ] ; if ( cur_XOR == tot_XOR ) { cnt ++ ; cur_XOR = 0 ; } } if ( cnt > 2 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var A = [ 0 , 2 , 2 ] ; var N = ( A . length ) ; possibleEqualArray ( A , N ) ;

Index/key variables: i
Accumulator variables: cnt, cur_XOR, i, tot_XOR
Iterator variables: i
Javascript program:
function countPalindromes ( S ) { var N = S . length ; var Z = Array ( N ) . fill ( 0 ) ; var l = 0 , r = 0 ; for ( var i = 1 ; i < N ; i ++ ) { if ( i <= r ) Z [ i ] = Math . min ( r - i + 1 , Z [ i - l ] ) ; while ( i + Z [ i ] < N && S [ Z [ i ] ] == S [ i + Z [ i ] ] ) { Z [ i ] ++ ; } if ( i + Z [ i ] - 1 > r ) { l = i ; r = i + Z [ i ] - 1 ; } } var sum = 0 ; for ( var i = 0 ; i < Z . length ; i ++ ) { sum += Z [ i ] + 1 ; } return sum ; } var S = " " ; document . write ( countPalindromes ( S ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function printSubsInDelimeters ( str ) { let dels = [ ] ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { dels . push ( i ) ; } else if ( ( str [ i ] == ' ' ) && ( dels . length > 0 ) ) { let pos = dels [ dels . length - 1 ] ; dels . pop ( ) ; let len = i - 1 - pos ; let ans ; if ( pos < len ) { ans = str . substring ( pos + 1 , len + 1 ) ; } else { ans = str . substring ( pos + 1 , len + pos + 1 ) ; } document . write ( ans + " " ) ; } } } let str = " " ; printSubsInDelimeters ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function printDiagonalTraversal ( nums ) { let m = nums . length ; let q = [ ] ; q . push ( new pair ( 0 , 0 ) ) ; while ( q . length != 0 ) { let p = q [ 0 ] ; q . shift ( ) ; document . write ( nums [ p . first ] [ p . second ] + " " ) ; if ( p . second == 0 && p . first + 1 < m ) { q . push ( new pair ( p . first + 1 , p . second ) ) ; } if ( p . second + 1 < nums [ p . first ] . length ) q . push ( new pair ( p . first , p . second + 1 ) ) ; } } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; printDiagonalTraversal ( arr ) ;

Class/struct names: pair
Javascript program:
function restore ( arr , N ) { var result = [ ] ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( ! mp . has ( arr [ i ] ) ) { result . push ( arr [ i ] ) ; mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } } return result ; } function print_result ( result ) { for ( var i = 0 ; i < result . length ; i ++ ) { document . write ( result [ i ] + " " ) ; } } var arr = [ 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 ] ; var N = arr . length ; print_result ( restore ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function restore ( arr , N ) { let result = [ ] ; let count1 = 1 ; let s = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { s . add ( arr [ i ] ) ; if ( s . size == count1 ) { result . push ( arr [ i ] ) ; count1 ++ ; } } return result ; } function print_result ( result ) { for ( let i = 0 ; i < result . length ; i ++ ) document . write ( result [ i ] + " " ) ; } let arr = [ 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 ] ; let N = arr . length ; print_result ( restore ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count1, i
Iterator variables: i
Javascript program:
function sum ( n ) { return n * parseInt ( ( n - 1 ) / 2 ) ; } function BSpattern ( N ) { var Val = 0 , Pthree = 0 , cnt = 0 , initial ; var s = " " ; for ( var i = 0 ; i < N ; i ++ ) { cnt = 0 ; if ( i > 0 ) { document . write ( s ) ; s += " " ; } for ( var j = i ; j < N ; j ++ ) { if ( i > 0 ) { cnt ++ ; } document . write ( ++ Val ) ; document . write ( 0 ) ; } if ( i == 0 ) { var Sumbeforelast = sum ( Val ) * 2 ; Pthree = Val + Sumbeforelast + 1 ; initial = Pthree ; } initial = initial - cnt ; Pthree = initial ; for ( var k = i ; k < N ; k ++ ) { document . write ( Pthree ++ ) ; if ( k != N - 1 ) { document . write ( 0 ) ; } } document . write ( " " ) ; } } var N = 5 ; BSpattern ( N ) ;

Accumulator variables: Pthree, cnt, i, j, k, s
Iterator variables: i, j, k
Javascript program:
function checkprefix ( A , B ) { var s1 = A . toString ( ) ; var s2 = B . toString ( ) ; var n1 = s1 . length ; var n2 = s2 . length ; if ( n1 < n2 ) { return false ; } for ( var i = 0 ; i < n2 ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { return false ; } } return true ; } var A = 12345 , B = 12 ; var result = checkprefix ( A , B ) ; if ( result ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let a = new Array ( 65 ) ; a . fill ( 0 ) ; function Count ( i ) { if ( i == 0 ) return 1 ; else if ( i < 0 ) return 0 ; if ( a [ i ] == 0 ) { a [ i ] = ( i + 1 ) + 2 * Count ( i - 1 ) ; return a [ i ] ; } else return a [ i ] ; } function solve ( n ) { let i , sum = 0 ; while ( n > 0 ) { i = parseInt ( Math . log ( n ) / Math . log ( 2 ) , 10 ) ; n = n - parseInt ( Math . pow ( 2 , i ) , 10 ) ; sum = sum + ( i + 1 ) + Count ( i - 1 ) ; } return sum ; } let n = 7 ; document . write ( solve ( n ) ) ;

Index/key variables: i
Javascript program:
function findPalindrome ( C ) { var S = C ; S = reverse ( S ) ; C = C + " " + S ; var n = C . length ; var longestPalindrome = new Array ( n ) . fill ( 0 ) ; longestPalindrome [ 0 ] = 0 ; var len = 0 ; var i = 1 ; while ( i < n ) { if ( C [ i ] === C [ len ] ) { len ++ ; longestPalindrome [ i ] = len ; i ++ ; } else { if ( len !== 0 ) { len = longestPalindrome [ len - 1 ] ; } else { longestPalindrome [ i ] = 0 ; i ++ ; } } } var ans = C . substring ( 0 , longestPalindrome [ n - 1 ] ) ; return ans ; } function findAns ( s ) { var A = " " ; var B = " " ; var F = " " ; var i = 0 ; var j = s . length - 1 ; var len = s . length ; while ( i < j && s [ i ] === s [ j ] ) { i = i + 1 ; j = j - 1 ; } if ( i > 0 ) { A = s . substring ( 0 , i ) ; B = s . substring ( len - i , len ) ; } if ( len > 2 * i ) { var C = s . substring ( i , i + ( s . length - 2 * i ) ) ; var D = findPalindrome ( C ) ; C = reverse ( C ) ; var E = findPalindrome ( C ) ; if ( D . length > E . length ) { F = D ; } else { F = E ; } } var answer = A + F + B ; return answer ; } function reverse ( input ) { var a = input . split ( " " ) ; var r = a . length - 1 ; for ( var l = 0 ; l < r ; l ++ , r -- ) { var temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( " " ) ; } var str = " " ; document . write ( findAns ( str ) ) ;

Index/key variables: i, j, l, len, r
Accumulator variables: i, l, len, r
Iterator variables: l
Javascript program:
function nthTerm ( N ) { let nth = 0 , first_term = 4 ; let pi = 1 , po = 1 ; let n = N ; while ( n > 1 ) { pi *= n - 1 ; n -- ; po *= 2 ; } nth = ( first_term * pi ) / po ; return nth ; } let N = 5 ; document . write ( nthTerm ( N ) ) ;

Accumulator variables: n, pi, po
Javascript program:
function finalNum ( arr , n ) { var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { result = __gcd ( result , arr [ i ] ) ; } return result ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var arr = [ 3 , 9 , 6 , 36 ] ; var n = arr . length ; document . write ( finalNum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isVowel ( ch ) { switch ( ch ) { case " " : case " " : case " " : case " " : case " " : return true ; } return false ; } function isSatisfied ( str , n ) { for ( var i = 1 ; i < n ; i ++ ) { if ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) ) { return false ; } } for ( var i = 1 ; i < n - 1 ; i ++ ) { if ( isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) && ! isVowel ( str [ i + 1 ] ) ) { return false ; } } return true ; } var str = " " ; var n = str . length ; if ( isSatisfied ( str . split ( " " ) , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LengthlongestPrefixSuffix ( s ) { var n = s . length ; var lps = Array . from ( { length : n } , ( _ , i ) => 0 ) ; lps [ 0 ] = 0 ; var len = 0 ; var i = 1 ; while ( i < n ) { if ( s . charAt ( i ) == s . charAt ( len ) ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } var res = lps [ n - 1 ] ; return ( res > n / 2 ) ? n / 2 : res ; } function longestPrefixSuffix ( s ) { var len = LengthlongestPrefixSuffix ( s ) ; var prefix = " " ; for ( var i = 0 ; i < len ; i ++ ) prefix += s . charAt ( i ) ; return prefix ; } var s = " " ; var ans = longestPrefixSuffix ( s ) ; if ( ans == " " ) document . write ( " " ) ; else document . write ( ans ) ;

Index/key variables: i
Accumulator variables: i, len, prefix
Iterator variables: i
Javascript program:
function no_of_characters ( M ) { let k = 1 ; while ( true ) { if ( Math . pow ( 2 , k + 1 ) - 2 < M ) k ++ ; else break ; } return k ; } function print_string ( M ) { let k , num , N ; k = no_of_characters ( M ) ; N = M - ( Math . pow ( 2 , k ) - 2 ) ; while ( k > 0 ) { num = Math . pow ( 2 , k - 1 ) ; if ( num >= N ) document . write ( " " ) ; else { document . write ( " " ) ; N -= num ; } k -- ; } document . write ( " " ) ; } let M ; M = 30 ; print_string ( M ) ; M = 55 ; print_string ( M ) ; M = 100 ; print_string ( M ) ;

Accumulator variables: N, k
Javascript program:
function updateString ( S , A , B ) { let l = A . length ; for ( let i = 0 ; i + l <= S . length ; i ++ ) { let curr = S . substring ( i , i + l ) ; if ( curr == A ) { let new_string = S . substring ( 0 , i ) + B + S . substring ( i + l ) ; S = new_string ; i += l - 1 ; } else { let new_string = S . substring ( 0 , i ) + A + S . substring ( i + l ) ; S = new_string ; i += l - 1 ; } } return S ; } let S = " " ; let A = " " ; let B = " " ; document . write ( updateString ( S , A , B ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printPattern ( n , m ) { if ( m > 2 * ( n + 1 ) m < n - 1 ) { document . write ( " " ) ; } else if ( Math . abs ( n - m ) <= 1 ) { while ( n > 0 && m > 0 ) { document . write ( " " ) ; n -- ; m -- ; } if ( n != 0 ) { document . write ( " " ) ; } if ( m != 0 ) { document . write ( " " ) ; } } else { while ( m - n > 1 && n > 0 ) { document . write ( " " ) ; m = m - 2 ; n = n - 1 ; } while ( n > 0 ) { document . write ( " " ) ; n -- ; m -- ; } while ( m > 0 ) { document . write ( " " ) ; m -- ; } } } var n = 4 , m = 8 ; printPattern ( n , m ) ;

Accumulator variables: m, n
Javascript program:
function countDecreasing ( A , n ) { var len = 1 ; for ( var i = 0 ; i < n - 1 ; ++ i ) { if ( A [ i + 1 ] < A [ i ] ) len ++ ; else { cnt += parseInt ( ( ( len - 1 ) * len ) / 2 ) ; len = 1 ; } } if ( len > 1 ) cnt += parseInt ( ( ( len - 1 ) * len ) / 2 ) ; return cnt ; } var A = [ 100 , 3 , 1 , 13 ] ; var n = A . length ; document . write ( countDecreasing ( A , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Javascript program:
function minimumChar ( S1 , S2 ) { let n = S1 . length ; let m = S2 . length ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < m - n + 1 ; i ++ ) { let minRemovedChar = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( S1 [ j ] != S2 [ i + j ] ) { minRemovedChar ++ ; } } ans = Math . min ( minRemovedChar , ans ) ; } return ans ; } let S1 = " " ; let S2 = " " ; document . write ( minimumChar ( S1 , S2 ) ) ;

Index/key variables: j
Accumulator variables: i, j, minRemovedChar
Iterator variables: i, j
Javascript program:
let mod = 100000007 ; function countFreq ( pat , txt ) { let M = pat . length ; let N = txt . length ; let res = 0 ; for ( let i = 0 ; i <= N - M ; i ++ ) { let j ; for ( j = 0 ; j < M ; j ++ ) { if ( txt [ i + j ] != pat [ j ] ) { break ; } } if ( j == M ) { res ++ ; j = 0 ; } } return res ; } let txt = " " ; let pat = " " ; document . write ( countFreq ( pat , txt ) ) ;

Index/key variables: j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function findMissingDigit ( a , b , c ) { let w = 1 ; let a_mod_11 = 0 ; for ( let i = a . length - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( a [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; w = w * - 1 ; } let b_mod_11 = 0 ; w = 1 ; for ( let i = b . length - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( b [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; w = w * - 1 ; } let c_mod_11 = 0 ; let xSignIsPositive = true ; w = 1 ; for ( let i = c . length - 1 ; i >= 0 ; i -- ) { if ( c [ i ] == ' ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( c [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; } w = w * - 1 ; } let x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( ! xSignIsPositive ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } let A = " " ; let B = " " ; let C = " " ; document . write ( findMissingDigit ( A , B , C ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: xSignIsPositive
Javascript program:
function findIfPossible ( N , str ) { let countG = 0 , countF = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) countG ++ ; else countF ++ ; } if ( 2 * countF != countG ) { document . write ( " " ) ; } else { let id = 0 ; let flag = true ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { countG -- ; id ++ ; } else { countF -- ; id -- ; } if ( id < 0 ) { flag = false ; break ; } if ( countG < countF ) { flag = false ; break ; } } if ( flag ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } let n = 6 ; let str = " " ; findIfPossible ( n , str ) ;

Index/key variables: i
Accumulator variables: countF, countG, i, id
Iterator variables: i
Boolean variables: flag
Javascript program:
function isPossible ( str1 , str2 ) { let arr = new Array ( 256 ) . fill ( 0 ) ; let l1 = str1 . length ; let l2 = str2 . length ; let i , j ; let possible = true ; for ( i = 0 ; i < l1 ; i ++ ) { arr [ str1 [ i ] ] = 1 ; } for ( i = 0 ; i < l2 ; i ++ ) { if ( str2 [ i ] != " " ) { if ( arr [ str2 [ i ] ] == 1 ) continue ; else { possible = false ; break ; } } } if ( possible ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str1 = " " ; let str2 = " " ; isPossible ( str1 , str2 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: possible
Javascript program:
function find_Min_Inversion ( n , s1 , s2 ) { let count = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( s1 [ i ] = ' ' ) { s1 [ i ] = ' ' ; } else { s1 [ i ] = ' ' ; } if ( s1 [ i + 1 ] = ' ' ) { s1 [ i + 1 ] = ' ' ; } else { s1 [ i + 1 ] = ' ' ; } count ++ ; } } if ( s1 != s2 ) { return count ; } return - 1 ; } let n = 4 ; let s1 = " " ; let s2 = " " ; document . write ( find_Min_Inversion ( n , s1 , s2 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findSubsequence ( S , ch ) { let N = S . length ; let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ch ) { ans ++ ; ch = String . fromCharCode ( ch . charCodeAt ( 0 ) + 1 ) ; } } return ans ; } function findMaxSubsequence ( S ) { let ans = 0 ; for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) { ans = Math . max ( ans , findSubsequence ( S , String . fromCharCode ( ch ) ) ) ; } return ans ; } let S = " " ; document . write ( findMaxSubsequence ( S ) ) ;

Index/key variables: i
Accumulator variables: ans, ch, i
Iterator variables: ch, i
Javascript program:
function minOpsToEmptyString ( s ) { var ans = Number . MIN_VALUE ; var cn0 = 0 ; var cn1 = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { if ( cn1 > 0 ) cn1 -- ; cn0 ++ ; } else { if ( cn0 > 0 ) cn0 -- ; cn1 ++ ; } ans = Math . max ( ans , Math . max ( cn0 , cn1 ) ) ; } document . write ( ans ) ; } var S = " " ; minOpsToEmptyString ( S ) ;

Accumulator variables: cn0, cn1, i
Iterator variables: i
Javascript program:
function shortestString ( S , N ) { let st = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( st > 0 && S [ i ] == ' ' ) { st -- ; } else { st ++ ; } } return st ; } let S = " " ; let N = S . length ; document . write ( shortestString ( S , N ) ) ;

Index/key variables: i
Accumulator variables: i, st
Iterator variables: i
Javascript program:
function findLength ( str , n ) { let pre = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let post = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { pre [ i ] = 0 ; post [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { if ( i != 0 ) { pre [ i ] += pre [ i - 1 ] ; } if ( str [ i ] == ' ' ) { pre [ i ] += 1 ; } } for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( i != n - 1 ) post [ i ] += post [ i + 1 ] ; if ( str [ i ] == ' ' ) post [ i ] += 1 ; } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , pre [ i ] + post [ i ] ) ; } return ans ; } let S = " " ; document . write ( findLength ( S , S . length ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubstring ( S , N ) { var prevSum = new Map ( ) ; var res = 0 ; var currentSum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] >= ' ' && S [ i ] <= ' ' ) { currentSum ++ ; } else currentSum -- ; if ( currentSum == 0 ) res ++ ; if ( prevSum . has ( currentSum ) ) { res += ( prevSum . get ( currentSum ) ) ; } if ( prevSum . has ( currentSum ) ) prevSum . set ( currentSum , prevSum . get ( currentSum ) + 1 ) else prevSum . set ( currentSum , 1 ) } return res ; } var S = " " ; document . write ( countSubstring ( S , S . length ) ) ;

Index/key variables: i
Accumulator variables: currentSum, i, res
Iterator variables: i
Javascript program:
function subString ( s , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var len = i + 1 ; len <= n ; len ++ ) { var test_str = s . substring ( i , len ) ; var res = { } ; var temp = test_str . split ( " " ) ; for ( const keys of temp ) { res [ keys ] = ( res [ keys ] ? res [ keys ] : 0 ) + 1 ; } var flag = 0 ; for ( const [ key , value ] of Object . entries ( res ) ) { if ( res [ key ] % 2 != 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) count += 1 ; } } return count ; } var S = " " ; var N = S . length ; document . write ( subString ( S , N ) ) ;

Index/key variables: key, keys
Accumulator variables: count, i, len
Iterator variables: i, keys, len
Javascript program:
function countStringPairs ( a , n ) { var ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { var p = a [ i ] ; var q = a [ j ] ; if ( p [ 0 ] !== q [ 0 ] ) { p = p . split ( " " ) ; q = q . split ( " " ) ; var temp = p [ 0 ] ; p [ 0 ] = q [ 0 ] ; q [ 0 ] = temp ; p = p . join ( " " ) ; q = q . join ( " " ) ; var flag1 = 0 ; var flag2 = 0 ; for ( let k = 0 ; k < n ; k ++ ) { if ( a [ k ] === p ) flag1 = 1 ; if ( a [ k ] === q ) flag2 = 1 ; } if ( flag1 === 0 && flag2 === 0 ) { ans = ans + 1 ; } } } } document . write ( ans ) ; } var arr = [ " " , " " , " " ] ; var N = arr . length ; countStringPairs ( arr , N ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function addFrequencyToCharacter ( s ) { var frequency = new Array ( 26 ) . fill ( 0 ) ; var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) { frequency [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] += 1 ; } for ( var i = 0 ; i < n ; i ++ ) { var add = frequency [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] % 26 ; if ( s [ i ] . charCodeAt ( 0 ) + add <= " " . charCodeAt ( 0 ) ) s [ i ] = String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) + add ) ; else { add = s [ i ] . charCodeAt ( 0 ) + add - " " . charCodeAt ( 0 ) ; s [ i ] = String . fromCharCode ( " " . charCodeAt ( 0 ) + add - 1 ) ; } } document . write ( s . join ( " " ) + " " ) ; } var str = " " ; addFrequencyToCharacter ( str . split ( " " ) ) ;

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