dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function solve ( n , str ) { let mymap = new Map ( ) ; let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { let c = str . charAt ( i ) ; if ( c == " " ) c = " " ; else if ( c == " " ) c = " " ; let c_int = parseInt ( c ) ; if ( mymap . has ( c_int ) ) mymap . set ( c_int , mymap . get ( c_int ) + 1 ) ; else mymap . set ( c_int , 1 ) ; } let rems = new Map ( ) ; while ( n > 0 ) { let rem = n % 10 ; if ( rem == 5 ) rem = 2 ; if ( rem == 9 ) rem = 6 ; if ( rems . has ( rem ) ) rems . set ( rem , rems . get ( rem ) + 1 ) ; else rems . set ( rem , 1 ) ; n = Math . floor ( n / 10 ) ; } let cnt = Number . MAX_SAFE_INTEGER ; for ( let ele of rems ) { let key = ele [ 0 ] ; if ( ! mymap . has ( key ) ) return 0 ; let temp = mymap . get ( key ) / ele [ 1 ] ; cnt = Math . min ( cnt , temp ) ; } return cnt ; } let N = 56 ; let M = " " ; document . write ( solve ( N , M ) ) ;

Accumulator variables: i
Iterator variables: ele, i
Javascript program:
var ansSwaps ; function check ( S ) { for ( var i = 1 ; i < S . length ; i ++ ) { if ( S [ i - 1 ] == S [ i ] ) { return false ; } } return true ; } function minimumSwaps ( S , swaps , idx ) { if ( check ( S ) ) { ansSwaps = Math . min ( ansSwaps , swaps ) ; } for ( var i = idx ; i < S . length ; i ++ ) { for ( var j = i + 1 ; j < S . length ; j ++ ) { swap ( S , i , j ) ; minimumSwaps ( S , swaps + 1 , i + 1 ) ; S = swap ( S , i , j ) ; } } } function swap ( arr , i , j ) { var temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } function findMinimumSwaps ( S ) { ansSwaps = Number . MAX_VALUE ; minimumSwaps ( S , 0 , 0 ) ; if ( ansSwaps == Number . MAX_VALUE ) document . write ( " " ) ; else document . write ( ansSwaps ) ; } var S = " " ; findMinimumSwaps ( S . split ( ' ' ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countOsBetween1s ( S , N , Q ) { let leftBound = new Array ( N ) ; let rightBound = new Array ( N ) ; let count = 0 ; let total = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { count = total ; } else if ( S [ i ] == ' ' ) { total ++ ; } rightBound [ i ] = count ; } count = 0 ; total = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == ' ' ) { count = total ; } else if ( S [ i ] == ' ' ) { total ++ ; } leftBound [ i ] = count ; } for ( let q = 0 ; q < 2 ; q ++ ) { let L = Q [ q ] [ 0 ] ; let R = Q [ q ] [ 1 ] ; count = leftBound [ L ] + rightBound [ R ] - total ; document . write ( count + " " ) ; } } let S = " " ; let Q = [ [ 0 , 4 ] , [ 0 , 5 ] ] ; let N = S . length ; countOsBetween1s ( S , N , Q ) ;

Index/key variables: L, R, i, q
Accumulator variables: i, q, total
Iterator variables: i, q
Javascript program:
let finalAns = " " ; class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function checkPalindrome ( s ) { let low = 0 , high = s . length - 1 ; while ( low < high ) { if ( s [ low ] != s [ high ] ) return false ; low ++ ; high -- ; } return true ; } function lexicographicallySmall ( root , s ) { if ( root == null ) return ; s += root . data ; if ( root . left == null && root . right == null ) { if ( checkPalindrome ( s ) ) { if ( finalAns == " " ) finalAns = s ; else finalAns = finalAns . localeCompare ( s ) <= 0 ? finalAns : s ; } return ; } lexicographicallySmall ( root . left , s ) ; lexicographicallySmall ( root . right , s ) ; } function getPalindromePath ( root ) { finalAns = " " ; lexicographicallySmall ( root , " " ) ; if ( finalAns == " " ) document . write ( " " ) ; else document . write ( finalAns ) ; } let root = newNode ( ' ' ) ; root . left = newNode ( ' ' ) ; root . left . left = newNode ( ' ' ) ; root . left . right = newNode ( ' ' ) ; root . right = newNode ( ' ' ) ; root . right . left = newNode ( ' ' ) ; root . right . right = newNode ( ' ' ) ; root . right . left . right = newNode ( ' ' ) ; getPalindromePath ( root ) ;

Index/key variables: high, low
Accumulator variables: high, low, s
Class/struct names: Node
Javascript program:
let MaxValue = 2147483647 ; function balanced ( small , caps ) { for ( let i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && ( caps [ i ] == 0 ) ) return false ; else if ( ( small [ i ] == 0 ) && ( caps [ i ] != 0 ) ) return false ; } return true ; } function smallestBalancedSubstring ( s ) { let small = new Array ( 26 ) ; let i ; let caps = new Array ( 26 ) ; small . fill ( 0 ) ; caps . fill ( 0 ) ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] . charCodeAt ( ) >= 65 && s [ i ] . charCodeAt ( ) <= 90 ) caps [ s [ i ] . charCodeAt ( ) - 65 ] ++ ; else small [ s [ i ] . charCodeAt ( ) - 97 ] ++ ; } let mp = new Map ( ) ; for ( i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && caps [ i ] == 0 ) { mp . set ( String . fromCharCode ( i + 97 ) , 1 ) ; } else if ( caps [ i ] != 0 && small [ i ] == 0 ) mp . set ( String . fromCharCode ( i + 65 ) , 1 ) ; } small . fill ( 0 ) ; caps . fill ( 0 ) ; i = 0 ; let st = 0 ; let start = - 1 , end = - 1 ; let minm = MaxValue ; while ( i < s . length ) { if ( mp . has ( s [ i ] ) ) { while ( st < i ) { if ( s [ st ] . charCodeAt ( ) >= 65 && s [ st ] . charCodeAt ( ) <= 90 ) caps [ s [ st ] . charCodeAt ( ) - 65 ] -- ; else small [ s [ st ] . charCodeAt ( ) - 97 ] -- ; st ++ ; } i += 1 ; st = i ; } else { if ( s [ i ] . charCodeAt ( ) >= 65 && s [ i ] . charCodeAt ( ) <= 90 ) caps [ s [ i ] . charCodeAt ( ) - 65 ] ++ ; else small [ s [ i ] . charCodeAt ( ) - 97 ] ++ ; while ( true ) { if ( s [ st ] . charCodeAt ( ) >= 65 && s [ st ] . charCodeAt ( ) <= 90 && caps [ s [ st ] . charCodeAt ( ) - 65 ] > 1 ) { caps [ s [ st ] . charCodeAt ( ) - 65 ] -- ; st ++ ; } else if ( s [ st ] . charCodeAt ( ) >= 97 && s [ st ] . charCodeAt ( ) <= 122 && small [ s [ st ] . charCodeAt ( ) - 97 ] > 1 ) { small [ s [ st ] . charCodeAt ( ) - 97 ] -- ; st ++ ; } else break ; } if ( balanced ( small , caps ) ) { if ( minm > ( i - st + 1 ) ) { minm = i - st + 1 ; start = st ; end = i ; } } i += 1 ; } } if ( start == - 1 end == - 1 ) document . write ( - 1 + " " ) ; else { let ans = " " ; for ( let j = start ; j <= end ; j ++ ) ans += s [ j ] ; document . write ( ans + " " ) ; } } let s = " " ; smallestBalancedSubstring ( s ) ;

Index/key variables: i, j, st
Accumulator variables: ans, i, j, st
Iterator variables: i, j
Javascript program:
class TrieNode { constructor ( ) { this . child = Array ( 256 ) ; } } ; function insertTrie ( root , str ) { var M = str . length ; for ( var i = 0 ; i < M ; i ++ ) { if ( root . child [ str [ i ] ] == null ) { root . child [ str [ i ] ] = new TrieNode ( ) ; } root = root . child [ str [ i ] ] ; } } function findStrLen ( root , str ) { var M = str . length ; var len = 0 ; for ( var i = 0 ; i < M ; i ++ ) { if ( root . child [ str [ i ] ] != null ) { len ++ ; root = root . child [ str [ i ] ] ; } else { return len ; } } return len ; } function findMaxLenPair ( arr , N ) { var idx = - 1 ; var len = 0 ; var root = new TrieNode ( ) ; insertTrie ( root , arr [ 0 ] ) ; for ( var i = 1 ; i < N ; i ++ ) { var temp = findStrLen ( root , arr [ i ] ) ; if ( temp > len ) { len = temp ; idx = i ; } insertTrie ( root , arr [ i ] ) ; } for ( var i = 0 ; i < N ; i ++ ) { var M = arr [ i ] . length ; if ( i != idx && M >= len ) { var found = true ; for ( var j = 0 ; j < len ; j ++ ) { if ( arr [ i ] [ j ] != arr [ idx ] [ j ] ) { found = false ; break ; } } if ( found ) { document . write ( " " + arr [ i ] + " " + arr [ idx ] + " " ) ; return ; } } } } var arr = [ " " , " " , " " ] ; var N = arr . length ; findMaxLenPair ( arr , N ) ;

Index/key variables: i, idx, j
Accumulator variables: i, j, len
Iterator variables: i, j
Boolean variables: found
Class/struct names: TrieNode
Javascript program:
function isScramble ( S1 , S2 ) { if ( S1 . length != S2 . length ) { return false ; } let n = S1 . length ; if ( n == 0 ) { return true ; } if ( S1 == S2 ) { return true ; } let tempArray1 = S1 . split ( ' ' ) ; let tempArray2 = S2 . split ( ' ' ) ; tempArray1 . sort ( ) ; tempArray2 . sort ( ) ; let copy_S1 = tempArray1 . join ( " " ) ; let copy_S2 = tempArray2 . join ( " " ) ; if ( copy_S1 != copy_S2 ) { return false ; } for ( let i = 1 ; i < n ; i ++ ) { if ( isScramble ( S1 . substring ( 0 , i ) , S2 . substring ( 0 , i ) ) && isScramble ( S1 . substring ( i , i + n ) , S2 . substring ( i , i + n ) ) ) { return true ; } if ( isScramble ( S1 . substring ( n - i , n - i + n ) , S2 . substring ( 0 , i ) ) && isScramble ( S1 . substring ( 0 , n - i ) , S2 . substring ( i , i + n ) ) ) { return true ; } } return false ; } let S1 = " " ; let S2 = " " ; if ( isScramble ( S1 , S2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: i
Iterator variables: i
Javascript program:
function bcdToDecimal ( s ) { let len = s . length ; let check = 0 , check0 = 0 ; let num = 0 , sum = 0 ; let mul = 1 , rev = 0 ; for ( let i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - ' ' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum == 0 && check0 == 0 ) { num = 1 ; check0 = 1 ; } else { num = num * 10 + sum ; } check = 0 ; sum = 0 ; mul = 1 ; } } while ( num > 0 ) { rev = rev * 10 + ( num % 10 ) ; num = Math . floor ( num / 10 ) ; } if ( check0 == 1 ) return rev - 1 ; return rev ; } let s = " " ; document . write ( bcdToDecimal ( s . split ( ' ' ) ) ) ;

Index/key variables: i
Accumulator variables: check, i, mul, sum
Iterator variables: i
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = this . right = null ; } } class Count { constructor ( ) { this . count = 0 ; } } var root ; var ct = new Count ( ) ; function countSingleRec ( node , c ) { if ( node == null ) return true ; var left = countSingleRec ( node . left , c ) ; var right = countSingleRec ( node . right , c ) ; if ( left == false right == false ) return false ; if ( node . left != null && node . data != node . left . data ) return false ; if ( node . right != null && node . data != node . right . data ) return false ; c . count ++ ; return true ; } function countSingle ( ) { return countSingle ( root ) ; } function countSingle ( node ) { countSingleRec ( node , ct ) ; return ct . count ; } root = new Node ( 5 ) ; root . left = new Node ( 4 ) ; root . right = new Node ( 5 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 4 ) ; root . right . right = new Node ( 5 ) ; document . write ( " " + countSingle ( root ) ) ;

Accumulator variables: count
Class/struct names: Count, Node
Javascript program:
function strBitwiseXOR ( arr , n ) { var result = " " ; var max_len = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { max_len = Math . max ( max_len , arr [ i ] . length ) ; arr [ i ] = arr [ i ] . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; } for ( var i = 0 ; i < n ; i ++ ) { var s ; for ( var j = 0 ; j < max_len - arr [ i ] . length ; j ++ ) s += ' ' ; arr [ i ] = arr [ i ] + s ; } for ( var i = 0 ; i < max_len ; i ++ ) { var pres_bit = 0 ; for ( var j = 0 ; j < n ; j ++ ) pres_bit = pres_bit ^ ( arr [ j ] [ i ] - ' ' . charCodeAt ( 0 ) ) ; result += ( pres_bit + ' ' . charCodeAt ( 0 ) ) ; } result = result . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; document . write ( result ) ; } var arr = [ " " , " " , " " ] ; var n = arr . length ; strBitwiseXOR ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j, result, s
Iterator variables: i, j
Javascript program:
var sticks = [ 6 , 7 , 4 , 6 , 5 , 4 , 6 , 5 , 2 , 4 , 4 , 3 , 6 , 6 , 6 , 5 , 7 , 6 , 5 , 3 , 5 , 4 , 6 , 4 , 3 , 4 ] var number = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ; function countSticks ( str ) { var cnt = 0 ; for ( var i = 0 ; str [ i ] ; i ++ ) { var ch = str [ i ] ; if ( ch >= ' ' && ch <= ' ' ) { cnt += sticks [ ch . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; } else { cnt += number [ ch . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; } } return cnt ; } var str = " " ; document . write ( countSticks ( str ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function remainingDigit ( S , N ) { let c = S . split ( " " ) ; let del = [ 0 , 0 ] ; let count = [ 0 , 0 ] ; let q = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { let x = ( c [ i ] == ' ' ? 1 : 0 ) ; count [ x ] ++ ; q . push ( x ) ; } while ( count [ 0 ] > 0 && count [ 1 ] > 0 ) { let t = q . shift ( ) ; if ( del [ t ] > 0 ) { del [ t ] -- ; count [ t ] -- ; } else { del [ t ^ 1 ] ++ ; q . push ( t ) ; } } if ( count [ 0 ] > 0 ) return " " ; return " " ; } let S = " " ; let N = S . length ; document . write ( remainingDigit ( S , N ) ) ;

Index/key variables: i, t, x
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( key ) { this . key = key ; this . left = this . right = null ; } } class Distance { constructor ( ) { this . minDis = Number . MAX_VALUE ; } } var root ; function findLeafDown ( root , lev , minDist ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( lev < ( minDist . minDis ) ) minDist . minDis = lev ; return ; } findLeafDown ( root . left , lev + 1 , minDist ) ; findLeafDown ( root . right , lev + 1 , minDist ) ; } function findThroughParent ( root , x , minDist ) { if ( root == null ) return - 1 ; if ( root == x ) return 0 ; var l = findThroughParent ( root . left , x , minDist ) ; if ( l != - 1 ) { findLeafDown ( root . right , l + 2 , minDist ) ; return l + 1 ; } var r = findThroughParent ( root . right , x , minDist ) ; if ( r != - 1 ) { findLeafDown ( root . left , r + 2 , minDist ) ; return r + 1 ; } return - 1 ; } function minimumDistance ( root , x ) { d = new Distance ( ) ; findLeafDown ( x , 0 , d ) ; findThroughParent ( root , x , d ) ; return d . minDis ; } root = new Node ( 1 ) ; root . left = new Node ( 12 ) ; root . right = new Node ( 13 ) ; root . right . left = new Node ( 14 ) ; root . right . right = new Node ( 15 ) ; root . right . left . left = new Node ( 21 ) ; root . right . left . right = new Node ( 22 ) ; root . right . right . left = new Node ( 23 ) ; root . right . right . right = new Node ( 24 ) ; root . right . left . left . left = new Node ( 1 ) ; root . right . left . left . right = new Node ( 2 ) ; root . right . left . right . left = new Node ( 3 ) ; root . right . left . right . right = new Node ( 4 ) ; root . right . right . left . left = new Node ( 5 ) ; root . right . right . left . right = new Node ( 6 ) ; root . right . right . right . left = new Node ( 7 ) ; root . right . right . right . right = new Node ( 8 ) ; x = root . right ; document . write ( " " + x . key + " " + minimumDistance ( root , x ) ) ;

Class/struct names: Distance, Node
Javascript program:
function getTime ( s , n ) { let res = " " ; let h = parseInt ( s . substring ( 0 , 0 + 2 ) ) ; let m = parseInt ( s . substring ( 3 , 3 + 2 ) ) ; let rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; let rev_hs = ( rev_h ) . toString ( ) ; if ( h == 23 && m >= 32 ) { res = " " ; } else if ( m < rev_h ) { let temp = " " ; if ( h < 10 ) temp = " " ; temp = temp + h . toString ( ) ; if ( rev_h < 10 ) res = res + temp + " " + rev_hs ; else res = res + temp + " " + rev_hs ; } else { h ++ ; rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; rev_hs = ( rev_h ) . toString ( ) ; let temp = " " ; if ( h < 10 ) temp = " " ; temp = temp + h . toString ( ) ; if ( rev_h < 10 ) res = res + temp + " " + rev_hs ; else res = res + temp + " " + rev_hs ; } return res ; } let s = " " ; let n = s . length ; document . write ( getTime ( s , n ) ) ;

Accumulator variables: h
Javascript program:
function CountSubstring ( str , n ) { var ans = parseInt ( ( n * ( n + 1 ) ) / 2 ) ; var a_index = 0 ; var b_index = 0 ; var c_index = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] === " " ) { a_index = i + 1 ; ans -= Math . min ( b_index , c_index ) ; } else if ( str [ i ] === " " ) { b_index = i + 1 ; ans -= Math . min ( a_index , c_index ) ; } else { c_index = i + 1 ; ans -= Math . min ( a_index , b_index ) ; } } return ans ; } var str = " " . split ( " " ) ; var n = str . length ; document . write ( CountSubstring ( str , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function isValid ( str , len ) { for ( let i = 1 ; i < len ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) return false ; } return true ; } let str = " " ; let len = str . length ; if ( isValid ( str , len ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( s , K ) { for ( var ch = 0 ; ch < 26 ; ch ++ ) { var c = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + ch ) ; var last = - 1 ; var found = true ; for ( var i = 0 ; i < K ; i ++ ) if ( s [ i ] == c ) last = i ; if ( last == - 1 ) continue ; for ( var i = K ; i < s . length ; i ++ ) { if ( s [ i ] == c ) last = i ; if ( last <= ( i - K ) ) { found = false ; break ; } } if ( found ) return 1 ; } return 0 ; } function binarySearch ( s ) { var low = 1 , high = s . length ; var ans ; while ( low <= high ) { var mid = ( high + low ) >> 1 ; if ( check ( s , mid ) ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } var s = " " ; document . write ( binarySearch ( s ) + " " ) ; s = " " ; document . write ( binarySearch ( s ) ) ;

Index/key variables: i
Accumulator variables: ch, i
Iterator variables: ch, i
Boolean variables: found
Javascript program:
const seg = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ; function LedRequired ( s , led ) { var count = 0 ; for ( var i = 0 ; i < s . length ; ++ i ) { count += seg [ ( s [ i ] ) - 48 ] ; } if ( count <= led ) return " " ; else return " " ; } var S = " " ; var led = 20 ; document . write ( LedRequired ( S , led ) + " " ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Javascript program:
function vowel_calc ( s ) { var n = s . length ; var arr = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( i == 0 ) arr . push ( n ) ; else arr . push ( ( n - i ) + arr [ i - 1 ] - i ) ; } var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) sum += arr [ i ] ; return sum ; } var s = " " ; document . write ( vowel_calc ( s ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function find ( s1 , s2 ) { var len = s1 . length , len_1 = s2 . length ; if ( len != len_1 ) return false ; var d = Array ( len ) . fill ( 0 ) ; d [ 0 ] = s2 [ 0 ] - s1 [ 0 ] ; for ( var i = 1 ; i < len ; i ++ ) { if ( s1 [ i ] > s2 [ i ] ) return false ; else { d [ i ] = s2 [ i ] - s1 [ i ] ; } } for ( var i = 0 ; i < len - 1 ; i ++ ) { if ( d [ i ] < d [ i + 1 ] ) return false ; } return true ; } var s1 = " " , s2 = " " ; if ( find ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function NthCharacter ( n ) { let s = " " ; let c = 1 ; for ( let i = 1 ; ; i ++ ) { if ( c < 10 ) s += c . toString ( ) ; else { let s1 = " " ; let dup = c ; while ( dup > 0 ) { s1 += ( dup % 10 ) . toString ( ) ; dup = Math . floor ( dup / 10 ) ; } s1 = s1 . split ( " " ) . reverse ( ) . join ( " " ) ; s += s1 ; } c ++ ; if ( s . length >= n ) { return s [ n - 1 ] ; } } } let n = 11 ; document . write ( NthCharacter ( n ) ) ;

Accumulator variables: c, i, s, s1
Iterator variables: i
Javascript program:
function solve ( s , k ) { var count = 0 , length = 0 , pos = 0 ; var m = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( ! m . has ( s [ i ] ) ) { m . set ( s [ i ] , 0 ) ; } m . set ( s [ i ] , m . get ( s [ i ] ) + 1 ) ; length ++ ; if ( length > k ) { if ( ! m . has ( s [ pos ] ) ) { m . set ( s [ pos ] , 0 ) ; } m . set ( s [ pos ] , m [ s [ pos ] ] - 1 ) ; pos += 1 ; length -- ; } if ( length == k && m . get ( s [ i ] ) == length ) count ++ ; } document . write ( count ) ; } var s = " " ; var k = 4 ; solve ( s , k ) ;

Index/key variables: i, pos
Accumulator variables: count, i, pos
Iterator variables: i
Javascript program:
var str = " " ; var newStr = str . split ( " " ) ; for ( var i = 0 ; i < newStr . length ; ++ i ) { if ( newStr [ i ] === " " ) { newStr [ i ] = " " ; } } document . write ( newStr . join ( " " ) + " " ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
let MAX = Number . MAX_VALUE ; let m = new Map ( ) ; let Min = Number . MAX_VALUE ; function minOperation ( s , i , j , count ) { if ( ( i >= s . length && j < 0 ) || ( i == j ) ) { return MAX ; } if ( s [ i ] == s [ j ] || ( count >= Min ) ) { return count ; } let str = ( i ) . toString ( ) + " " + ( j ) . toString ( ) ; if ( ! m . has ( str ) ) { if ( i >= s . length ) { m . set ( str , minOperation ( s , i , j - 1 , count + 1 ) ) ; } else if ( j < 0 ) { m . set ( str , minOperation ( s , i + 1 , j , count + 1 ) ) ; } else { m . set ( str , Math . min ( minOperation ( s , i , j - 1 , count + 1 ) , minOperation ( s , i + 1 , j , count + 1 ) ) ) ; } } if ( m . get ( str ) < Min ) { Min = m . get ( str ) ; } return m . get ( str ) ; } let s = " " ; let ans = minOperation ( s , 0 , s . length - 1 , 0 ) ; if ( ans == MAX ) { document . write ( - 1 ) ; } else { document . write ( ans ) ; }

Index/key variables: i, j
Javascript program:
function solve ( n , l ) { if ( l < 3 ) { if ( parseInt ( n ) % 8 === 0 ) return true ; n = reverse ( n ) ; if ( parseInt ( n ) % 8 === 0 ) return true ; return false ; } var hash = new Array ( 10 ) . fill ( 0 ) ; for ( var i = 0 ; i < l ; i ++ ) hash [ parseInt ( n [ i ] ) - 0 ] ++ ; for ( var i = 104 ; i < 1000 ; i += 8 ) { var dup = i ; var freq = new Array ( 10 ) . fill ( 0 ) ; freq [ parseInt ( dup % 10 ) ] ++ ; dup = dup / 10 ; freq [ parseInt ( dup % 10 ) ] ++ ; dup = dup / 10 ; freq [ parseInt ( dup % 10 ) ] ++ ; dup = i ; if ( freq [ parseInt ( dup % 10 ) ] > hash [ parseInt ( dup % 10 ) ] ) continue ; dup = dup / 10 ; if ( freq [ parseInt ( dup % 10 ) ] > hash [ parseInt ( dup % 10 ) ] ) continue ; dup = dup / 10 ; if ( freq [ parseInt ( dup % 10 ) ] > hash [ parseInt ( dup % 10 ) ] ) continue ; return true ; } return false ; } function reverse ( input ) { var a = input . split ( " " ) ; var l , r = 0 ; r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { var temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( " " ) ; } var number = " " ; var l = number . length ; if ( solve ( number , l ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r
Iterator variables: i, l
Javascript program:
function newString ( s , k ) { var X = " " ; while ( s . length > 0 ) { var temp = s [ 0 ] ; for ( var i = 1 ; i < k && i < s . length ; i ++ ) { if ( s [ i ] < temp ) { temp = s [ i ] ; } } X = X + temp ; for ( var i = 0 ; i < k ; i ++ ) { if ( s [ i ] === temp ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; break ; } } } return X ; } var s = " " ; var k = 3 ; document . write ( newString ( s , k ) ) ;

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