dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function subsequence ( s , binary , len ) { let sub = " " ; for ( let j = 0 ; j < len ; j ++ ) if ( binary & ( 1 << j ) ) sub += s [ j ] ; return sub ; } function possibleSubsequences ( s ) { let sorted_subsequence = new Map ( ) ; let len = s . length ; let limit = Math . pow ( 2 , len ) ; for ( let i = 1 ; i <= limit - 1 ; i ++ ) { let sub = subsequence ( s , i , len ) ; if ( ! sorted_subsequence . has ( sub . length ) ) sorted_subsequence . set ( sub . length , new Set ( ) ) ; sorted_subsequence . get ( sub . length ) . add ( sub ) ; } for ( let it of sorted_subsequence ) { document . write ( " " + it [ 0 ] + " " + " " ) ; for ( let ii of it [ 1 ] ) document . write ( ii + " " ) ; document . write ( " " ) ; } } let s = " " ; possibleSubsequences ( s ) ;

Index/key variables: j
Accumulator variables: i, j, sub
Iterator variables: i, ii, it, j
Javascript program:
function remainder ( str ) { let len = str . length ; let num ; let rem = 0 ; for ( let i = 0 ; i < len ; i ++ ) { num = rem * 10 + ( str [ i ] - ' ' ) ; rem = num % 11 ; } return rem ; } let str = " " ; document . write ( remainder ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function longestSubseq ( s ) { let n = s . length ; let pre_count_0 = new Array ( n + 2 ) ; let pre_count_1 = new Array ( n + 1 ) ; let post_count_0 = new Array ( n + 2 ) ; pre_count_0 [ 0 ] = 0 ; post_count_0 [ n + 1 ] = 0 ; pre_count_1 [ 0 ] = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { pre_count_0 [ j ] = pre_count_0 [ j - 1 ] ; pre_count_1 [ j ] = pre_count_1 [ j - 1 ] ; post_count_0 [ n - j + 1 ] = post_count_0 [ n - j + 2 ] ; if ( s [ j - 1 ] == ' ' ) pre_count_0 [ j ] ++ ; else pre_count_1 [ j ] ++ ; if ( s [ n - j ] == ' ' ) post_count_0 [ n - j + 1 ] ++ ; } if ( pre_count_0 [ n ] == n pre_count_0 [ n ] == 0 ) return n ; let ans = 0 ; for ( let i = 1 ; i <= n ; i ++ ) for ( let j = i ; j <= n ; j ++ ) ans = Math . max ( pre_count_0 [ i - 1 ] + pre_count_1 [ j ] - pre_count_1 [ i - 1 ] + post_count_0 [ j + 1 ] , ans ) ; return ans ; } let s = " " ; document . write ( longestSubseq ( s ) ) ;

Index/key variables: j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function shouldSwap ( str , start , curr ) { for ( let i = start ; i < curr ; i ++ ) { if ( str [ i ] == str [ curr ] ) { return false ; } } return true ; } function findPermutations ( str , index , n ) { if ( index >= n ) { document . write ( str ) ; document . write ( " " ) return ; } for ( let i = index ; i < n ; i ++ ) { let check = shouldSwap ( str , index , i ) ; if ( check ) { swap ( str , index , i ) ; findPermutations ( str , index + 1 , n ) ; swap ( str , index , i ) ; } } } function swap ( str , i , j ) { let c = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = c ; } let str = [ ' ' , ' ' , ' ' , ' ' ] ; let n = str . length ; findPermutations ( str , 0 , n ) ;

Index/key variables: curr, i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function findPermutations ( str , index , n ) { if ( index >= n index + 1 >= n ) { document . write ( str . join ( " " ) + " " ) ; return ; } findPermutations ( str , index + 1 , n ) ; swap ( str , index ) ; findPermutations ( str , index + 2 , n ) ; swap ( str , index ) ; } function swap ( arr , index ) { var temp = arr [ index ] ; arr [ index ] = arr [ index + 1 ] ; arr [ index + 1 ] = temp ; } var str = " " . split ( " " ) ; var n = str . length ; findPermutations ( str , 0 , n ) ;

Index/key variables: index
Javascript program:
function decodeMedianString ( s ) { var l = s . length ; var s1 = " " ; var isEven = ( l % 2 == 0 ) ? true : false ; for ( i = 0 ; i < l ; i += 2 ) { if ( isEven ) { s1 = s . charAt ( i ) + s1 ; s1 += s . charAt ( i + 1 ) ; } else { if ( l - i > 1 ) { s1 += s . charAt ( i ) ; s1 = s . charAt ( i + 1 ) + s1 ; } else { s1 += s . charAt ( i ) ; } } } return s1 ; } var s = " " ; document . write ( decodeMedianString ( s ) ) ;

Accumulator variables: i, s1
Iterator variables: i
Javascript program:
function maximumChars ( str ) { let n = str . length ; let res = - 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) res = Math . max ( res , Math . abs ( j - i - 1 ) ) ; return res ; } let str = " " ; document . write ( maximumChars ( str ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX_CHAR = 256 ; function maximumChars ( str ) { let n = str . length ; let res = - 1 ; let firstInd = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) firstInd [ i ] = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { let first_ind = firstInd [ str [ i ] . charCodeAt ( 0 ) ] ; if ( first_ind == - 1 ) firstInd [ str [ i ] . charCodeAt ( 0 ) ] = i ; else res = Math . max ( res , Math . abs ( i - first_ind - 1 ) ) ; } return res ; } let str = " " ; document . write ( maximumChars ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isUnique ( a , n , k ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += a [ i ] ; sum += n - 1 ; return ( sum == k ) ; } var a = [ 3 , 3 , 3 ] ; var n = a . length ; var k = 12 ; if ( isUnique ( a , n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function nextWord ( s ) { if ( s == " " ) return " " ; var i = s . length - 1 ; while ( s [ i ] == ' ' && i >= 0 ) i -- ; if ( i == - 1 ) s = s + ' ' ; else s [ i ] = String . fromCharCode ( s [ i ] . charCodeAt ( 0 ) + 1 ) ; return s . join ( ' ' ) ; } var str = " " . split ( ' ' ) ; document . write ( nextWord ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function isValid ( p ) { var n = p . length ; var c1 = 0 , c0 = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( p [ i ] == ' ' ) c0 ++ ; if ( p [ i ] == ' ' ) c1 ++ ; } return ( c0 == c1 ) ? true : false ; } function longestSub ( s ) { var max_len = 0 ; var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { if ( isValid ( s . substr ( i , j - i + 1 ) ) && max_len < j - i + 1 ) max_len = j - i + 1 ; } } return max_len ; } var s = " " ; document . write ( longestSub ( s ) ) ;

Index/key variables: i
Accumulator variables: c0, c1, i, j
Iterator variables: i, j
Javascript program:
function isPalindrome ( s , i , j ) { let p = j ; for ( let k = i ; k <= p ; k ++ ) { if ( s [ k ] != s [ p ] ) return false ; p -- ; } return true ; } function countWays ( s ) { let n = s . length ; let count = 0 ; if ( isPalindrome ( s , 0 , n - 1 ) ) { for ( let i = n / 2 ; i < n ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) count ++ ; else break ; } { count ++ ; } else } else { for ( let i = 0 ; i < n / 2 ; i ++ ) { if ( s [ i ] != s [ n - 1 - i ] ) { let j = n - 1 - i ; if ( isPalindrome ( s , i , n - 2 - i ) ) { for ( let k = i - 1 ; k >= 0 ; k -- ) { if ( s [ k ] != s [ j ] ) break ; count ++ ; } count ++ ; } if ( isPalindrome ( s , i + 1 , n - 1 - i ) ) { for ( let k = n - i ; k < n ; k ++ ) { if ( s [ k ] != s [ i ] ) break ; count ++ ; } count ++ ; } break ; } } } return count ; } let s = " " ; document . write ( countWays ( s ) ) ;

Index/key variables: i, j, k, p
Accumulator variables: count, i, k, p
Iterator variables: i, k
Javascript program:
function countOfSubstringWithKOnes ( s , K ) { let N = s . length ; let res = 0 ; let countOfOne = 0 ; let freq = new Array ( N + 1 ) ; freq . fill ( 0 ) ; freq [ 0 ] = 1 ; for ( let i = 0 ; i < N ; i ++ ) { countOfOne += ( s [ i ] - ' ' ) ; if ( countOfOne >= K ) { res += freq [ countOfOne - K ] ; } freq [ countOfOne ] ++ ; } return res ; } let s = " " ; let K = 1 ; document . write ( countOfSubstringWithKOnes ( s , K ) ) ;

Index/key variables: countOfOne, i
Accumulator variables: countOfOne, i, res
Iterator variables: i
Javascript program:
var MAX_CHAR = 256 ; function printDuo ( str ) { var countChar = Array ( MAX_CHAR ) . fill ( 0 ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) countChar [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var str1 = " " , str2 = " " ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) { if ( countChar [ i ] > 1 ) str2 = str2 + String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; else if ( countChar [ i ] == 1 ) str1 = str1 + String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; } document . write ( " " + " " ) ; document . write ( str1 + " " ) ; document . write ( " " + " " ) ; document . write ( str2 + " " ) ; } var str = " " ; printDuo ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function reverse ( num , i , j ) { while ( i < j ) { var temp = num [ i ] ; num [ i ] = num [ j ] ; num [ j ] = temp ; i ++ ; j -- ; } } function nextPalin ( num , n ) { if ( n <= 3 ) { document . write ( " " ) ; return ; } var temp ; var mid = n / 2 - 1 ; var i , j ; for ( i = mid - 1 ; i >= 0 ; i -- ) if ( num [ i ] < num [ i + 1 ] ) break ; if ( i < 0 ) { document . write ( " " ) ; return ; } var smallest = i + 1 ; for ( j = i + 2 ; j <= mid ; j ++ ) if ( num [ j ] > num [ i ] && num [ j ] <= num [ smallest ] ) smallest = j ; temp = num [ i ] ; num [ i ] = num [ smallest ] ; num [ smallest ] = temp ; temp = num [ n - i - 1 ] ; num [ n - i - 1 ] = num [ n - smallest - 1 ] ; num [ n - smallest - 1 ] = temp ; reverse ( num , i + 1 , mid ) ; if ( n % 2 == 0 ) reverse ( num , mid + 1 , n - i - 2 ) ; else reverse ( num , mid + 2 , n - i - 2 ) ; var result = num . join ( ' ' ) ; document . write ( " " + result ) ; } var str = " " ; var num = str . split ( ' ' ) ; var n = str . length ; nextPalin ( num , n ) ;

Index/key variables: i, j, smallest
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX_CHAR = 256 ; function isPossible ( s1 , s2 ) { let count = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < s2 . length ; i ++ ) count [ s2 [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( count [ s1 [ i ] . charCodeAt ( 0 ) ] == 0 ) return false ; count [ s1 [ i ] . charCodeAt ( 0 ) ] -- ; } return true ; } let s1 = " " , s2 = " " ; if ( isPossible ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nextHighUsingAtMostOneSwap ( st ) { var num = st . split ( ' ' ) ; var l = num . length ; var posRMax = l - 1 ; var index = - 1 ; for ( var i = l - 2 ; i >= 0 ; i -- ) { if ( num [ i ] >= num [ posRMax ] ) posRMax = i ; else { index = i ; break ; } } if ( index == - 1 ) return " " ; var greatSmallDgt = - 1 ; for ( var i = l - 1 ; i > index ; i -- ) { if ( num [ i ] > num [ index ] ) { if ( greatSmallDgt == - 1 ) greatSmallDgt = i ; else if ( num [ i ] <= num [ greatSmallDgt ] ) greatSmallDgt = i ; } } var temp = num [ index ] ; num [ index ] = num [ greatSmallDgt ] ; num [ greatSmallDgt ] = temp ; return ( num . join ( ' ' ) ) ; } var num = " " ; document . write ( " " + num ) ; document . write ( " " + nextHighUsingAtMostOneSwap ( num ) ) ;

Index/key variables: greatSmallDgt, i, index, posRMax
Accumulator variables: i
Iterator variables: i
Javascript program:
function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function longestVowel ( str ) { let count = 0 , res = 0 ; let s = str . split ( " " ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) count ++ ; else { res = Math . max ( res , count ) ; count = 0 ; } } return Math . max ( res , count ) ; } let s = " " ; document . write ( longestVowel ( s ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let MAX_CHAR = 26 ; function check ( freq , k ) { for ( let i = 0 ; i < MAX_CHAR ; i ++ ) if ( freq [ i ] != 0 && freq [ i ] != k ) return false ; return true ; } function substrings ( s , k ) { let res = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { let freq = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let j = i ; j < s . length ; j ++ ) { let index = s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; freq [ index ] ++ ; if ( freq [ index ] > k ) break ; else if ( freq [ index ] == k && check ( freq , k ) == true ) res ++ ; } } return res ; } let s = " " ; let k = 2 ; document . write ( substrings ( s , k ) + " " ) ; s = " " ; k = 2 ; document . write ( substrings ( s , k ) + " " ) ;

Index/key variables: i, index, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function have_same_frequency ( freq , k ) { for ( let i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] != 0 && freq [ i ] != k ) { return false ; } } return true ; } function count_substrings ( s , k ) { let count = 0 ; let distinct = 0 ; let have = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { have [ i ] = false ; } for ( let i = 0 ; i < s . length ; i ++ ) { have [ ( ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ] = true ; } for ( let i = 0 ; i < 26 ; i ++ ) { if ( have [ i ] ) { distinct ++ ; } } for ( let length = 1 ; length <= distinct ; length ++ ) { let window_length = length * k ; let freq = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) freq [ i ] = 0 ; let window_start = 0 ; let window_end = window_start + window_length - 1 ; for ( let i = window_start ; i <= Math . min ( window_end , s . length - 1 ) ; i ++ ) { freq [ ( ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ] ++ ; } while ( window_end < s . length ) { if ( have_same_frequency ( freq , k ) ) { count ++ ; } freq [ ( ( s [ window_start ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ] -- ; window_start ++ ; window_end ++ ; if ( window_end < s . length ) { freq [ ( s [ window_end ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ] ++ ; } } } return count ; } let s = " " ; let k = 2 ; document . write ( count_substrings ( s , k ) + " " ) ; s = " " ; k = 2 ; document . write ( count_substrings ( s , k ) + " " ) ;

Index/key variables: i, window_end, window_start
Accumulator variables: count, distinct, i, window_end, window_start
Iterator variables: i
Javascript program:
let MAX_CHARS = 26 ; function longestSubseqWithK ( str , k ) { let n = str . length ; let freq = new Array ( MAX_CHARS ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 } for ( let i = 0 ; i < n ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] >= k ) { document . write ( str [ i ] ) ; } } } let str = " " ; let k = 2 ; longestSubseqWithK ( str , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function generate ( st , s ) { if ( s . length == 0 ) return st ; if ( ! st . has ( s ) ) { st . add ( s ) ; for ( let i = 0 ; i < s . length ; i ++ ) { let t = s ; t = t . substr ( 0 , i ) + t . substr ( i + 1 ) ; st = generate ( st , t ) ; } } return st ; } let s = " " ; let st = new Set ( ) ; st = generate ( st , s ) ; let str = ' ' ; console . log ( st ) for ( item of st . values ( ) ) str += item + ' ' document . write ( str ) ;

Accumulator variables: i, str
Iterator variables: i
Javascript program:
function countSubstrs ( str , i , j , n ) { if ( n == 1 ) return 1 ; if ( n <= 0 ) return 0 ; let res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ; if ( str [ i ] == str [ j ] ) res ++ ; return res ; } let str = " " ; let n = str . length ; document . write ( countSubstrs ( str , 0 , n - 1 , n ) ) ;

Index/key variables: i, j
Accumulator variables: res
Javascript program:
function countManipulations ( s1 , s2 ) { let count = 0 ; let char_count = new Array ( 26 ) ; for ( let i = 0 ; i < char_count . length ; i ++ ) { char_count [ i ] = 0 ; } for ( let i = 0 ; i < s1 . length ; i ++ ) char_count [ s1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < s2 . length ; i ++ ) { char_count [ s2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; } for ( let i = 0 ; i < 26 ; ++ i ) { if ( char_count [ i ] != 0 ) { count += Math . abs ( char_count [ i ] ) ; } } return count ; } let s1 = " " ; let s2 = " " ; document . write ( countManipulations ( s1 , s2 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let MAX_CHAR = 26 ; function leastCount ( s1 , s2 , n ) { let count1 = new Array ( MAX_CHAR ) ; let count2 = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { count1 [ i ] = 0 ; count2 [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { count1 [ s1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; count2 [ s2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let res = 0 ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { if ( count1 [ i ] != 0 ) { res += Math . abs ( count1 [ i ] - count2 [ i ] ) ; } } return res ; } let s1 = " " ; let s2 = " " ; let len = s1 . length ; let res = leastCount ( s1 , s2 , len ) ; document . write ( res ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
var MAX_CHAR = 26 ; function stringPalindrome ( A , B ) { var countA = Array . from ( { length : MAX_CHAR } , ( _ , i ) => 0 ) ; var countB = Array . from ( { length : MAX_CHAR } , ( _ , i ) => 0 ) ; var l1 = A . length ; var l2 = B . length ; for ( var i = 0 ; i < l1 ; i ++ ) countA [ A . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < l2 ; i ++ ) countB [ B . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < 26 ; i ++ ) if ( ( countA [ i ] > 1 && countB [ i ] == 0 ) ) return ' ' ; return ' ' ; } var a = " " ; var b = " " ; document . write ( stringPalindrome ( a , b ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printLCSubStr ( X , Y , m , n ) { let LCSuff = new Array ( m + 1 ) ; let len = 0 ; let row = 0 , col = 0 ; for ( let i = 0 ; i <= m ; i ++ ) { LCSuff [ i ] = Array ( n + 1 ) ; for ( let j = 0 ; j <= n ; j ++ ) { LCSuff [ i ] [ j ] = 0 ; if ( i == 0 j == 0 ) LCSuff [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) { LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ; if ( len < LCSuff [ i ] [ j ] ) { len = LCSuff [ i ] [ j ] ; row = i ; col = j ; } } else LCSuff [ i ] [ j ] = 0 ; } } if ( len == 0 ) { document . write ( " " ) ; return ; } let resultStr = " " ; while ( LCSuff [ row ] [ col ] != 0 ) { -- len ; row -- ; col -- ; } document . write ( resultStr ) ; } let X = " " ; let Y = " " ; let m = X . length ; let n = Y . length ; printLCSubStr ( X , Y , m , n ) ;

Index/key variables: col, i, j, row
Accumulator variables: col, i, j, row
Iterator variables: i, j
Javascript program:
function substringConversions ( str , k , b ) { for ( let i = 0 ; i + k <= str . length ; i ++ ) { let sub = str . substring ( i , i + k ) ; let sum = 0 , counter = 0 ; for ( let j = sub . length - 1 ; j >= 0 ; j -- ) { sum = ( sum + ( ( sub [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * Math . pow ( b , counter ) ) ) ; counter ++ ; } document . write ( sum + " " ) ; } } let str = " " ; let b = 3 , k = 3 ; substringConversions ( str , b , k ) ;

Index/key variables: j
Accumulator variables: counter, i, j
Iterator variables: i, j
Javascript program:
var MAX_CHAR = 256 ; function countBalance ( str ) { var leftVisited = Array ( MAX_CHAR ) . fill ( 0 ) ; var rightVisited = Array ( MAX_CHAR ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) rightVisited [ str [ i ] . charCodeAt ( 0 ) ] ++ ; var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) { leftVisited [ str [ i ] . charCodeAt ( 0 ) ] ++ ; rightVisited [ str [ i ] . charCodeAt ( 0 ) ] -- ; var j ; for ( j = 0 ; j < MAX_CHAR ; j ++ ) { if ( ( leftVisited [ j ] == 0 && rightVisited [ j ] != 0 ) || ( leftVisited [ j ] != 0 && rightVisited [ j ] == 0 ) ) break ; } if ( j == MAX_CHAR ) res ++ ; } return res ; } var str = " " ; document . write ( countBalance ( str ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function findFlips ( str , n ) { var last = ' ' ; var res = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( last != str . charAt ( i ) ) res ++ ; last = str . charAt ( i ) ; } return parseInt ( res / 2 ) ; } var str = " " ; var n = str . length ; document . write ( findFlips ( str , n ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function findLen ( A , n , k , ch ) { let maxlen = 1 ; let cnt = 0 ; let l = 0 , r = 0 ; while ( r < n ) { if ( A [ r ] != ch ) ++ cnt ; while ( cnt > k ) { if ( A [ l ] != ch ) -- cnt ; ++ l ; } maxlen = Math . max ( maxlen , r - l + 1 ) ; ++ r ; } return maxlen ; } function answer ( A , n , k ) { let maxlen = 1 ; for ( let i = 0 ; i < 26 ; ++ i ) { maxlen = Math . max ( maxlen , findLen ( A , n , k , String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) ) ; maxlen = Math . max ( maxlen , findLen ( A , n , k , String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) ) ; } return maxlen ; } let n = 5 , k = 2 ; let A = " " ; document . write ( " " + answer ( A , n , k ) + " " ) ; n = 6 ; k = 4 ; let B = " " ; document . write ( " " + answer ( B , n , k ) ) ;

Index/key variables: l, r
Iterator variables: i
Javascript program:
function allCharactersSame ( s ) { let s1 = new Set ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { s1 . add ( s [ i ] ) ; } if ( s1 . size == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } let str = " " ; allCharactersSame ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printMinIndexChar ( str , patt ) { let minIndex = Number . MAX_VALUE ; let m = str . length ; let n = patt . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( patt [ i ] == str [ j ] && j < minIndex ) { minIndex = j ; break ; } } } if ( minIndex != Number . MAX_VALUE ) document . write ( " " + str [ minIndex ] ) ; else document . write ( " " ) ; } let str = " " ; let patt = " " ; printMinIndexChar ( str , patt ) ;

Index/key variables: i, j, minIndex
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printMinIndexChar ( str , patt ) { let hm = new Map ( ) ; let minIndex = Number . MAX_VALUE ; let m = str . length ; let n = patt . length ; for ( let i = 0 ; i < m ; i ++ ) if ( ! hm . has ( str [ i ] ) ) hm . set ( str [ i ] , i ) ; for ( let i = 0 ; i < n ; i ++ ) if ( hm . has ( patt [ i ] ) && hm . get ( patt [ i ] ) < minIndex ) minIndex = hm . get ( patt [ i ] ) ; if ( minIndex != Number . MAX_VALUE ) document . write ( " " + str [ minIndex ] ) ; else document . write ( " " ) ; } let str = " " ; let patt = " " ; printMinIndexChar ( str , patt ) ;

Index/key variables: i, minIndex
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX_CHAR = 26 ; function checkCorrectOrNot ( s ) { let count1 = new Array ( MAX_CHAR ) ; let count2 = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { count1 [ i ] = 0 ; count2 [ i ] = 0 ; } let n = s . length ; if ( n == 1 ) return true ; for ( let i = 0 , j = n - 1 ; i < j ; i ++ , j -- ) { count1 [ s [ i ] - ' ' ] ++ ; count2 [ s [ j ] - ' ' ] ++ ; } for ( let i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ; return true ; } let s = " " ; if ( checkCorrectOrNot ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

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