dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countSubstrings ( str , K ) { var N = str . length ; var answer = 0 ; var map = new Map ( ) ; for ( var i = 0 ; i < K ; i ++ ) { if ( map . has ( str [ i ] ) ) map . set ( str [ i ] , map . get ( str [ i ] ) + 1 ) else map . set ( str [ i ] , 1 ) } if ( map . size == K ) answer ++ ; for ( var i = K ; i < N ; i ++ ) { if ( map . has ( str [ i ] ) ) map . set ( str [ i ] , map . get ( str [ i ] ) + 1 ) else map . set ( str [ i ] , 1 ) if ( map . has ( str [ i - K ] ) ) map . set ( str [ i - K ] , map . get ( str [ i - K ] ) - 1 ) if ( map . has ( str [ i - K ] ) && map . get ( str [ i - K ] ) == 0 ) { map . delete ( str [ i - K ] ) ; } if ( map . size == K ) { answer ++ ; } } return answer ; } var str = " " ; var K = 3 ; document . write ( countSubstrings ( str , K ) ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
let mp = new Map ( ) ; 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 copy_S1 = S1 , copy_S2 = S2 ; let t1 = copy_S1 . split ( ' ' ) let t2 = copy_S2 . split ( ' ' ) t1 . sort ( ) ; t2 . sort ( ) ; copy_S1 = t1 . join ( " " ) ; copy_S2 = t2 . join ( " " ) ; if ( copy_S1 != copy_S2 ) { return false ; } let key = ( S1 + " " + S2 ) ; if ( mp . has ( key ) ) { return mp [ key ] ; } let flag = false ; for ( let i = 1 ; i < n ; i ++ ) { if ( isScramble ( S1 . substring ( 0 , i ) , S2 . substring ( 0 , i ) ) && isScramble ( S1 . substring ( i , n ) , S2 . substring ( i , n ) ) ) { flag = true ; return true ; } if ( isScramble ( S1 . substring ( 0 , i ) , S2 . substring ( n - i , n ) ) && isScramble ( S1 . substring ( i , n ) , S2 . substring ( 0 , n - i ) ) ) { flag = true ; return true ; } } mp [ key ] = flag ; return false ; } let S1 = " " ; let S2 = " " ; if ( isScramble ( S1 , S2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: key
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function LongestPalindromicPrefix ( s ) { let n = s . length ; let max_len = 0 ; for ( let len = 1 ; len <= n ; len ++ ) { let temp = s . substring ( 0 , len ) ; let temp2 = temp ; temp2 = reverse ( temp2 ) ; if ( temp == temp2 ) { max_len = len ; } } document . write ( s . substring ( 0 , max_len ) ) ; } function reverse ( input ) { let a = input . split ( ' ' ) ; let l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { let temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( " " ) ; } let str = " " ; LongestPalindromicPrefix ( str ) ;

Index/key variables: l, r
Accumulator variables: l, len, r
Iterator variables: l, len
Javascript program:
function find_kth_String_of_n ( n , k ) { let d = new Array ( n ) ; d . fill ( 0 ) ; for ( let i = n - 1 ; i > - 1 ; i -- ) { d [ i ] = k % 26 ; k = parseInt ( k / 26 , 10 ) ; } if ( k > 0 ) return " " ; let s = " " ; for ( let i = 0 ; i < n ; i ++ ) s += String . fromCharCode ( d [ i ] + ( ' ' ) . charCodeAt ( ) ) ; return s ; } let n = 3 ; let k = 10 ; k -= 1 ; document . write ( find_kth_String_of_n ( n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k, s
Iterator variables: i
Javascript program:
function findMinLength ( s ) { var n = s . length ; var counts = new Map ( ) ; var indices = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { if ( counts . has ( s [ i ] ) ) counts . set ( s [ i ] , counts . get ( s [ i ] ) + 1 ) else counts . set ( s [ i ] , 1 ) indices . push ( i ) ; } } if ( counts . size < 5 ) return - 1 ; var flag1 = 0 , flag2 = 0 ; var i = 0 ; var j = indices . length - 1 ; while ( ( j - i ) >= 4 ) { if ( ! flag1 && counts . get ( s [ indices [ i ] ] ) > 1 ) { if ( counts . has ( s [ indices [ i ] ] ) ) counts . set ( s [ indices [ i ] ] , counts . get ( s [ indices [ i ] ] ) - 1 ) i ++ ; } else flag1 = 1 ; if ( ! flag2 && counts . get ( s [ indices [ j ] ] ) > 1 ) { if ( counts . has ( s [ indices [ j ] ] ) ) counts . set ( s [ indices [ j ] ] , counts . get ( s [ indices [ j ] ] ) - 1 ) j -- ; } else flag2 = 1 ; if ( flag1 && flag2 ) break ; } return ( indices [ j ] - indices [ i ] + 1 ) ; } var s = " " ; document . write ( findMinLength ( s ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function isConsonants ( x ) { x = x . toLowerCase ( ) ; return ! ( x === " " x === " " x === " " x === " " x === " " ) ; } function longestConsonantsSubsequence ( str ) { var answer = " " ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { if ( isConsonants ( str [ i ] ) ) { answer += str [ i ] ; } } return answer ; } var str = " " ; document . write ( longestConsonantsSubsequence ( str ) + " " ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
function lengthOfSubsequence ( str , K ) { var mp = new Map ( ) ; str . split ( ' ' ) . forEach ( ch => { if ( mp . has ( ch ) ) mp . set ( ch , mp . get ( ch ) + 1 ) else mp . set ( ch , 1 ) } ) ; var minimum = mp . get ( ' ' ) ; for ( var i = 1 ; i < K ; i ++ ) { minimum = Math . min ( minimum , mp . get ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) ) ; } return minimum * K ; } var str = " " ; var K = 3 ; document . write ( lengthOfSubsequence ( str , K ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function convertToString ( sum ) { let str = " " ; while ( sum > 0 ) { str = str + String . fromCharCode ( ( sum % 10 ) + ' ' . charCodeAt ( ) ) ; sum = parseInt ( sum / 10 , 10 ) ; } return str ; } function GetIndividulaDigitSum ( str , len ) { let sum = 0 ; for ( let i = 0 ; i < len ; i ++ ) { sum = sum + str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; } return convertToString ( sum ) ; } function GetDigitalRoot ( str ) { if ( str . length == 1 ) { return ( str [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; } str = GetIndividulaDigitSum ( str , str . length ) ; return GetDigitalRoot ( str ) ; } let str = " " ; document . write ( GetDigitalRoot ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( str1 , str2 ) { var c = 0 ; for ( var i = 0 ; i < str1 . length ; i ++ ) { if ( str2 . includes ( str1 [ i ] ) ) c += 1 ; } document . write ( " " + + parseInt ( c ) ) ; } var str1 = " " ; var str2 = " " ; count ( str1 , str2 ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function countOfLetters ( str ) { var letter = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( ( str [ i ] >= ' ' && str [ i ] <= ' ' ) || ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ) letter ++ ; } return letter ; } function countOfNumbers ( str ) { var number = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) number ++ ; } return number ; } function check ( str ) { if ( countOfLetters ( str ) == countOfNumbers ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; check ( str ) ;

Index/key variables: i
Accumulator variables: i, letter, number
Iterator variables: i
Javascript program:
function findMinCost ( s , i , j ) { var gr = Array . from ( Array ( 26 ) , ( ) => new Array ( ) ) ; var edge = Array . from ( Array ( 26 ) , ( ) => Array ( 26 ) ) ; for ( var k = 0 ; k < 26 ; k ++ ) for ( var l = 0 ; l < 26 ; l ++ ) edge [ k ] [ l ] = 0 ; for ( var k = 0 ; k < s . length ; k ++ ) { if ( k - 1 >= 0 && ! edge [ s [ k ] . charCodeAt ( 0 ) - 97 ] [ s [ k - 1 ] . charCodeAt ( 0 ) - 97 ] ) gr [ s [ k ] . charCodeAt ( 0 ) - 97 ] . push ( s [ k - 1 ] . charCodeAt ( 0 ) - 97 ) , edge [ s [ k ] . charCodeAt ( 0 ) - 97 ] [ s [ k - 1 ] . charCodeAt ( 0 ) - 97 ] = 1 ; if ( k + 1 <= s . length - 1 && ! edge [ s [ k ] . charCodeAt ( 0 ) - 97 ] [ s [ k + 1 ] . charCodeAt ( 0 ) - 97 ] ) gr [ s [ k ] . charCodeAt ( 0 ) - 97 ] . push ( s [ k + 1 ] . charCodeAt ( 0 ) - 97 ) , edge [ s [ k ] . charCodeAt ( 0 ) - 97 ] [ s [ k + 1 ] . charCodeAt ( 0 ) - 97 ] = 1 ; } var q = [ ] ; q . push ( s [ i ] . charCodeAt ( 0 ) - 97 ) ; var v = Array ( 26 ) . fill ( 0 ) ; var d = 0 ; while ( q . length > 0 ) { var cnt = q . length ; while ( cnt -- > 0 ) { var curr = q [ 0 ] ; q . shift ( ) ; if ( v [ curr ] ) continue ; v [ curr ] = 1 ; if ( curr == s [ j ] . charCodeAt ( 0 ) - 97 ) return d ; for ( var it = 0 ; it < gr [ curr ] . length ; it ++ ) { q . push ( gr [ curr ] [ it ] ) ; } } d ++ ; } return - 1 ; } var s = " " ; var i = 0 ; var j = 4 ; document . write ( findMinCost ( s , i , j ) ) ;

Index/key variables: curr, i, it, j, k, l
Accumulator variables: cnt, d, it, k, l
Iterator variables: it, k, l
Javascript program:
let MAX = 26 ; function performQueries ( str , q , type , ch , freq ) { let n = str . length ; let L = new Array ( MAX ) ; let F = new Array ( MAX ) ; let cnt = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { L [ i ] = new Array ( n ) ; F [ i ] = new Array ( n ) ; cnt [ i ] = 0 ; for ( let j = 0 ; j < n ; j ++ ) { L [ i ] [ j ] = 0 ; F [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) { let k = str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; cnt [ k ] ++ ; for ( let j = 0 ; j < MAX ; j ++ ) { if ( k == j ) { L [ j ] [ cnt [ j ] ] = i ; F [ j ] [ cnt [ j ] ] = i ; } else L [ j ] [ cnt [ j ] ] = L [ j ] [ cnt [ j ] ] + 1 ; } } for ( let i = 0 ; i < q ; i ++ ) { if ( type [ i ] == 1 ) { document . write ( L [ ch [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] [ freq [ i ] ] ) ; } else { document . write ( F [ ch [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] [ freq [ i ] ] ) ; } document . write ( " " ) ; } } let str = " " ; let type = [ 1 , 2 ] ; let ch = [ ' ' , ' ' ] ; let freq = [ 2 , 2 ] ; let q = type . length ; performQueries ( str , q , type , ch , freq ) ;

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function anagram_pairs ( s , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let chArr = s [ i ] . split ( " " ) ; chArr . sort ( ) ; s [ i ] = chArr . join ( " " ) ; if ( mp . has ( s [ i ] ) ) { mp . set ( s [ i ] , mp . get ( s [ i ] ) + 1 ) } else { mp . set ( s [ i ] , 1 ) } } let ans = 0 ; for ( let i of mp ) { let k = i [ 1 ] ; ans += Math . floor ( ( k * ( k - 1 ) ) / 2 ) ; } return ans ; } let s = [ " " , " " , " " , " " , " " ] ; let n = s . length ; document . write ( anagram_pairs ( s , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function Insert ( arr , n , k ) { let ind = 0 ; let sz = 0 ; let s = " " ; let ch = arr [ 0 ] ; s += ch ; sz = 1 ; ind = 0 ; for ( let i = 1 ; i < n ; i ++ ) { ch = arr [ i ] ; let s1 = s . substring ( 0 , ind + 1 ) ; let temp = k % sz ; let ro = temp - Math . min ( temp , sz - ind - 1 ) ; if ( ro == 0 ) { let s2 = s . substring ( ind + 1 , ind + 1 + temp ) ; let s3 = s . substring ( ind + temp + 1 , sz ) ; s = s1 + s2 + ch + s3 ; ind = s1 . length + s2 . length ; sz = s . length ; } else { let s2 = s . substring ( 0 , ro ) ; let s3 = s . substring ( ro , sz ) ; s = s2 + ch + s3 ; ind = s2 . length ; sz = s . length ; } } if ( ind == 0 ) { return s [ sz - 1 ] ; } else { return s [ ind - 1 ] ; } } let arr = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; let k = 2 ; let n = arr . length ; document . write ( Insert ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
let MAX = 256 ; let freq ; function preCalculate ( str , n ) { freq [ str [ 0 ] . charCodeAt ( 0 ) ] [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { let ch = str [ i ] ; for ( let j = 0 ; j < MAX ; j ++ ) { let charToUpdate = String . fromCharCode ( j ) ; if ( charToUpdate == ch ) freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1 ; else freq [ j ] [ i ] = freq [ j ] [ i - 1 ] ; } } } function getFrequency ( ch , l , r ) { if ( l == 0 ) return freq [ ch . charCodeAt ( 0 ) ] [ r ] ; else return ( freq [ ch . charCodeAt ( 0 ) ] [ r ] - freq [ ch . charCodeAt ( 0 ) ] [ l - 1 ] ) ; } function lastNonRepeating ( str , n , l , r ) { for ( let i = r ; i >= l ; i -- ) { let ch = str [ i ] ; if ( getFrequency ( ch , l , r ) == 1 ) return ( " " + ch ) ; } return " " ; } let str = " " ; let n = str . length ; let queries = [ [ 2 , 9 ] , [ 2 , 3 ] , [ 0 , 12 ] ] ; let q = queries . length ; freq = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { freq [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { freq [ i ] [ j ] = 0 ; } } preCalculate ( str , n ) ; for ( let i = 0 ; i < q ; i ++ ) { document . write ( lastNonRepeating ( str , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ; }

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function pre_process ( substrings , s ) { var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) { var dup = " " ; for ( var j = i ; j < n ; j ++ ) { dup += s [ j ] ; substrings . push ( dup ) ; } } substrings . sort ( ) ; } var s = " " ; var substrings = [ ] ; pre_process ( substrings , s ) ; var queries = [ 1 , 5 , 10 ] ; var q = queries . length ; for ( var i = 0 ; i < q ; i ++ ) document . write ( substrings [ queries [ i ] - 1 ] + " " ) ;

Index/key variables: i, j
Accumulator variables: dup, i, j
Iterator variables: i, j
Javascript program:
function FindString ( str , num , n ) { var p = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { var x = [ 0 , 0 ] ; x [ 0 ] = str [ i ] ; x [ 1 ] = num [ i ] ; p . push ( x ) ; } while ( p . length > 1 ) { var x = p [ p . length - 1 ] ; p . pop ( ) ; var y = p [ p . length - 1 ] ; p . pop ( ) ; var temp = x [ 1 ] + y [ 1 ] ; var sb = x [ 0 ] + y [ 0 ] ; var z = [ 0 , 0 ] ; z [ 1 ] = temp ; z [ 0 ] = sb ; p . push ( z ) ; } var z = p [ p . length - 1 ] ; p . pop ( ) ; document . write ( z [ 0 ] + " " ) ; } var str = [ " " , " " , " " ] ; var num = [ 2 , 3 , 7 ] ; var n = num . length ; FindString ( str , num , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( str , K ) { var n = str . length ; var res = 999999999 , count = 0 , a , b ; var cnt = Array ( 27 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) cnt [ str [ i ] . charCodeAt ( 0 ) - 97 + 1 ] ++ ; for ( var i = 1 ; i < ( 26 - K + 1 ) ; i ++ ) { a = i ; b = i + K ; count = 0 ; for ( var j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= a && j >= b ) count = count + ( Math . min ( j - b , 25 - j + a + 1 ) ) * cnt [ j ] ; else if ( j <= a && j <= b ) count = count + ( Math . min ( a - j , 25 + j - b + 1 ) ) * cnt [ j ] ; } } res = Math . min ( res , count ) ; } for ( var i = 26 - K + 1 ; i <= 26 ; i ++ ) { a = i ; b = ( i + K ) % 26 ; count = 0 ; for ( var j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= b && j <= a ) count = count + ( Math . min ( j - b , a - j ) ) * cnt [ j ] ; } } res = Math . min ( res , count ) ; } return res ; } var str = " " ; var K = 2 ; document . write ( minCost ( str , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printBinStr ( str , len ) { for ( var i = 0 ; i < len ; i ++ ) { document . write ( str [ i ] ) ; } document . write ( " " ) ; } function generateBinStr ( str , len , currlen , occur , nextbit ) { if ( currlen == len ) { if ( occur == 2 && nextbit == 0 ) printBinStr ( str , len ) ; return ; } if ( currlen == 0 ) { str [ 0 ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else { if ( occur < 2 ) { str [ currlen ] = nextbit ; if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { occur += 1 ; } generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else { if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { return ; } else { str [ currlen ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } } } } var n = 5 ; if ( n < 4 ) document . write ( - 1 ) ; else { var str = Array ( n ) ; generateBinStr ( str , n , 0 , 0 , 0 ) ; generateBinStr ( str , n , 0 , 0 , 1 ) ; }

Index/key variables: currlen, i
Accumulator variables: i, occur
Iterator variables: i
Javascript program:
function printLastChar ( str ) { str = str + " " ; for ( var i = 1 ; i < str . length ; i ++ ) { if ( str [ i ] === " " ) document . write ( str [ i - 1 ] + " " ) ; } } var str = " " ; printLastChar ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxBalancedStr ( s ) { var open1 = 0 , close1 = 0 ; var open2 = 0 , close2 = 0 ; var open3 = 0 , close3 = 0 ; for ( i = 0 ; i < s . length ; i ++ ) { switch ( s . charAt ( i ) ) { case ' ' : open1 ++ ; break ; case ' ' : close1 ++ ; break ; case ' ' : open2 ++ ; break ; case ' ' : close2 ++ ; break ; case ' ' : open3 ++ ; break ; case ' ' : close3 ++ ; break ; } } var maxLen = 2 * Math . min ( open1 , close1 ) + 2 * Math . min ( open2 , close2 ) + 2 * Math . min ( open3 , close3 ) ; return maxLen ; } var s = " " ; document . write ( maxBalancedStr ( s ) ) ;

Accumulator variables: close1, close2, close3, i, open1, open2, open3
Iterator variables: i
Javascript program:
function strBitwiseOR ( arr , n ) { var res = " " ; var max_size = - 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { max_size = Math . max ( max_size , 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_size - arr [ i ] . length ; j ++ ) s += ' ' ; arr [ i ] = arr [ i ] + s ; } for ( var i = 0 ; i < max_size ; i ++ ) { var curr_bit = 0 ; for ( var j = 0 ; j < n ; j ++ ) curr_bit = curr_bit | ( arr [ j ] [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; res += String . fromCharCode ( curr_bit + ' ' . charCodeAt ( 0 ) ) ; } res = res . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; return res ; } var arr = [ " " , " " , " " ] ; var n = arr . length ; document . write ( strBitwiseOR ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res, s
Iterator variables: i, j
Javascript program:
function findCost ( s1 , s2 , a , b , c , d , n ) { var cost = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s1 [ i ] == s2 [ i ] ) continue ; else { if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( a , b + c ) ) ; else if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( b , a + c ) ) ; else if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( c , a + b ) ) ; } } return cost ; } var s1 = " " ; var s2 = " " ; var a = 2 , b = 3 , c = 4 , d = 10 ; var n = s1 . length ; document . write ( findCost ( s1 , s2 , a , b , c , d , n ) ) ;

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Javascript program:
function check ( s , k ) { for ( var i = 0 ; i < s . length ; i ++ ) if ( s [ i ] != s [ i % k ] ) return false ; return true ; } function countCommonDivisors ( a , b ) { var ct = 0 ; var n = a . length , m = b . length ; for ( var i = 1 ; i <= Math . min ( n , m ) ; i ++ ) { if ( n % i == 0 && m % i == 0 ) if ( a . substring ( 0 , i ) == b . substring ( 0 , i ) ) if ( check ( a , i ) && check ( b , i ) ) ct ++ ; } return ct ; } var a = " " , b = " " H2 : I6 ; document . write ( countCommonDivisors ( a , b ) ) ;

Index/key variables: i
Accumulator variables: ct, i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } function levelOrder ( root ) { if ( root == null ) return ; let q = [ ] ; q . push ( root ) ; q . push ( null ) ; while ( q . length != 0 ) { let curr = q . shift ( ) ; if ( curr == null ) { if ( q . length != 0 ) { q . push ( null ) ; document . write ( " " ) ; } } else { if ( curr . left != null ) q . push ( curr . left ) ; if ( curr . right != null ) q . push ( curr . right ) ; document . write ( curr . data + " " ) ; } } } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; levelOrder ( root ) ;

Class/struct names: Node
Javascript program:
function nextZero ( i , occurrences ) { while ( i < occurrences . length ) { if ( occurrences [ i ] == 0 ) return i ; i ++ ; } return - 1 ; } function getModifiedString ( str ) { let n = str . length ; if ( n > 26 ) return " " ; let ch = str . split ( ' ' ) ; let occurrences = new Array ( 26 ) ; occurrences . fill ( 0 ) ; let i ; for ( i = 0 ; i < n ; i ++ ) occurrences [ ch [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; let index = nextZero ( 0 , occurrences ) ; for ( i = 0 ; i < n ; i ++ ) { if ( occurrences [ ch [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] > 1 ) { occurrences [ ch [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] -- ; ch [ i ] = String . fromCharCode ( ' ' . charCodeAt ( ) + index ) ; occurrences [ index ] = 1 ; index = nextZero ( index + 1 , occurrences ) ; } } let s = ch . join ( " " ) ; return s ; } let str = " " ; document . write ( getModifiedString ( str ) ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function subStringsStartingHere ( str , n , startIndex ) { var count = 0 , i = startIndex + 1 ; while ( i <= n ) { if ( str . startsWith ( str . substring ( startIndex , i ) ) ) { count ++ ; } else break ; i ++ ; } return count ; } function countSubStrings ( str , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) count += subStringsStartingHere ( str , n , i ) ; } return count ; } var str = " " ; var n = str . length ; document . write ( countSubStrings ( str , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function binarySearch ( arr , x ) { let l = 0 , r = arr . length - 1 ; while ( l <= r ) { let m = l + Math . floor ( ( r - l ) / 2 ) ; let res = x . localeCompare ( arr [ m ] ) ; if ( res == 0 ) return m ; if ( res > 0 ) l = m + 1 ; else r = m - 1 ; } return - 1 ; } let arr = [ " " , " " , " " , " " ] ; let x = " " ; let result = binarySearch ( arr , x ) ; if ( result == - 1 ) document . write ( " " ) ; else document . write ( " " + " " + result + " " ) ;

Index/key variables: m
Javascript program:
const max_val = 257 ; function PrimeCharacters ( s ) { var prime = new Array ( max_val + 1 ) ; for ( var i = 0 ; i <= max_val ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] === true ) { for ( var i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } var count = 0 ; for ( var i = 0 ; i < s . length ; ++ i ) { if ( prime [ s [ i ] . charCodeAt ( 0 ) ] ) count ++ ; } return count ; } var S = " " ; document . write ( PrimeCharacters ( S ) ) ;

Index/key variables: i, p
Accumulator variables: count, i, p
Iterator variables: i, p
Javascript program:
function largestSubsequence ( s ) { function largestSubsequence ( s ) { let maxi = 0 ; let prev1 ; for ( let i = 0 ; i < 10 ; i ++ ) { for ( let j = 0 ; j < 10 ; j ++ ) { if ( i != j ) { let len = 0 ; prev1 = String ( j ) ; for ( let k = 0 ; k < s . length ; k ++ ) { if ( s [ k ] == String ( i ) && prev1 == String ( j ) ) { prev1 = s [ k ] ; len ++ ; } else if ( s [ k ] == String ( j ) && prev1 == String ( i ) ) { prev1 = s [ k ] ; len ++ ; } } maxi = Math . max ( len , maxi ) ; } } } if ( maxi != 1 ) document . write ( maxi , ' ' ) ; else document . write ( 0 , ' ' ) ; } let s = " " ; largestSubsequence ( s ) ;

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