dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countP ( n , k ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = new Array ( k + 1 ) ; for ( let j = 0 ; j < k + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( let i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( let i = 0 ; i <= k ; i ++ ) dp [ 0 ] [ k ] = 0 ; for ( let i = 1 ; i <= n ; i ++ ) for ( let j = 1 ; j <= k ; j ++ ) if ( j == 1 i == j ) dp [ i ] [ j ] = 1 ; else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ; return dp [ n ] [ k ] ; } document . write ( countP ( 5 , 2 ) )

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printCountDP ( dist ) { var ways = [ ] , n = dist ; ways . length = 3 ; ways [ 0 ] = 1 ; ways [ 1 ] = 1 ; ways [ 2 ] = 2 ; for ( var i = 3 ; i <= n ; i ++ ) ways [ i % 3 ] = ways [ ( i - 1 ) % 3 ] + ways [ ( i - 2 ) % 3 ] + ways [ ( i - 3 ) % 3 ] ; return ways [ n % 3 ] ; } var dist = 4 ; document . write ( printCountDP ( dist ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countNumbersWith4 ( n ) { let result = 0 ; for ( let x = 1 ; x <= n ; x ++ ) result += has4 ( x ) ? 1 : 0 ; return result ; } function has4 ( x ) { while ( x != 0 ) { if ( x % 10 == 4 ) return true ; x = Math . floor ( x / 10 ) ; } return false ; } let n = 328 ; document . write ( " " + n + " " + countNumbersWith4 ( n ) ) ;

Accumulator variables: result, x
Iterator variables: x
Javascript program:
function countNumbersWith4 ( n ) { if ( n < 4 ) return 0 ; let d = Math . floor ( Math . log10 ( n ) ) ; let a = new Array ( d + 2 ) ; for ( let i = 0 ; i < d + 2 ; i ++ ) { a [ i ] = 0 ; } a [ 0 ] = 0 ; a [ 1 ] = 1 ; for ( let i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 9 + Math . floor ( Math . ceil ( Math . pow ( 10 , i - 1 ) ) ) ; let p = Math . floor ( Math . ceil ( Math . pow ( 10 , d ) ) ) ; let msd = Math . floor ( n / p ) ; if ( msd == 4 ) return ( msd ) * a [ d ] + ( n % p ) + 1 ; if ( msd > 4 ) return ( msd - 1 ) * a [ d ] + p + countNumbersWith4 ( n % p ) ; return ( msd ) * a [ d ] + countNumbersWith4 ( n % p ) ; } let n = 328 ; document . write ( " " + n + " " + countNumbersWith4 ( n ) ) ;

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minRemovalsDP ( arr , n ) { let longest_start = - 1 , longest_end = 0 ; for ( let start = 0 ; start < n ; start ++ ) { let min = Number . MAX_VALUE , max = Number . MIN_VALUE ; for ( let end = start ; end < n ; end ++ ) { let val = arr [ end ] ; if ( val < min ) { min = val ; } if ( val > max ) { max = val ; } if ( 2 * min <= max ) { break ; } if ( end - start > longest_end - longest_start longest_start == - 1 ) { longest_start = start ; longest_end = end ; } } } if ( longest_start == - 1 ) { return n ; } return ( n - ( longest_end - longest_start + 1 ) ) ; } let arr = [ 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 ] ; let n = arr . length ; document . write ( minRemovalsDP ( arr , n ) ) ;

Index/key variables: end
Accumulator variables: end, start
Iterator variables: end, start
Javascript program:
function arithmeticThree ( set , n ) { for ( let j = 1 ; j < n - 1 ; j ++ ) { let i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] == 2 * set [ j ] ) return true ; ( set [ i ] + set [ k ] < 2 * set [ j ] ) ? k ++ : i -- ; } } return false ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: j
Javascript program:
function optimalStrategyOfGame ( arr , n ) { let table = new Array ( n ) ; let gap , i , j , x , y , z ; for ( let d = 0 ; d < n ; d ++ ) { table [ d ] = new Array ( n ) ; } for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { x = ( ( i + 2 ) <= j ) ? table [ i + 2 ] [ j ] : 0 ; y = ( ( i + 1 ) <= ( j - 1 ) ) ? table [ i + 1 ] [ j - 1 ] : 0 ; z = ( i <= ( j - 2 ) ) ? table [ i ] [ j - 2 ] : 0 ; table [ i ] [ j ] = Math . max ( arr [ i ] + Math . min ( x , y ) , arr [ j ] + Math . min ( y , z ) ) ; } } return table [ 0 ] [ n - 1 ] ; } let arr1 = [ 8 , 15 , 3 , 7 ] ; let n = arr1 . length ; document . write ( " " + optimalStrategyOfGame ( arr1 , n ) + " " ) ; let arr2 = [ 2 , 2 , 2 , 2 ] ; n = arr2 . length ; document . write ( " " + optimalStrategyOfGame ( arr2 , n ) + " " ) ; let arr3 = [ 20 , 30 , 2 , 2 , 2 , 10 ] ; n = arr3 . length ; document . write ( " " + optimalStrategyOfGame ( arr3 , n ) ) ;

Index/key variables: d, i, j
Accumulator variables: d
Iterator variables: d, gap, i
Javascript program:
function maxSumIS ( arr , n ) { let i , j , max = 0 ; let msis = new Array ( n ) ; for ( i = 0 ; i < n ; i ++ ) msis [ i ] = arr [ i ] ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ; return max ; } let arr = [ 1 , 101 , 2 , 3 , 100 , 4 , 5 ] ; let n = arr . length ; document . write ( " " + " " + maxSumIS ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const printLeftPath = ( i , j , K ) => { if ( K & 1 ) { for ( let p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { document . write ( ` ${ i } ` ) ; } else { document . write ( ` ${ j } ` ) ; } } } else { for ( let p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { document . write ( ` ${ j } ` ) ; } else { document . write ( ` ${ i } ` ) ; } } } } const printRightPath = ( j , k , K ) => { if ( K & 1 ) { for ( let p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { document . write ( ` ${ K } ` ) ; } else { document . write ( ` ${ j } ` ) ; } } } else { for ( let p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { document . write ( ` ${ K } ` ) ; } else { document . write ( ` ${ j } ` ) ; } } } } const constructPalindromicPath = ( edges , n , K ) => { let adj = new Array ( n + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( n + 1 ) . fill ( 0 ) ) ; for ( let i = 0 ; i < edges . length ; i ++ ) { adj [ edges [ i ] [ 0 ] [ 0 ] ] [ edges [ i ] [ 0 ] [ 1 ] ] = edges [ i ] [ 1 ] ; } if ( K & 1 ) { document . write ( ` ` ) ; for ( let i = 1 ; i <= K + 1 ; i ++ ) { document . write ( ` ${ ( i & 1 ) + 1 } ` ) ; } return ; } let found = 0 ; let idx1 , idx2 ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( i == j ) { continue ; } if ( adj [ i ] [ j ] == adj [ j ] [ i ] ) { found = 1 ; idx1 = i ; idx2 = j ; } } } if ( found ) { document . write ( ` ` ) for ( let i = 1 ; i <= K + 1 ; i ++ ) { if ( i & 1 ) { document . write ( ` ${ idx1 } ` ) ; } else { document . write ( ` ${ idx2 } ` ) ; } } return ; } else { let mp1 = new Array ( n + 1 ) . fill ( [ ] ) ; let mp2 = new Array ( n + 1 ) . fill ( [ ] ) ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( i == j ) { continue ; } if ( adj [ i ] [ j ] == ' ' ) { mp1 [ i ] . push ( j ) ; } else { mp2 [ i ] . push ( j ) ; } } } for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( j == i ) { continue ; } if ( adj [ i ] [ j ] == ' ' ) { if ( mp1 [ j ] . size ( ) ) { let k = mp1 [ j ] [ 0 ] ; if ( k == i k == j ) { continue ; } document . write ( ` ` ) ; K -= 2 ; K = parseInt ( k / 2 ) ; printLeftPath ( i , j , K ) ; document . write ( ` ${ i } ${ j } ${ k } ` ) ; printRightPath ( j , k , K ) ; return ; } } } } for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( j == i ) { continue ; } if ( adj [ i ] [ j ] == ' ' ) { if ( mp1 [ j ] . length ) { let k = mp1 [ j ] [ 0 ] ; if ( k == i k == j ) { continue ; } document . write ( ` ` ) ; K -= 2 ; K = parseInt ( k / 2 ) ; printLeftPath ( i , j , K ) ; document . write ( ` ${ i } ${ j } ${ k } ` ) ; printRightPath ( j , k , K ) ; return ; } } } } } document . write ( " " ) ; } let N = 3 , K = 4 ; let edges = [ [ [ 1 , 2 ] , ' ' ] , [ [ 1 , 3 ] , ' ' ] , [ [ 2 , 1 ] , ' ' ] , [ [ 2 , 3 ] , ' ' ] , [ [ 3 , 1 ] , ' ' ] , [ [ 3 , 2 ] , ' ' ] ] ; constructPalindromicPath ( edges , N , K ) ;

Index/key variables: i, j
Accumulator variables: K, i, j, p
Iterator variables: i, j, p
Javascript program:
function checkArray ( arr , N , k ) { if ( N < 3 ) return - 1 ; let i , Sum = 0 , temp = 0 ; for ( i = 0 ; i < N ; i ++ ) Sum += arr [ i ] ; let R = ( k * k + k + 1 ) ; if ( Sum % R != 0 ) return 0 ; let Mid = k * ( Sum / R ) ; for ( i = 1 ; i < N - 1 ; i ++ ) { temp += arr [ i - 1 ] ; if ( arr [ i ] == Mid ) { if ( temp == Mid / k ) return i + 1 ; else return 0 ; } } return 0 ; } let arr = [ 5 , 1 , 4 , 20 , 6 , 15 , 9 , 10 ] ; let N = arr . length ; let K = 2 ; document . write ( checkArray ( arr , N , K ) + " " ) ;

Index/key variables: i
Accumulator variables: Sum, i, temp
Iterator variables: i
Javascript program:
function encodeString ( str ) { let res = " " ; let small = new Array ( 26 ) . fill ( 0 ) , capital = new Array ( 26 ) . fill ( 0 ) , num = new Array ( 26 ) . fill ( 0 ) ; let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { num [ str [ i ] . charCodeAt ( 0 ) - 48 ] = i ; } else if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { small [ str [ i ] . charCodeAt ( 0 ) - 97 ] = i ; } else if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { capital [ str [ i ] . charCodeAt ( 0 ) - 65 ] = i ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) && small [ str [ i ] . charCodeAt ( 0 ) - 97 ] == i ) { let occ = str [ i ] . charCodeAt ( 0 ) - 96 ; while ( occ -- ) { res += str [ i ] ; } } else if ( ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) && capital [ str [ i ] . charCodeAt ( 0 ) - 65 ] == i ) { let occ = str [ i ] . charCodeAt ( 0 ) - 64 ; while ( occ -- ) { res += str [ i ] ; } } else if ( ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) && num [ str [ i ] . charCodeAt ( 0 ) - 48 ] == i ) { let occ = str [ i ] . charCodeAt ( 0 ) - 48 ; while ( occ -- ) { res += str [ i ] ; } } else { res += str [ i ] ; } } document . write ( res ) ; } let str = " " ; encodeString ( str ) ;

Index/key variables: i
Accumulator variables: i, occ, res
Iterator variables: i
Javascript program:
function possibleEqualArray ( A , N ) { let pref = new Array ( N ) ; pref [ 0 ] = A [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { pref [ i ] = pref [ i - 1 ] ^ A [ i ] ; } if ( pref [ N - 1 ] == 0 ) { document . write ( " " ) ; return ; } let cur_xor = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { cur_xor ^= A [ i ] ; for ( let j = 0 ; j < i ; j ++ ) { if ( j ) { let middle_xor = pref [ j - 1 ] ^ pref [ i - 1 ] ; let left_xor = pref [ j - 1 ] ; let right_xor = cur_xor ; if ( left_xor == middle_xor && middle_xor == right_xor ) { document . write ( " " ) ; return ; } } } } document . write ( " " ) ; } let A = [ 0 , 2 , 2 ] ; let N = A . length ; possibleEqualArray ( A , N ) ;

Index/key variables: i
Accumulator variables: cur_xor, i, j
Iterator variables: i, j
Javascript program:
function GenerateArray ( N , X ) { let prev_xor = X ; for ( let i = 1 ; i <= N ; i ++ ) { document . write ( ( i ^ prev_xor ) ) ; if ( i != N ) { document . write ( " " ) ; } prev_xor = i ; } } let N = 4 , X = 3 ; document . write ( " " ) ; GenerateArray ( N , X ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function createGrid ( grid , is1 , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( is1 ) { grid [ i ] [ j ] = " " ; is1 = false ; } else { grid [ i ] [ j ] = " " ; is1 = true ; } } if ( M % 2 == 0 ) is1 = ! is1 ; } } function testGrid ( testGrid , Grid , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( Grid [ i ] [ j ] != " " ) { if ( Grid [ i ] [ j ] != testGrid [ i ] [ j ] ) { return false ; } } } } return true ; } function printGrid ( grid , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( grid [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function findPossibleGrid ( N , M , grid ) { let gridTest1 = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( 1001 ) ) ; let gridTest2 = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( 1001 ) ) ; createGrid ( gridTest1 , true , N , M ) ; createGrid ( gridTest2 , false , N , M ) ; if ( testGrid ( gridTest1 , grid , N , M ) ) { document . write ( " " ) ; printGrid ( gridTest1 , N , M ) ; } else if ( testGrid ( gridTest2 , grid , N , M ) ) { document . write ( " " ) ; printGrid ( gridTest2 , N , M ) ; } else { document . write ( " " ) ; } } let N = 4 , M = 4 ; let grid = [ [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , [ " " , " " , " " , " " ] , ] ; findPossibleGrid ( N , M , grid ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: is1
Javascript program:
const INF64 = 1000000000000000000 ; const N = 200 * 1000 + 13 ; let n ; let arr = Array ( N ) ; let brr = Array ( N ) ; function brute ( ind , l , r ) { if ( ind == n / 2 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( brr [ i ] + " " ) ; exit ( 0 ) ; } for ( let i = l ; i <= arr [ ind ] / 2 ; ++ i ) if ( arr [ ind ] - i <= r ) { brr [ ind ] = i ; brr [ n - ind - 1 ] = arr [ ind ] - i ; brute ( ind + 1 , i , arr [ ind ] - i ) ; } } n = 2 ; n *= 2 ; arr [ 0 ] = 5 ; arr [ 1 ] = 6 ; brute ( 0 , 0 , INF64 ) ;

Index/key variables: i, ind
Accumulator variables: i, n
Iterator variables: i
Javascript program:
function modifylet ( s , s1 , s2 ) { let ans = " " ; for ( let i = 0 ; i < s . length ; i ++ ) { let k = 0 ; if ( s [ i ] == s1 [ k ] && i + s1 . length <= s . length ) { let j ; for ( j = i ; j < i + s1 . length ; j ++ ) { if ( s [ j ] != s1 [ k ] ) { break ; } else { k = k + 1 ; } } if ( j == i + s1 . length ) { ans = ans + s2 ; i = j - 1 ; } else { ans = ans + s [ i ] ; } } else { ans = ans + s [ i ] ; } } document . write ( ans ) ; } let S = " " ; let S1 = " " ; let S2 = " " ; modifylet ( S , S1 , S2 ) ;

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minCount ( N , K ) { let SmallestNumber = new Array ( 10 ) ; let MinimumSteps = new Array ( 10 ) ; for ( let i = 0 ; i <= 9 ; i ++ ) { SmallestNumber [ i ] = Number . MAX_VALUE ; MinimumSteps [ i ] = Number . MAX_VALUE ; } for ( let i = 1 ; i <= 10 ; i ++ ) { let num = K * i ; SmallestNumber [ num % 10 ] = Math . min ( SmallestNumber [ num % 10 ] , num ) ; MinimumSteps [ num % 10 ] = Math . min ( MinimumSteps [ num % 10 ] , i ) ; } if ( N < SmallestNumber [ N % 10 ] ) { return - 1 ; } else { return MinimumSteps [ N % 10 ] ; } } let N = 42 , K = 7 ; document . write ( minCount ( N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countMinSteps ( arr , N ) { let val = 0 ; let mx = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < N ; i ++ ) { let curr = arr [ i ] ; mx = Math . max ( mx , curr ) ; val = Math . max ( val , mx - curr ) ; } let res = 0 ; while ( ( 1 << res ) - 1 < val ) { ++ res ; } return res ; } let arr = [ 1 , 7 , 6 , 5 ] ; let N = arr . length ; document . write ( countMinSteps ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function setBits ( n ) { var count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } function findNthTerm ( N ) { var x = setBits ( N ^ ( N - 1 ) ) ; document . write ( x ) ; } var N = 8 ; findNthTerm ( N ) ;

Accumulator variables: count
Javascript program:
function findMinMoves ( arr , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % N != 0 ) return - 1 ; let avg = sum / N ; let total = 0 ; let needCount = 0 ; for ( let i = 0 ; i < N ; i ++ ) { needCount += ( arr [ i ] - avg ) ; total = Math . max ( Math . max ( Math . abs ( needCount ) , arr [ i ] - avg ) , total ) ; } return total ; } let arr = [ 1 , 0 , 5 ] ; let N = arr . length ; document . write ( findMinMoves ( arr , N ) )

Index/key variables: i
Accumulator variables: i, needCount, sum
Iterator variables: i
Javascript program:
function find ( N , Arr ) { var amount = 0 ; var mid_odd = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { var siz = Arr [ i ] . length ; for ( var j = 0 ; j < siz / 2 ; j ++ ) amount = amount + Arr [ i ] [ j ] ; if ( siz % 2 == 1 ) mid_odd . push ( Arr [ i ] [ siz / 2 ] ) ; } mid_odd . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < mid_odd . length ; i ++ ) if ( i % 2 == 0 ) amount = amount + mid_odd [ i ] ; document . write ( amount + " " ) ; } var N = 2 ; var Arr = [ [ 5 , 2 , 3 , 4 ] , [ 1 , 6 ] ] ; find ( N , Arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkPattern ( arr , m , k , n ) { let count = 1 , t = 0 ; for ( let i = 0 ; i < n - m ; i ++ ) { if ( arr [ i ] == arr [ i + m ] ) { t ++ ; if ( t == m ) { t = 0 ; count ++ ; if ( count == k ) { return " " ; } } } else { t = 0 ; count = 1 ; } } return " " ; } let arr = [ 6 , 1 , 3 , 3 , 3 , 3 ] ; let M = 1 , K = 3 ; let N = arr . length ; document . write ( checkPattern ( arr , M , K , N ) ) ;

Index/key variables: i
Accumulator variables: count, i, t
Iterator variables: i
Javascript program:
function getZarr ( str , Z ) { let n = str . length ; let k ; let L = 0 ; let R = 0 ; for ( let i = 1 ; i < n ; ++ i ) { if ( i > R ) { L = R = i ; while ( R < n && str [ R - L ] == str [ R ] ) { R ++ ; } Z [ i ] = R - L ; R -- ; } else { k = i - L ; if ( Z [ k ] < R - i + 1 ) { Z [ i ] = Z [ k ] ; } else { L = i ; while ( R < n && str [ R - L ] == str [ R ] ) { R ++ ; } Z [ i ] = R - L ; R -- ; } } } } function goodStr ( str , word ) { let concat = word + " " + str ; let l = concat . length ; let Z = new Array ( l ) ; getZarr ( concat , Z ) ; let res = " " ; let pSize = word . length ; for ( let i = 0 ; i < l ; ++ i ) { if ( i + pSize < l - 1 && Z [ i + pSize + 1 ] == pSize ) { i += pSize - 1 ; } else if ( i < str . length ) { res += str [ i ] ; } } return res ; } let str = " " ; let word = " " ; document . write ( goodStr ( str , word ) ) ;

Index/key variables: R, i, k
Accumulator variables: R, i, res
Iterator variables: i
Javascript program:
function findOccurrences ( S , T ) { let n1 = S . length ; let n2 = T . length ; let ans = 0 ; let last = 0 ; for ( let i = 0 ; i <= n1 - n2 ; i ++ ) { let chk = true ; for ( let j = 0 ; j < n2 ; j ++ ) { if ( T [ j ] != S [ i + j ] ) { chk = false ; break ; } } if ( chk ) { ans += ( i + 1 - last ) * ( n1 - ( i + n2 - 1 ) ) ; last = i + 1 ; } } document . write ( ans ) ; } let S = " " , T = " " ; findOccurrences ( S , T ) ;

Index/key variables: j
Accumulator variables: ans, i, j
Iterator variables: i, j
Boolean variables: chk
Javascript program:
function LargestArray ( N , low , high ) { let high_index = N - ( high - low + 1 ) ; if ( high_index > ( N - 1 ) / 2 ) { document . write ( " " ) ; return ; } if ( high_index <= 0 ) high_index = 1 ; let A = [ ] ; let temp = high ; for ( let i = high_index ; i >= 0 ; i -- ) { A [ i ] = temp -- ; } high -= 1 ; for ( let i = high_index + 1 ; i < N ; i ++ ) A [ i ] = high -- ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let N = 5 , low = 2 , high = 6 ; LargestArray ( N , low , high ) ;

Index/key variables: i
Accumulator variables: high, i, temp
Iterator variables: i
Javascript program:
function printDiagonalTraversal ( nums ) { let max_size = nums [ 0 ] . length ; let v = [ ] ; for ( let i = 0 ; i < 2 * max_size - 1 ; i ++ ) { v . push ( [ ] ) ; } for ( let i = 0 ; i < nums [ 0 ] . length ; i ++ ) { for ( let j = 0 ; j < nums [ 0 ] . length ; j ++ ) { v [ i + j ] . push ( nums [ i ] [ j ] ) ; } } for ( let i = 0 ; i < v . length ; i ++ ) { for ( let j = v [ i ] . length - 1 ; j >= 0 ; j -- ) { document . write ( v [ i ] [ j ] + " " ) ; } } } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; printDiagonalTraversal ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isValid ( s ) { let n = Math . sqrt ( s . length ) ; let check = s [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { let x = i , y = i ; while ( x >= 0 && y < n ) { if ( s [ ( n * x ) + y ] != check || s [ ( n * y ) + x ] != check ) { document . write ( " " ) ; return ; } x -- ; y ++ ; } } document . write ( " " ) ; } let str = " " ; isValid ( str ) ;

Accumulator variables: i, x, y
Iterator variables: i
Javascript program:
var N = 10 ; var pref = new Array ( N ) . fill ( 0 ) ; var power = new Array ( N ) . fill ( 0 ) ; function toDigit ( ch ) { return ch - " " ; } function powerOf10 ( ) { power [ 0 ] = 1 ; for ( var i = 1 ; i < N ; i ++ ) power [ i ] = power [ i - 1 ] * 10 ; } function precomputePrefix ( str , n ) { pref [ 0 ] = str [ 0 ] - " " ; for ( var i = 1 ; i < n ; i ++ ) pref [ i ] = pref [ i - 1 ] + toDigit ( str [ i ] ) ; } function triangularNumber ( i ) { var res = parseInt ( ( i * ( i + 1 ) ) / 2 ) ; return res ; } function sumOfSubStrings ( str ) { var n = str . length ; powerOf10 ( ) ; precomputePrefix ( str . split ( " " ) , n ) ; var ans = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { ans += ( pref [ n - i - 2 ] * ( i + 1 ) + toDigit ( str [ n - i - 1 ] ) * triangularNumber ( n - i - 1 ) ) * power [ i ] ; } return ans ; } var str = " " ; document . write ( sumOfSubStrings ( str ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function OddLengthSum ( arr ) { var sum = 0 ; var l = arr . length ; for ( var i = 0 ; i < l ; i ++ ) { for ( var j = i ; j < l ; j += 2 ) { for ( var k = i ; k <= j ; k ++ ) { sum += arr [ k ] ; } } } return sum ; } var arr = [ 1 , 5 , 3 , 1 , 2 ] document . write ( OddLengthSum ( arr ) ) ;

Index/key variables: k
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
function OddLengthSum ( arr ) { let sum = 0 ; let l = arr . length ; for ( let i = 0 ; i < l ; i ++ ) { sum += Math . floor ( ( ( i + 1 ) * ( l - i ) + 1 ) / 2 ) * arr [ i ] ; } return sum ; } let arr = [ 1 , 5 , 3 , 1 , 2 ] ; document . write ( OddLengthSum ( arr ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function phi ( n ) { let result = 1 ; for ( let p = 2 ; p < n ; p ++ ) { if ( __gcd ( p , n ) == 1 ) { result ++ ; } } return result ; } function sameEulerTotient ( n ) { return phi ( n ) == phi ( 2 * n ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let N = 13 ; if ( sameEulerTotient ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: p, result
Iterator variables: p
Javascript program:
function solve ( arr , N ) { var M = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { M . set ( i , arr [ i ] ) ; } arr . sort ( ( a , b ) => a - b ) ; var Count = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { Count . set ( arr [ i ] , parseInt ( Math . pow ( 2 , N - i - 1 ) ) ) ; } M . forEach ( ( value , key ) => { document . write ( Count . get ( value ) + ' ' ) ; } ) ; } var arr = [ 5 , 2 , 1 ] ; var N = arr . length ; solve ( arr , N ) ;

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