dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function getStudentsList ( file , n ) { let avgScore ; let maxAvgScore = Number . MIN_SAFE_INTEGER ; let names = [ ] ; for ( let i = 0 ; i < n ; i += 4 ) { avgScore = Math . floor ( ( Number ( file [ i + 1 ] ) + Number ( file [ i + 2 ] ) + Number ( file [ i + 3 ] ) ) / 3 ) ; if ( avgScore > maxAvgScore ) { maxAvgScore = avgScore ; names = [ ] ; names . push ( file [ i ] ) ; } else if ( avgScore == maxAvgScore ) names . push ( file [ i ] ) ; } for ( let i = 0 ; i < names . length ; i ++ ) { document . write ( names [ i ] + " " ) ; } document . write ( maxAvgScore ) ; } let file = [ " " , " " , " " , " " , " " , " " , " " , " " ] ; let n = file . length ; getStudentsList ( file , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX_LEN = 1005 ; let MAX_CHAR = 26 ; let ALL_CHARS = 256 ; function compare ( arr1 , arr2 ) { for ( let i = 0 ; i < ALL_CHARS ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } function search ( pat , txt ) { let M = pat . length ; let N = txt . length ; let i ; let countP = new Array ( ALL_CHARS ) ; countP . fill ( 0 ) ; let countTW = new Array ( ALL_CHARS ) ; countTW . fill ( 0 ) ; for ( i = 0 ; i < M ; i ++ ) { countP [ pat [ i ] . charCodeAt ( ) ] ++ ; countTW [ txt [ i ] . charCodeAt ( ) ] ++ ; } for ( i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) { return true ; } countTW [ txt [ i ] . charCodeAt ( ) ] ++ ; countTW [ txt [ i - M ] . charCodeAt ( ) ] -- ; } if ( compare ( countP , countTW ) ) return true ; return false ; } function calculatesubString ( s1 , s2 , n ) { let count = 0 , j = 0 , x = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let len = 1 ; len <= n - i ; len ++ ) { if ( search ( s1 . substring ( i , i + len ) , s2 ) ) { count = count + 1 ; } } } return count ; } let str1 = " " ; let str2 = " " ; let len = str1 . length ; document . write ( calculatesubString ( str1 , str2 , len ) ) ;

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i, len
Javascript program:
function strScore ( str , s , n ) { var score = 0 , index = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( str [ i ] == s ) { for ( j = 0 ; j < s . length ; j ++ ) { score += s . charAt ( j ) . charCodeAt ( 0 ) - ( ' ' ) . charCodeAt ( 0 ) + 1 ; } index = i + 1 ; break ; } } score = score * index ; return score ; } str = [ " " , " " , " " , " " , " " ] ; s = " " ; var n = str . length ; var score = strScore ( str , s , n ) ; document . write ( score ) ;

Index/key variables: i
Accumulator variables: i, j, score
Iterator variables: i, j
Javascript program:
function find ( parent , i ) { if ( parent [ i ] == - 1 ) return i ; return find ( parent , parent [ i ] ) ; } function Union ( parent , x , y ) { let xset = find ( parent , x ) ; let yset = find ( parent , y ) ; parent [ xset ] = yset ; }

Index/key variables: i, xset
Javascript program:
function isAlphaNumeric ( str ) { var code , i , len ; for ( i = 0 , len = str . length ; i < len ; i ++ ) { code = str . charCodeAt ( i ) ; return false ; } } return true ; } ; function K_thletter ( S , K ) { var N = S . length ; var size = 0 ; for ( var i = 0 ; i < N ; ++ i ) { if ( Number . isInteger ( parseInt ( S [ i ] ) ) ) size = size * ( S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; else size += 1 ; } for ( var i = N - 1 ; i >= 0 ; -- i ) { K %= size ; if ( K == 0 && isAlphaNumeric ( S [ i ] ) ) return " " + S [ i ] ; if ( Number . isInteger ( parseInt ( S [ i ] ) ) ) size = size / ( S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; else size -= 1 ; } } var S = " " ; var K = 15 ; document . write ( K_thletter ( S , K ) ) ;

Index/key variables: i
Accumulator variables: i, size
Iterator variables: i
Javascript program:
function minParentheses ( p ) { var bal = 0 ; var ans = 0 ; for ( var i = 0 ; i < p . length ; ++ i ) { bal += p [ i ] == ' ' ? 1 : - 1 ; if ( bal == - 1 ) { ans += 1 ; bal += 1 ; } } return bal + ans ; } var p = " " ; document . write ( minParentheses ( p ) ) ;

Index/key variables: i
Accumulator variables: ans, bal
Iterator variables: i
Javascript program:
function isPalindrome ( r ) { var p = r ; p . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; return ( r == p ) ; } function CheckStr ( s ) { var l = s . length ; var i ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substring ( 0 , i ) ) ) break ; } if ( i == ( l + 1 ) ) return false ; i = 2 ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substring ( l - i , l ) ) ) return true ; } return false ; } var s = " " ; if ( CheckStr ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function oddEquivalent ( s , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) count ++ ; } return count ; } var s = " " ; var n = s . length ; document . write ( oddEquivalent ( s , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function getSmallestAndLargest ( s , k ) { var currStr = s . substring ( 0 , k ) ; var lexMin = currStr ; var lexMax = currStr ; for ( var i = k ; i < s . length ; i ++ ) { currStr = currStr . substring ( 1 , k ) + s [ i ] ; if ( lexMax < currStr ) lexMax = currStr ; if ( lexMin > currStr ) lexMin = currStr ; } document . write ( lexMin + " " ) ; document . write ( lexMax + " " ) ; } var str = " " ; var k = 3 ; getSmallestAndLargest ( str , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findNumberOfTimes ( str1 , str2 ) { let freq = new Array ( 26 ) ; let freq2 = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { freq [ i ] = 0 ; freq2 [ i ] = 0 ; } let l1 = str1 . length ; for ( let i = 0 ; i < l1 ; i ++ ) { freq [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let l2 = str2 . length ; for ( let i = 0 ; i < l2 ; i ++ ) { freq2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let count = Number . MAX_VALUE ; for ( let i = 0 ; i < l2 ; i ++ ) { if ( freq2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] != 0 ) count = Math . min ( count , freq [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] / freq2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ) ; } return count ; } let str1 = " " ; let str2 = " " ; document . write ( findNumberOfTimes ( str1 , str2 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( s1 , s2 ) { let flag1 = 0 , flag2 = 0 ; if ( s1 . length != s2 . length ) return false ; let l = s1 . length ; for ( let i = 0 ; i < l ; i ++ ) { if ( s1 [ i ] == ' ' ) flag1 = 1 ; if ( s2 [ i ] == ' ' ) flag2 = 1 ; if ( flag1 && flag2 ) return true ; } if ( ! flag1 && ! flag2 ) return true ; return false ; } let s1 = " " ; let s2 = " " ; if ( solve ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nextGreatestAlphabet ( alphabets , K ) { var l = 0 , r = alphabets . length - 1 ; var ans = - 1 ; while ( l <= r ) { var mid = ( l + r ) / 2 ; if ( alphabets [ mid ] > K ) { ans = mid ; r = mid - 1 ; } else l = mid + 1 ; } return alphabets [ ans ] ; } var letters = [ " " , " " , " " ] ; var K = " " ; document . write ( nextGreatestAlphabet ( letters , K ) ) ;

Index/key variables: ans, mid
Javascript program:
function subzero ( s , k ) { let ans = 0 , curr = 0 ; let len = s . length ; let str = s . split ( " " ) ; for ( let i = 0 ; i < len ; ++ i ) { if ( str [ i ] == ' ' ) curr ++ ; else curr = 0 ; ans = Math . max ( ans , curr ) ; } if ( ans == len ) return len * k ; else { let pre = 0 , suff = 0 ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) pre ++ ; else break ; } for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) suff ++ ; else break ; } if ( k > 1 ) ans = Math . max ( ans , pre + suff ) ; return ans ; } } let str = " " ; let k = 5 ; document . write ( subzero ( str , k ) ) ;

Index/key variables: i
Accumulator variables: curr, i, pre, suff
Iterator variables: i
Javascript program:
function Dragon_Curve_Sequence ( n ) { let s = " " ; for ( let i = 2 ; i <= n ; i ++ ) { let temp = " " ; let prev = ' ' ; let zero = ' ' ; let one = ' ' ; for ( let j = 0 ; j < s . length ; j ++ ) { temp = temp + s [ j ] ; if ( prev == ' ' ) { temp += one ; prev = one ; } else { temp += zero ; prev = zero ; } } s = temp ; } return s ; } let n = 4 ; let s = Dragon_Curve_Sequence ( n ) ; document . write ( s + " " ) ;

Index/key variables: j
Accumulator variables: i, j, temp
Iterator variables: i, j
Javascript program:
function findSubstrings ( s , k ) { var ans = 0 ; var cnt = Array ( 26 ) ; var i , j , n = s . length ; for ( i = 0 ; i < n ; i ++ ) { cnt = Array ( 26 ) . fill ( 0 ) ; for ( j = i ; j < n ; j ++ ) { cnt [ ( s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ] ++ ; if ( cnt [ ( s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ] <= k ) ans ++ ; else break ; } } return ans ; } var S = " " ; var k = 2 ; document . write ( findSubstrings ( S , k ) ) ;

Index/key variables: j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let MAX = 26 ; function targetstring ( str1 , str2 ) { let l1 = str1 . length ; let l2 = str2 . length ; if ( l1 != l2 ) return false ; let map = new Array ( MAX ) ; for ( let i = 0 ; i < map . length ; i ++ ) { map [ i ] = 0 ; } for ( let i = 0 ; i < l1 ; i ++ ) map [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < l2 ; i ++ ) { map [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; if ( map [ str2 [ i ] - ' ' . charCodeAt ( 0 ) ] < 0 ) return false ; } return true ; } let str1 = " " ; let str2 = " " ; if ( targetstring ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isDigitPresent ( x , d ) { while ( x > 0 ) { if ( x % 10 == d ) break ; x = x / 10 ; } return ( x > 0 ) ; } function printNumbers ( n , d ) { for ( let i = 0 ; i <= n ; i ++ ) if ( i == d || isDigitPresent ( i , d ) ) document . write ( i + " " ) ; } let n = 47 , d = 7 ; printNumbers ( n , d ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findExtraCharcter ( strA , strB ) { let m1 = new Array ( 256 ) ; for ( let i = 0 ; i < 256 ; i ++ ) m1 [ i ] = 0 ; for ( let i = 0 ; i < strB . length ; i ++ ) m1 [ strB [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < strA . length ; i ++ ) m1 [ strA [ i ] . charCodeAt ( 0 ) ] -- ; for ( let i = 0 ; i < m1 . length ; i ++ ) { if ( m1 [ i ] == 1 ) return String . fromCharCode ( i ) ; } return Number . MIN_VALUE ; } let strA = " " ; let strB = " " ; document . write ( findExtraCharcter ( strA . split ( " " ) , strB . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findExtraCharcter ( strA , strB ) { let res = 0 ; for ( let i = 0 ; i < strA . length ; i ++ ) { res ^= strA . charCodeAt ( i ) ; } for ( let i = 0 ; i < strB . length ; i ++ ) { res ^= strB . charCodeAt ( i ) ; } return res ; } let strA = " " ; let strB = " " ; document . write ( String . fromCharCode ( findExtraCharcter ( strA , strB ) ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function findExtraCharacter ( s1 , s2 ) { let smallStr ; let largeStr ; if ( s1 . length > s2 . length ) { smallStr = s2 ; largeStr = s1 ; } else { smallStr = s1 ; largeStr = s2 ; } let smallStrCodeTotal = 0 ; let largeStrCodeTotal = 0 ; let i = 0 ; for ( ; i < smallStr . length ; i ++ ) { smallStrCodeTotal += smallStr [ i ] . charCodeAt ( 0 ) ; largeStrCodeTotal += largeStr [ i ] . charCodeAt ( 0 ) ; } largeStrCodeTotal += largeStr [ i ] . charCodeAt ( 0 ) ; let intChar = largeStrCodeTotal - smallStrCodeTotal ; return String . fromCharCode ( intChar ) ; } let s1 = " " ; let s2 = " " ; let extraChar = findExtraCharacter ( s1 , s2 ) ; document . write ( " " + extraChar ) ;

Index/key variables: i
Accumulator variables: i, largeStrCodeTotal, smallStrCodeTotal
Javascript program:
function myCopy ( s1 , s2 ) { let i = 0 ; for ( i = 0 ; i < s1 . length ; i ++ ) s2 [ i ] = s1 [ i ] ; } let s1 = " " ; let s2 = [ ] ; let index = 0 ; myCopy ( s1 , s2 , index ) ; document . write ( s2 . join ( " " ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateSum ( arr , n ) { if ( n == 0 ) return 0 ; let s = arr [ 0 ] ; let value = parseInt ( s ) ; let sum = value ; for ( let i = 2 ; i < n ; i = i + 2 ) { s = arr [ i ] ; value = parseInt ( s ) ; let operation = arr [ i - 1 ] [ 0 ] ; if ( operation == ' ' ) sum += value ; else sum -= value ; } return sum ; } let arr = [ " " , " " , " " , " " , " " , " " , " " ] ; let n = arr . length ; document . write ( calculateSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Javascript program:
var MAX_CHAR = 26 ; function twoStrings ( s1 , s2 ) { var v = Array ( MAX_CHAR ) . fill ( 0 ) ; for ( var i = 0 ; i < s1 . length ; i ++ ) v [ s1 [ i ] - ' ' ] = true ; for ( var i = 0 ; i < s2 . length ; i ++ ) if ( v [ s2 [ i ] - ' ' ] ) return true ; return false ; } var str1 = " " ; var str2 = " " ; if ( twoStrings ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LargestString ( na ) { let N = na . length ; let c = new Array ( N ) ; let m = 1 ; for ( let j = 0 ; j < N ; j ++ ) { let character = new Array ( 26 , 0 ) ; for ( let k = 0 ; k < na [ j ] . length ; k ++ ) { let x = na [ j ] [ k ] . charCodeAt ( 0 ) - 65 ; if ( ( na [ j ] [ k ] != ' ' ) && ( character [ x ] == 0 ) ) { c [ j ] ++ ; character [ x ] = 1 ; } } if ( c [ j ] > c [ m ] ) m = j ; } document . write ( na [ m ] ) ; } let na = [ " " , " " , " " , " " , " " ] ; LargestString ( na ) ;

Index/key variables: j, k, m, x
Accumulator variables: j, k
Iterator variables: j, k
Javascript program:
var MAX_CHAR = 26 function minRemoval ( str ) { var hash = Array ( MAX_CHAR ) . fill ( 0 ) ; for ( var i = 0 ; str [ i ] ; i ++ ) hash [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var count = 0 ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) if ( hash [ i ] % 2 ) count ++ ; return ( count == 0 ) ? 0 : count - 1 ; } var str = " " ; document . write ( minRemoval ( str ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function modifiedLevelOrder ( node ) { if ( node == null ) return ; if ( node . left == null && node . right == null ) { document . write ( node . data ) ; return ; } let myQueue = [ ] ; let myStack = [ ] ; let temp = null ; let sz ; let ct = 0 ; let rightToLeft = false ; myQueue . push ( node ) ; while ( myQueue . length != 0 ) { ct ++ ; sz = myQueue . length ; for ( let i = 0 ; i < sz ; i ++ ) { temp = myQueue . shift ( ) ; if ( rightToLeft == false ) document . write ( temp . data + " " ) ; else myStack . push ( temp ) ; if ( temp . left != null ) myQueue . push ( temp . left ) ; if ( temp . right != null ) myQueue . push ( temp . right ) ; } if ( rightToLeft == true ) { while ( myStack . length != 0 ) { temp = myStack . pop ( ) ; document . write ( temp . data + " " ) ; } } if ( ct == 2 ) { rightToLeft = ! rightToLeft ; ct = 0 ; } document . write ( " " ) ; } } 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 . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 3 ) ; root . left . right . right = new Node ( 1 ) ; root . right . left . left = new Node ( 4 ) ; root . right . left . right = new Node ( 2 ) ; root . right . right . left = new Node ( 7 ) ; root . right . right . right = new Node ( 2 ) ; root . left . right . left . left = new Node ( 16 ) ; root . left . right . left . right = new Node ( 17 ) ; root . right . left . right . left = new Node ( 18 ) ; root . right . right . left . right = new Node ( 19 ) ; modifiedLevelOrder ( root ) ;

Accumulator variables: ct, i
Iterator variables: i
Boolean variables: rightToLeft
Class/struct names: Node
Javascript program:
function minnode ( n , keyval , mstset ) { let mini = Number . MAX_VALUE ; let mini_index = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( mstset [ i ] == false && keyval [ i ] < mini ) { mini = keyval [ i ] ; mini_index = i ; } } return mini_index ; } function findcost ( n , city ) { let parent = Array ( n ) . fill ( 0 ) ; let keyval = Array ( n ) . fill ( 0 ) ; let mstset = Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { keyval [ i ] = Number . MAX_VALUE ; mstset [ i ] = false ; } parent [ 0 ] = - 1 ; keyval [ 0 ] = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let u = minnode ( n , keyval , mstset ) ; mstset [ u ] = true ; for ( let v = 0 ; v < n ; v ++ ) { if ( city [ u ] [ v ] > 0 && mstset [ v ] == false && city [ u ] [ v ] < keyval [ v ] ) { keyval [ v ] = city [ u ] [ v ] ; parent [ v ] = u ; } } } let cost = 0 ; for ( let i = 1 ; i < n ; i ++ ) cost += city [ parent [ i ] ] [ i ] ; document . write ( cost + " " ) ; } let n1 = 5 ; let city1 = [ [ 0 , 1 , 2 , 3 , 4 ] , [ 1 , 0 , 5 , 0 , 7 ] , [ 2 , 5 , 0 , 6 , 0 ] , [ 3 , 0 , 6 , 0 , 0 ] , [ 4 , 7 , 0 , 0 , 0 ] ] ; findcost ( n1 , city1 ) ; let n2 = 6 ; let city2 = [ [ 0 , 1 , 1 , 100 , 0 , 0 ] , [ 1 , 0 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 0 , 0 , 0 ] , [ 100 , 0 , 0 , 0 , 2 , 2 ] , [ 0 , 0 , 0 , 2 , 0 , 2 ] , [ 0 , 0 , 0 , 2 , 2 , 0 ] ] ; findcost ( n2 , city2 ) ;

Index/key variables: i, u, v
Accumulator variables: cost, i, v
Iterator variables: i, v
Javascript program:
let LEFT = 0 ; let RIGHT = 1 ; function ChangeDirection ( Dir ) { Dir = 1 - Dir ; return Dir ; } class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function modifiedLevelOrder ( root ) { if ( root == null ) return ; let dir = LEFT ; let temp ; let Q = [ ] ; let S = [ ] ; S . push ( root ) ; while ( Q . length != 0 S . length != 0 ) { while ( S . length != 0 ) { temp = S . pop ( ) ; document . write ( temp . data + " " ) ; if ( dir == LEFT ) { if ( temp . left != null ) Q . push ( temp . left ) ; if ( temp . right != null ) Q . push ( temp . right ) ; } else { if ( temp . right != null ) Q . push ( temp . right ) ; if ( temp . left != null ) Q . push ( temp . left ) ; } } document . write ( " " ) ; while ( Q . length != 0 ) { temp = Q [ 0 ] ; Q . shift ( ) ; document . write ( temp . data + " " ) ; if ( dir == LEFT ) { if ( temp . left != null ) S . push ( temp . left ) ; if ( temp . right != null ) S . push ( temp . right ) ; } else { if ( temp . right != null ) S . push ( temp . right ) ; if ( temp . left != null ) S . push ( temp . left ) ; } } document . write ( " " ) ; dir = ChangeDirection ( dir ) ; } } 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 . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 3 ) ; root . left . right . right = new Node ( 1 ) ; root . right . left . left = new Node ( 4 ) ; root . right . left . right = new Node ( 2 ) ; root . right . right . left = new Node ( 7 ) ; root . right . right . right = new Node ( 2 ) ; root . left . right . left . left = new Node ( 16 ) ; root . left . right . left . right = new Node ( 17 ) ; root . right . left . right . left = new Node ( 18 ) ; root . right . right . left . right = new Node ( 19 ) ; modifiedLevelOrder ( root ) ;

Class/struct names: Node
Javascript program:
let N = 8 ; function isSafe ( x , y , sol ) { return ( x >= 0 && x < N && y >= 0 && y < N && sol [ x ] [ y ] == - 1 ) ; } function printSolution ( sol ) { for ( let x = 0 ; x < N ; x ++ ) { for ( let y = 0 ; y < N ; y ++ ) document . write ( sol [ x ] [ y ] + " " ) ; document . write ( " " ) ; } } function solveKT ( ) { let sol = new Array ( 8 ) ; for ( var i = 0 ; i < sol . length ; i ++ ) { sol [ i ] = new Array ( 2 ) ; } for ( let x = 0 ; x < N ; x ++ ) for ( let y = 0 ; y < N ; y ++ ) sol [ x ] [ y ] = - 1 ; let xMove = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ] ; let yMove = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ] ; sol [ 0 ] [ 0 ] = 0 ; if ( ! solveKTUtil ( 0 , 0 , 1 , sol , xMove , yMove ) ) { document . write ( " " ) ; return false ; } else printSolution ( sol ) ; return true ; } function solveKTUtil ( x , y , movei , sol , xMove , yMove ) { let k , next_x , next_y ; if ( movei == N * N ) return true ; for ( k = 0 ; k < 8 ; k ++ ) { next_x = x + xMove [ k ] ; next_y = y + yMove [ k ] ; if ( isSafe ( next_x , next_y , sol ) ) { sol [ next_x ] [ next_y ] = movei ; if ( solveKTUtil ( next_x , next_y , movei + 1 , sol , xMove , yMove ) ) return true ; else sol [ next_x ] [ next_y ] = - 1 ; } } return false ; } solveKT ( ) ;

Index/key variables: i, k, next_x, next_y, x, y
Accumulator variables: i, k, x, y
Iterator variables: i, k, x, y
Javascript program:
let V = 4 ; function printSolution ( color ) { document . write ( " " + " " ) ; for ( let i = 0 ; i < V ; i ++ ) document . write ( " " + color [ i ] ) ; document . write ( " " ) ; } function isSafe ( graph , color ) { for ( let i = 0 ; i < V ; i ++ ) for ( let j = i + 1 ; j < V ; j ++ ) if ( graph [ i ] [ j ] && color [ j ] == color [ i ] ) return false ; return true ; } function graphColoring ( graph , m , i , color ) { if ( i == V ) { if ( isSafe ( graph , color ) ) { printSolution ( color ) ; return true ; } return false ; } for ( let j = 1 ; j <= m ; j ++ ) { color [ i ] = j ; if ( graphColoring ( graph , m , i + 1 , color ) ) return true ; color [ i ] = 0 ; } return false ; } let graph = [ [ false , true , true , true ] , [ true , false , true , false ] , [ true , true , false , true ] , [ true , false , true , false ] ] ; let m = 3 ; let color = new Array ( V ) ; for ( let i = 0 ; i < V ; i ++ ) color [ i ] = 0 ; if ( ! graphColoring ( graph , m , 0 , color ) ) document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function cntMaxOperationToMakeN_1_0 ( arr , N ) { let cntOp = 0 ; let PQ = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { PQ . push ( arr [ i ] ) ; } PQ . sort ( function ( a , b ) { return a - b } ) ; PQ . reverse ( ) ; while ( PQ . length > 1 ) { let X = PQ [ 0 ] ; PQ . shift ( ) ; let Y = PQ [ 0 ] ; PQ . shift ( ) ; X -- ; Y -- ; if ( X != 0 ) { PQ . push ( X ) ; PQ . sort ( function ( a , b ) { return a - b } ) ; PQ . reverse ( ) ; } if ( Y != 0 ) { PQ . push ( Y ) ; PQ . sort ( function ( a , b ) { return a - b } ) ; PQ . reverse ( ) ; } cntOp += 1 ; } return cntOp ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; document . write ( cntMaxOperationToMakeN_1_0 ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: X, Y, cntOp, i
Iterator variables: i
Javascript program:
function generateMatrix ( N ) { let odd = 1 ; let even = 2 ; let mat = new Array ( N + 1 ) ; for ( var i = 0 ; i < mat . length ; i ++ ) { mat [ i ] = new Array ( 2 ) ; } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= N ; j ++ ) { if ( ( i + j ) % 2 == 0 ) { mat [ i ] [ j ] = odd ; odd += 2 ; } else { mat [ i ] [ j ] = even ; even += 2 ; } } } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= N ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let N = 4 ; generateMatrix ( N ) ;

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