dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var MAX = 1000 ; function waysToKAdjacentSetBits ( dp , n , k , currentIndex , adjacentSetBits , lastBit ) { if ( currentIndex == n ) { if ( adjacentSetBits == k ) return 1 ; return 0 ; } if ( dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] != - 1 ) { return dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] ; } var noOfWays = 0 ; if ( lastBit == 1 ) { noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits + 1 , 1 ) ; noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } else if ( ! lastBit ) { noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 1 ) ; noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] = noOfWays ; return noOfWays ; } var n = 5 , k = 2 ; var dp = Array . from ( Array ( MAX ) , ( ) => Array ( MAX ) ) ; for ( var i = 0 ; i < MAX ; i ++ ) for ( var j = 0 ; j < MAX ; j ++ ) dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; var totalWays = waysToKAdjacentSetBits ( dp , n , k , 1 , 0 , 1 ) + waysToKAdjacentSetBits ( dp , n , k , 1 , 0 , 0 ) ; document . write ( " " + totalWays + " " ) ;

Index/key variables: adjacentSetBits, currentIndex, i, j, lastBit
Accumulator variables: i, j, noOfWays
Iterator variables: i, j
Javascript program:
function printTetra ( n ) { if ( n < 0 ) return ; var first = 0 , second = 1 ; var third = 1 , fourth = 2 ; var curr ; if ( n == 0 ) cout << first ; else if ( n == 1 n == 2 ) cout << second ; else if ( n == 3 ) cout << fourth ; else { for ( var i = 4 ; i <= n ; i ++ ) { curr = first + second + third + fourth ; first = second ; second = third ; third = fourth ; fourth = curr ; } document . write ( curr ) ; } } var n = 10 ; printTetra ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countWays ( n ) { let res = new Array ( n + 2 ) ; res [ 0 ] = 1 ; res [ 1 ] = 1 ; res [ 2 ] = 2 ; for ( let i = 3 ; i <= n ; i ++ ) res [ i ] = res [ i - 1 ] + res [ i - 2 ] + res [ i - 3 ] ; return res [ n ] ; } let n = 4 ; document . write ( countWays ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function countWays ( n ) { var a = 1 , b = 2 , c = 4 ; var d = 0 ; if ( n == 0 n == 1 n == 2 ) return n ; if ( n == 3 ) return c ; for ( var i = 4 ; i <= n ; i ++ ) { d = c + b + a ; a = b ; b = c ; c = d ; } return d ; } var n = 4 ; document . write ( countWays ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPossible ( elements , sum ) { var dp = [ sum + 1 ] ; dp [ 0 ] = 1 ; for ( var i = 0 ; i < elements . length ; i ++ ) { for ( var j = sum ; j >= elements [ i ] ; j -- ) { if ( dp [ j - elements [ i ] ] == 1 ) dp [ j ] = 1 ; } } if ( dp [ sum ] == 1 ) return true ; return false ; } var elements = [ 6 , 2 , 5 ] ; var sum = 7 ; if ( isPossible ( elements , sum ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function nCr ( n , r ) { if ( r > n ) return 0 ; if ( r > n - r ) r = n - r ; mod = 1000000007 ; var arr = new Array ( r ) ; for ( var i = n - r + 1 ; i <= n ; i ++ ) { arr [ i + r - n - 1 ] = i ; } var ans = 1 ; for ( var k = 1 ; k < r + 1 ; k ++ ) { var j = 0 , i = k ; while ( j < arr . length ) { var x = gcd ( i , arr [ j ] ) ; if ( x > 1 ) { arr [ j ] /= x ; i /= x ; } if ( i == 1 ) break ; j += 1 ; } } arr . forEach ( function ( i ) { ans = ( ans * i ) % mod ; } ) ; return ans ; } var n = 5 , r = 2 ; document . write ( " " + n + " " + r + " " + nCr ( n , r ) + " " ) ;

Index/key variables: j
Accumulator variables: i, j, k
Iterator variables: i, k
Javascript program:
function FindKthChar ( str , K , X ) { var ans = " " ; var sum = 0 ; for ( i = 0 ; i < str . length ; i ++ ) { var digit = parseInt ( str [ i ] ) ; var range = parseInt ( Math . pow ( digit , X ) ) ; sum += range ; if ( K <= sum ) { ans = str [ i ] ; break ; } } return ans ; } var str = " " ; var K = 9 ; var X = 3 ; var ans = FindKthChar ( str , K , X ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countSetBits ( n ) { var count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } function totalPairs ( s1 , s2 ) { var count = 0 ; var arr1 = new Array ( 7 ) . fill ( 0 ) ; var arr2 = new Array ( 7 ) . fill ( 0 ) ; for ( let i = 0 ; i < s1 . length ; i ++ ) { set_bits = countSetBits ( s1 [ i ] . charCodeAt ( 0 ) ) ; arr1 [ set_bits ] += 1 ; } for ( let i = 0 ; i < s2 . length ; i ++ ) { set_bits = countSetBits ( s2 [ i ] . charCodeAt ( 0 ) ) ; arr2 [ set_bits ] += 1 ; } for ( let i = 1 ; i < 7 ; i ++ ) { count += arr1 [ i ] * arr2 [ i ] ; } return count ; } var s1 = " " ; var s2 = " " ; document . write ( totalPairs ( s1 , s2 ) ) ;

Index/key variables: i, set_bits
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countSubstr ( str , n , x , y ) { var tot_count = 0 ; var count_x = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] === x ) count_x ++ ; if ( str [ i ] === y ) tot_count += count_x ; } return tot_count ; } var str = " " ; var n = str . length ; var x = " " , y = " " ; document . write ( " " + countSubstr ( str , n , x , y ) ) ;

Index/key variables: i
Accumulator variables: count_x, i, tot_count
Iterator variables: i
Javascript program:
var OUT = 0 ; var IN = 1 ; function countWords ( str ) { var state = OUT ; var wc = 0 ; var i = 0 ; while ( i < str . length ) { if ( str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' ) state = OUT ; else if ( state == OUT ) { state = IN ; ++ wc ; } ++ i ; } return wc ; } var str = " " ; document . write ( " " + countWords ( str ) ) ;

Index/key variables: i
Javascript program:
function itemType ( n ) { let count = 0 ; let day = 1 ; while ( count + day * ( day + 1 ) / 2 < n ) { count += day * ( day + 1 ) / 2 ; day ++ ; } for ( let type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) { return type ; } } } let N = 10 ; document . write ( itemType ( N ) ) ;

Accumulator variables: count, day, type
Iterator variables: type
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function isSortedDesc ( head ) { if ( head == null head . next == null ) return true ; return head . data > head . next . data && isSortedDesc ( head . next ) ; } function newNode ( data ) { var temp = new Node ( ) ; temp . next = null ; temp . data = data ; return temp ; } var head = newNode ( 7 ) ; head . next = newNode ( 5 ) ; head . next . next = newNode ( 4 ) ; head . next . next . next = newNode ( 3 ) ; if ( isSortedDesc ( head ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Class/struct names: Node
Javascript program:
const maxLength = ( str , n , c , k ) => { let ans = - 1 ; let cnt = 0 ; let left = 0 ; for ( let right = 0 ; right < n ; right ++ ) { if ( str [ right ] == c ) { cnt ++ ; } while ( cnt > k ) { if ( str [ left ] == c ) { cnt -- ; } left ++ ; } ans = Math . max ( ans , right - left + 1 ) ; } return ans ; } const maxConsecutiveSegment = ( S , K ) => { let N = S . length ; return Math . max ( maxLength ( S , N , ' ' , K ) , maxLength ( S , N , ' ' , K ) ) ; } let S = " " ; let K = 1 ; document . write ( maxConsecutiveSegment ( S , K ) ) ;

Index/key variables: left, right
Accumulator variables: cnt, left, right
Iterator variables: right
Javascript program:
function findMaxOccurence ( str , N ) { for ( var i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { str [ i ] = ' ' ; } } document . write ( str . join ( ' ' ) ) ; } var str = " " . split ( ' ' ) ; var N = str . length ; findMaxOccurence ( str , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkInfinite ( s ) { var flag = 1 ; var N = s . length ; for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( s [ i ] == String . fromCharCode ( ( s [ i + 1 ] . charCodeAt ( 0 ) ) + 1 ) ) { continue ; } else if ( s [ i ] == ' ' && s [ i + 1 ] == ' ' ) { continue ; } else { flag = 0 ; break ; } } if ( flag == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var s = " " ; checkInfinite ( s ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minChangeInLane ( barrier , n ) { let dp = [ 1 , 0 , 1 ] ; for ( let j = 0 ; j < n ; j ++ ) { let val = barrier [ j ] ; if ( val > 0 ) { dp [ val - 1 ] = 1e6 ; } for ( let i = 0 ; i < 3 ; i ++ ) { if ( val != i + 1 ) { dp [ i ] = Math . min ( dp [ i ] , Math . min ( dp [ ( i + 1 ) % 3 ] , dp [ ( i + 2 ) % 3 ] ) + 1 ) ; } } } return Math . min ( dp [ 0 ] , Math . min ( dp [ 1 ] , dp [ 2 ] ) ) ; } let barrier = [ 0 , 1 , 2 , 3 , 0 ] ; let N = barrier . length ; document . write ( minChangeInLane ( barrier , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function numWays ( ratings , queries ) { var dp = Array . from ( Array ( n ) , ( ) => Array ( 10002 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < k ; i ++ ) dp [ 0 ] [ ratings [ 0 ] [ i ] ] += 1 ; for ( var i = 1 ; i < n ; i ++ ) { for ( var sum = 0 ; sum <= 10000 ; sum ++ ) { for ( var j = 0 ; j < k ; j ++ ) { if ( sum >= ratings [ i ] [ j ] ) dp [ i ] [ sum ] += dp [ i - 1 ] [ sum - ratings [ i ] [ j ] ] ; } } } for ( var sum = 1 ; sum <= 10000 ; sum ++ ) { dp [ n - 1 ] [ sum ] += dp [ n - 1 ] [ sum - 1 ] ; } for ( var q = 0 ; q < 2 ; q ++ ) { var a = queries [ q ] [ 0 ] ; var b = queries [ q ] [ 1 ] ; document . write ( dp [ n - 1 ] [ b ] - dp [ n - 1 ] [ a - 1 ] + " " ) ; } } var n = 2 ; var k = 3 ; var ratings = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ; var queries = [ [ 6 , 6 ] , [ 1 , 6 ] ] ; numWays ( ratings , queries ) ;

Index/key variables: b, i, j, q, sum
Accumulator variables: i, j, q, sum
Iterator variables: i, j, q, sum
Javascript program:
function numberOfPermWithKInversion ( N , K ) { let dp = new Array ( 2 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } let mod = 1000000007 ; for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 0 ; j <= K ; j ++ ) { if ( i == 1 ) { dp [ i % 2 ] [ j ] = ( j == 0 ) ? 1 : 0 ; } else if ( j == 0 ) dp [ i % 2 ] [ j ] = 1 ; else dp [ i % 2 ] [ j ] = ( dp [ i % 2 ] [ j - 1 ] % mod + ( dp [ 1 - i % 2 ] [ j ] - ( ( Math . max ( j - ( i - 1 ) , 0 ) == 0 ) ? 0 : dp [ 1 - i % 2 ] [ Math . max ( j - ( i - 1 ) , 0 ) - 1 ] ) + mod ) % mod ) % mod ; } } document . write ( dp [ N % 2 ] [ K ] ) ; } let N = 3 , K = 2 ; numberOfPermWithKInversion ( N , K ) ;

Index/key variables: K, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function MaxProfit ( treasure , color , n , k , col , A , B ) { let sum = 0 ; if ( k == n ) return 0 ; if ( col == color [ k ] ) sum += Math . max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) ) ; else sum += Math . max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) ) ; return sum ; } let A = - 5 , B = 7 ; let treasure = [ 4 , 8 , 2 , 9 ] ; let color = [ 2 , 2 , 6 , 2 ] ; let n = color . length ; document . write ( MaxProfit ( treasure , color , n , 0 , 0 , A , B ) ) ;

Index/key variables: k
Accumulator variables: sum
Javascript program:
let sum = 0 ; function Combination ( a , combi , n , r , depth , index ) { if ( index == r ) { let product = 1 ; for ( let i = 0 ; i < r ; i ++ ) product = product * combi [ i ] ; sum += product ; return ; } for ( let i = depth ; i < n ; i ++ ) { combi [ index ] = a [ i ] ; Combination ( a , combi , n , r , i + 1 , index + 1 ) ; } } function allCombination ( a , n ) { for ( let i = 1 ; i <= n ; i ++ ) { let combi = [ ] ; Combination ( a , combi , n , i , 0 , 0 ) ; document . write ( " " + i + " " + sum + " " ) ; sum = 0 ; } } let n = 5 ; let a = [ ] ; for ( let i = 0 ; i < n ; i ++ ) a [ i ] = i + 1 ; allCombination ( a , n ) ;

Index/key variables: i, index
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function max ( x , y ) { return ( x > y ? x : y ) ; } function maxTasks ( high , low , n ) { var task_dp = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; task_dp [ 0 ] = 0 ; task_dp [ 1 ] = high [ 0 ] ; for ( i = 2 ; i <= n ; i ++ ) task_dp [ i ] = Math . max ( high [ i - 1 ] + task_dp [ i - 2 ] , low [ i - 1 ] + task_dp [ i - 1 ] ) ; return task_dp [ n ] ; } var n = 5 ; var high = [ 3 , 6 , 8 , 7 , 6 ] ; var low = [ 1 , 5 , 4 , 5 , 3 ] ; document . write ( maxTasks ( high , low , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function PermutationCoeff ( n , k ) { let P = 1 ; for ( let i = 0 ; i < k ; i ++ ) P *= ( n - i ) ; return P ; } let n = 10 , k = 2 ; document . write ( " " + n + " " + k + " " + PermutationCoeff ( n , k ) ) ;

Accumulator variables: P, i
Iterator variables: i
Javascript program:
function findPartition ( arr , n ) { var sum = 0 ; var i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; var part = Array ( parseInt ( sum / 2 ) + 1 ) . fill ( ) . map ( ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; for ( i = 0 ; i <= n ; i ++ ) part [ 0 ] [ i ] = true ; for ( i = 1 ; i <= parseInt ( sum / 2 ) ; i ++ ) part [ i ] [ 0 ] = false ; for ( i = 1 ; i <= parseInt ( sum / 2 ) ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { part [ i ] [ j ] = part [ i ] [ j - 1 ] ; if ( i >= arr [ j - 1 ] ) part [ i ] [ j ] = part [ i ] [ j ] || part [ i - arr [ j - 1 ] ] [ j - 1 ] ; } } return part [ parseInt ( sum / 2 ) ] [ n ] ; } var arr = [ 3 , 1 , 1 , 2 , 2 , 1 ] ; var n = arr . length ; if ( findPartition ( arr , n ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function minimumOperations ( orig_str , m , n ) { let orig = orig_str ; let turn = 1 ; let j = 1 ; for ( let i = 0 ; i < orig_str . length ; i ++ ) { let m_cut = orig_str . substring ( orig_str . length - m ) ; orig_str = orig_str . substring ( 0 , orig_str . length - m ) ; orig_str = m_cut + orig_str ; j = j + 1 ; if ( orig != orig_str ) { turn = turn + 1 ; let n_cut = orig_str . substring ( orig_str . length - n ) ; orig_str = orig_str . substring ( 0 , orig_str . length - n ) ; orig_str = n_cut + orig_str ; j = j + 1 ; } if ( orig == orig_str ) { break ; } turn = turn + 1 ; } document . write ( turn ) ; } let S = " " ; let X = 5 , Y = 3 ; minimumOperations ( S , X , Y ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function KMPSearch ( pat , txt ) { let M = pat . length ; let N = txt . length ; let lps = new Array ( M ) ; lps . fill ( 0 ) ; computeLPSArray ( pat , M , lps ) ; let i = 0 ; let j = 0 ; while ( i < N ) { if ( pat [ j ] == txt [ i ] ) { j ++ ; i ++ ; } if ( j == M ) { return i - j ; } else if ( i < N && pat [ j ] != txt [ i ] ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } return 0 ; } function computeLPSArray ( pat , M , lps ) { let len = 0 ; lps [ 0 ] = 0 ; let i = 1 ; while ( i < M ) { if ( pat [ i ] == pat [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } function countRotations ( s ) { let s1 = s . substring ( 1 , s . length ) + s ; let pat = s . split ( ' ' ) ; let text = s1 . split ( ' ' ) ; return 1 + KMPSearch ( pat , text ) ; } let s1 = " " ; document . write ( countRotations ( s1 ) ) ;

Index/key variables: i, j, len
Accumulator variables: i, j, len
Javascript program:
let dfa = 0 ; function start ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; } function state1 ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; else if ( c == ' ' c == ' ' ) dfa = 2 ; else dfa = 0 ; } function state2 ( c ) { if ( c == ' ' c == ' ' ) dfa = 3 ; else dfa = 0 ; } function state3 ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; else dfa = 0 ; } function isAccepted ( str ) { let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( dfa == 0 ) start ( str [ i ] ) ; else if ( dfa == 1 ) state1 ( str [ i ] ) ; else if ( dfa == 2 ) state2 ( str [ i ] ) ; else state3 ( str [ i ] ) ; } return ( dfa != 3 ) ; } let str = " " . split ( ' ' ) ; if ( isAccepted ( str ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var parent = new Array ( 26 ) . fill ( 0 ) ; function find ( x ) { if ( x !== parent [ x ] ) return ( parent [ x ] = find ( parent [ x ] ) ) ; return x ; } function join ( x , y ) { var px = find ( x ) ; var pz = find ( y ) ; if ( px !== pz ) { parent [ pz ] = px ; } } function convertible ( s1 , s2 ) { var mp = { } ; for ( var i = 0 ; i < s1 . length ; i ++ ) { if ( ! mp . hasOwnProperty ( s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) { mp [ s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = s2 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; } else { if ( mp [ s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] !== s2 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) return false ; } } for ( const [ key , value ] of Object . entries ( mp ) ) { if ( key === value ) continue ; else { if ( find ( key ) == find ( value ) ) return false ; else join ( key , value ) ; } } return true ; } function initialize ( ) { for ( var i = 0 ; i < 26 ; i ++ ) { parent [ i ] = i ; } } var s1 , s2 ; s1 = " " ; s2 = " " ; initialize ( ) ; if ( convertible ( s1 , s2 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, pz, x
Accumulator variables: i
Iterator variables: i
Javascript program:
let SIZE = 26 ; function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } return prime ; } function printChar ( str , n ) { let prime = [ ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) { prime . push ( true ) ; } prime = SieveOfEratosthenes ( prime , str . length + 1 ) ; let freq = [ ] ; for ( let i = 0 ; i < 26 ; i ++ ) { freq . push ( 0 ) ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str . charCodeAt ( i ) - 97 ] ++ ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ freq [ str . charCodeAt ( i ) - 97 ] ] ) { document . write ( str [ i ] ) ; } } } let str = " " ; let n = str . length ; printChar ( str , n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function prime ( n ) { if ( n <= 1 ) return false ; let max_div = Math . floor ( Math . sqrt ( n ) ) ; for ( let i = 2 ; i < 1 + max_div ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function checkString ( s ) { let freq = new Map ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! freq . has ( s [ i ] ) ) freq . set ( s [ i ] , 0 ) ; freq . set ( s [ i ] , freq . get ( s [ i ] ) + 1 ) ; } for ( let i = 0 ; i < s . length ; i ++ ) { if ( prime ( freq . get ( s [ i ] ) ) ) document . write ( s [ i ] ) ; } } let s = " " ; checkString ( s ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let SIZE = 26 ; function printChar ( str , n ) { let freq = new Array ( SIZE ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { freq [ str . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ str . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] % 2 == 0 ) { document . write ( str [ i ] ) ; } } } let str = " " ; let n = str . length ; printChar ( str , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CompareAlphanumeric ( str1 , str2 ) { let i , j ; i = 0 ; j = 0 ; let len1 = str1 . length ; let len2 = str2 . length ; while ( i <= len1 && j <= len2 ) { while ( i < len1 && ( ! ( ( str1 [ i ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str1 [ i ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) || ( str1 [ i ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str1 [ i ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) || ( str1 [ i ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str1 [ i ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) ) ) ) { i ++ ; } while ( j < len2 && ( ! ( ( str2 [ j ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str2 [ j ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) || ( str2 [ j ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str2 [ j ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) || ( str2 [ j ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str2 [ j ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) ) ) ) { j ++ ; } if ( i == len1 && j == len2 ) { return true ; } else if ( str1 [ i ] != str2 [ j ] ) { return false ; } else { i ++ ; j ++ ; } } return false ; } function CompareAlphanumericUtil ( str1 , str2 ) { let res ; res = CompareAlphanumeric ( str1 . split ( ' ' ) , str2 . split ( ' ' ) ) ; if ( res == true ) { document . write ( " " + " " ) ; } else { document . write ( " " ) ; } } let str1 , str2 ; str1 = " " ; str2 = " " ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = " " ; str2 = " " ; CompareAlphanumericUtil ( str1 , str2 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function solveQueries ( str , query ) { let len = str . length ; let Q = query . length ; let pre = new Array ( len ) ; for ( let i = 0 ; i < len ; i ++ ) { pre [ i ] = new Array ( 26 ) ; for ( let j = 0 ; j < 26 ; j ++ ) { pre [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < len ; i ++ ) { pre [ i ] [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; if ( i > 0 ) { for ( let j = 0 ; j < 26 ; j ++ ) pre [ i ] [ j ] += pre [ i - 1 ] [ j ] ; } } for ( let i = 0 ; i < Q ; i ++ ) { let l = query [ i ] [ 0 ] ; let r = query [ i ] [ 1 ] ; let maxi = 0 ; let c = ' ' ; for ( let j = 0 ; j < 26 ; j ++ ) { let times = pre [ r ] [ j ] ; if ( l > 0 ) times -= pre [ l - 1 ] [ j ] ; if ( times > maxi ) { maxi = times ; c = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + j ) ; } } document . write ( " " + ( i + 1 ) + " " + c + " " ) ; } } let str = " " ; let query = [ [ 0 , 1 ] , [ 1 , 6 ] , [ 5 , 6 ] ] ; solveQueries ( str , query ) ;

Index/key variables: i, j, r
Accumulator variables: i, j, times
Iterator variables: i, j
Javascript program:
function startsWith ( str , pre ) { let strLen = str . length ; let preLen = pre . length ; let i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } function endsWith ( str , suff ) { let i = str . length - 1 ; let j = suff . length - 1 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } function checkString ( str , a , b ) { if ( str . length != a . length + b . length ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } let str = " " ; let a = " " ; let b = " " ; if ( checkString ( str , a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
let SIZE = 26 ; function printChar ( str , n ) { let freq = [ ] ; for ( let i = 0 ; i < SIZE ; i ++ ) { freq . push ( 0 ) ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str . charCodeAt ( i ) - 97 ] ++ ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ str . charCodeAt ( i ) - 97 ] % 2 == 1 ) { document . write ( str [ i ] ) ; } } } let str = " " ; let n = str . length ; printChar ( str , n ) ;

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