dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = this . right = null ; } } var root ; function printInorder ( node ) { if ( node != null ) { printInorder ( node . left ) ; document . write ( node . data + " " ) ; printInorder ( node . right ) ; } } function RemoveHalfNodes ( node ) { if ( node == null ) return null ; node . left = RemoveHalfNodes ( node . left ) ; node . right = RemoveHalfNodes ( node . right ) ; if ( node . left == null && node . right == null ) return node ; if ( node . left == null ) { new_root = node . right ; return new_root ; } if ( node . right == null ) { new_root = node . left ; return new_root ; } return node ; } NewRoot = null ; root = new Node ( 2 ) ; root . left = new Node ( 7 ) ; root . right = new Node ( 5 ) ; root . left . right = new Node ( 6 ) ; root . left . right . left = new Node ( 1 ) ; root . left . right . right = new Node ( 11 ) ; root . right . right = new Node ( 9 ) ; root . right . right . left = new Node ( 4 ) ; document . write ( " " ) ; printInorder ( root ) ; NewRoot = RemoveHalfNodes ( root ) ; document . write ( " " ) ; printInorder ( NewRoot ) ; script

Class/struct names: Node
Javascript program:
function strToBinary ( s ) { let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { let val = ( s [ i ] ) . charCodeAt ( 0 ) ; let bin = " " ; while ( val > 0 ) { if ( val % 2 == 1 ) { bin += ' ' ; } else bin += ' ' ; val = Math . floor ( val / 2 ) ; } bin = reverse ( bin ) ; document . write ( bin + " " ) ; } } function reverse ( input ) { a = input . split ( " " ) ; let l , r = 0 ; 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 s = " " ; strToBinary ( s ) ;

Index/key variables: i, l, r
Accumulator variables: bin, i, l, r
Iterator variables: i, l
Javascript program:
function binarySearch ( arr , low , high , x ) { if ( low > high ) return - 1 ; let mid = Math . floor ( ( low + high ) / 2 ) ; if ( arr [ mid ] == " " ) { let left = mid - 1 ; let right = mid + 1 ; while ( true ) { if ( left < low && right > high ) return - 1 ; if ( left >= low && arr [ left ] != " " ) { mid = left ; break ; } else if ( right <= high && arr [ right ] != " " ) { mid = right ; break ; } left -- ; right ++ ; } } if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] > x ) return binarySearch ( arr , low , mid - 1 , x ) ; else return binarySearch ( arr , mid + 1 , high , x ) ; } function sparseSearch ( arr , x , n ) { return binarySearch ( arr , 0 , n - 1 , x ) ; } let arr = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let x = " " ; let n = x . length ; let index = sparseSearch ( arr , x , n ) ; if ( index != - 1 ) document . write ( x + " " + index ) ; else document . write ( x + " " ) ;

Index/key variables: left, mid, right
Accumulator variables: left, right
Javascript program:
function factorial ( n ) { let f = 1 ; for ( let i = 1 ; i <= n ; i ++ ) f = f * i ; return f ; } function print ( temp ) { for ( let i = 0 ; i < temp . length ; i ++ ) document . write ( temp [ i ] ) ; document . write ( " " ) ; } function calculateTotal ( temp , n ) { let f = factorial ( n ) ; let hm = new Map ( ) ; for ( let i = 0 ; i < temp . length ; i ++ ) { if ( hm . has ( temp [ i ] ) ) hm . set ( temp [ i ] , hm . get ( temp [ i ] ) + 1 ) ; else hm . set ( temp [ i ] , 1 ) ; } for ( let [ key , value ] of hm . entries ( ) ) { let x = value ; if ( x > 1 ) { let temp5 = factorial ( x ) ; f = Math . floor ( f / temp5 ) ; } } return f ; } function nextPermutation ( temp ) { let i ; for ( i = temp . length - 1 ; i > 0 ; i -- ) if ( temp [ i ] > temp [ i - 1 ] ) break ; let min = i ; let j , x = temp [ i - 1 ] ; for ( j = i + 1 ; j < temp . length ; j ++ ) if ( ( temp [ j ] < temp [ min ] ) && ( temp [ j ] > x ) ) min = j ; let temp_to_swap ; temp_to_swap = temp [ i - 1 ] ; temp [ i - 1 ] = temp [ min ] ; temp [ min ] = temp_to_swap ; temp = temp . slice ( 0 , i ) . sort ( ) . concat ( temp . slice ( i , temp . length ) ) ; print ( temp ) ; } function printAllPermutations ( s ) { let temp = s . split ( " " ) ; temp . sort ( ) ; print ( temp ) ; let total = calculateTotal ( temp , temp . length ) ; for ( let i = 1 ; i < total ; i ++ ) nextPermutation ( temp ) ; } let s = " " ; printAllPermutations ( s ) ;

Index/key variables: i, j, min
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printSequence ( arr , input ) { let output = " " ; let n = input . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( input [ i ] == ' ' ) output = output + " " . charCodeAt ( 0 ) ; else { let position = input [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; output = output + arr [ position ] ; } } return output ; } let str = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] let input = " " ; document . write ( printSequence ( str , input ) ) ;

Index/key variables: i, position
Accumulator variables: i
Iterator variables: i
Javascript program:
function findLUSlength ( a , b ) { let map = new Map ( ) ; let strArr = [ ] ; strArr . push ( a ) ; strArr . push ( b ) ; for ( let s = 0 ; s < strArr . length ; s ++ ) { for ( let i = 0 ; i < ( 1 << strArr [ s ] . length ) ; i ++ ) { let t = " " ; for ( let j = 0 ; j < strArr [ s ] . length ; j ++ ) { if ( ( ( i >> j ) & 1 ) != 0 ) t += strArr [ s ] [ j ] ; } if ( map . has ( t ) ) map . set ( t , map . get ( t ) + 1 ) ; else map . set ( t , 1 ) ; } } let res = 0 ; for ( let [ key , value ] of map . entries ( ) ) { if ( value == 1 ) res = Math . max ( res , key . length ) ; } return res ; } let a = " " , b = " " ; document . write ( findLUSlength ( a , b ) ) ;

Index/key variables: j, s
Accumulator variables: i, j, s, t
Iterator variables: i, j, s
Javascript program:
function round ( s , n ) { let c = s . split ( ' ' ) ; if ( c [ n - 1 ] == ' ' ) return s ; else if ( c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' ) { c [ n - 1 ] = ' ' ; return c . join ( " " ) ; } else { c [ n - 1 ] = ' ' ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( c [ i ] == ' ' ) c [ i ] = ' ' ; else { let t = c [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ; c [ i ] = String . fromCharCode ( 48 + t ) ; break ; } } } let s1 = c . join ( " " ) ; if ( s1 [ 0 ] == ' ' ) s1 = " " + s1 ; return s1 ; } let s = " " ; let n = s . length ; document . write ( round ( s , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isEven ( s ) { let l = s . length ; let dotSeen = false ; for ( let i = l - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' && dotSeen == false ) continue ; if ( s [ i ] == ' ' ) { dotSeen = true ; continue ; } if ( ( s [ i ] - ' ' ) % 2 == 0 ) return true ; return false ; } } let s = " " ; if ( isEven ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: dotSeen
Javascript program:
function minCost ( s ) { var alphabets = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < s . length ; i ++ ) { alphabets [ s [ i ] . charCodeAt ( 0 ) - 97 ] = true ; } var count = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( alphabets [ i ] ) { count ++ ; } } return count ; } var s = " " ; document . write ( " " + s + " " + minCost ( s . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function checkingPossibility ( a , n , s ) { let mark = new Array ( a [ 0 ] * n ) ; mark . fill ( 0 ) ; let start = 0 ; let possible = 1 ; while ( start >= 0 && start < n ) { if ( s == " " ) { if ( mark [ start ] == 0 ) { mark [ start ] = 1 ; start -= a [ start ] ; } else { possible = 0 ; break ; } } else { if ( mark [ start ] == 0 ) { mark [ start ] = 1 ; start += a [ start ] ; } else { possible = 0 ; break ; } } } if ( possible == 0 ) document . write ( " " + " " ) ; else document . write ( " " ) ; } let n = 2 ; let s = " " ; let a = [ 1 , 2 ] ; checkingPossibility ( a , n , s ) ;

Index/key variables: start
Accumulator variables: start
Javascript program:
function simplify ( path ) { let v = [ ] ; let n = path . length ; let ans = " " ; for ( let i = 0 ; i < n ; i ++ ) { let dir = " " ; while ( i < n && path [ i ] != ' ' ) { dir += path [ i ] ; i ++ ; } if ( dir == " " ) { if ( v . length > 0 ) v . pop ( ) ; } else if ( dir == " " dir == " " ) { } else { v . push ( dir ) ; } } for ( let i of v ) { ans += " " + i ; } if ( ans == " " ) return " " ; return ans ; } let Str = " " ; let res = simplify ( Str ) ; document . write ( res ) ;

Index/key variables: i
Accumulator variables: ans, dir, i
Iterator variables: i
Javascript program:
let NO_OF_CHARS = 256 ; function max_distinct_char ( str , n ) { let count = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { count [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } let max_distinct = 0 ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( count [ i ] != 0 ) { max_distinct ++ ; } } return max_distinct ; } function smallesteSubstr_maxDistictChar ( str ) { let n = str . length ; let max_distinct = max_distinct_char ( str , n ) ; let minl = n ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { let subs = null ; if ( i < j ) subs = str . substring ( i , j ) ; else subs = str . substring ( j , i ) ; let subs_lenght = subs . length ; let sub_distinct_char = max_distinct_char ( subs , subs_lenght ) ; if ( subs_lenght < minl && max_distinct == sub_distinct_char ) { minl = subs_lenght ; } } } return minl ; } let str = " " ; let len = smallesteSubstr_maxDistictChar ( str ) ; document . write ( " " + " " + " " + len ) ;

Index/key variables: i
Accumulator variables: i, j, max_distinct
Iterator variables: i, j
Javascript program:
function evaluateBoolExpr ( s ) { let n = s . length ; for ( let i = 0 ; i < n ; i += 2 ) { if ( i + 1 < n && i + 2 < n ) { if ( s [ i + 1 ] == ' ' ) { if ( s [ i + 2 ] == ' ' s [ i ] == 0 ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } else if ( ( i + 1 ) < n && s [ i + 1 ] == ' ' ) { if ( s [ i + 2 ] == ' ' s [ i ] == ' ' ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } else { if ( s [ i + 2 ] == s [ i ] ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } } } return ( s [ n - 1 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; } let s = " " ; let sb = s . split ( ' ' ) ; document . write ( evaluateBoolExpr ( sb ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function FirstRepeated ( str ) { let checker = 0 ; for ( let i = 0 ; i < str . length ; ++ i ) { let val = ( str [ i ] - ' ' ) ; if ( ( checker & ( 1 << val ) ) > 0 ) return i ; checker |= ( 1 << val ) ; } return - 1 ; } let s = " " ; let i = FirstRepeated ( s ) ; if ( i != - 1 ) document . write ( " " + s [ i ] + " " + i ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: checker
Iterator variables: i
Javascript program:
let alphabets = " " ; function panLipogramChecker ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) { s [ i ] = s [ i ] . toLowerCase ; } let counter = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { let pos = s . search ( alphabets [ i ] ) ; if ( pos < 0 pos > s . length ) counter += 1 ; } if ( counter == 0 ) document . write ( " " ) ; else if ( counter >= 2 ) document . write ( " " + " " ) ; else document . write ( " " ) ; } let str = " " + " " ; panLipogramChecker ( str ) ; document . write ( " " ) ; str = " " + " " ; panLipogramChecker ( str ) ; document . write ( " " ) ; str = " " + " " ; panLipogramChecker ( str ) ;

Index/key variables: i
Accumulator variables: counter, i
Iterator variables: i
Javascript program:
function splitString ( str ) { let alpha = " " ; let num = " " ; let special = " " ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( ! isNaN ( String ( str [ i ] ) * 1 ) ) num += str [ i ] ; else if ( ( str [ i ] >= ' ' && str [ i ] <= ' ' ) || ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ) alpha += str [ i ] ; else special += str [ i ] ; } document . write ( alpha + " " ) ; document . write ( num + " " ) ; document . write ( special + " " ) ; } let str = " " ; splitString ( str ) ;

Index/key variables: i
Accumulator variables: alpha, i, num, special
Iterator variables: i
Javascript program:
function SubString ( str , n ) { for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j <= n ; j ++ ) document . write ( str . substring ( i , j ) + " " ) ; } var str = " " ; SubString ( str , str . length ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printSubstrings ( str ) { var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { for ( var k = i ; k <= j ; k ++ ) { document . write ( str . charAt ( k ) ) ; } document . write ( " " ) ; } } } var str = " " ; printSubstrings ( str ) ;

Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let n ; function solve ( i , X , Y , a , b , n ) { if ( i == n ) return 0 ; if ( X <= 0 ) return b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) ; if ( Y <= 0 ) return a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) ; else return Math . max ( a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) , b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) ) ; } let a = [ 1 , 2 , 3 , 4 , 5 ] ; let b = [ 5 , 4 , 3 , 2 , 1 ] ; n = a . length ; let x = 3 , y = 3 ; document . write ( solve ( 0 , x , y , a , b , n ) ) ;

Index/key variables: i
Javascript program:
function evenNumSubstring ( str ) { let len = str . length ; let count = 0 ; for ( let i = 0 ; i < len ; i ++ ) { let temp = str [ i ] - ' ' ; if ( temp % 2 == 0 ) count += ( i + 1 ) ; } return count ; } let str = " " ; document . write ( evenNumSubstring ( str ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isSubSequence ( str1 , str2 ) { var m = str1 . length , n = str2 . length ; for ( var i = 0 ; i < n && j < m ; i ++ ) if ( str1 [ j ] == str2 [ i ] ) j ++ ; return ( j == m ) ; } function findLongestString ( dict , str ) { var result = " " ; var length = 0 ; dict . forEach ( word => { if ( length < word . length && isSubSequence ( word , str ) ) { result = word ; length = word . length ; } } ) ; return result ; } var dict = [ " " , " " , " " , " " ] ; var str = " " ; document . write ( findLongestString ( dict , str ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function versionCompare ( v1 , v2 ) { var vnum1 = 0 , vnum2 = 0 ; for ( var i = 0 , j = 0 ; ( i < v1 . length j < v2 . length ) ; ) { while ( i < v1 . length && v1 [ i ] != ' ' ) { vnum1 = vnum1 * 10 + ( v1 [ i ] - ' ' ) ; i ++ ; } while ( j < v2 . length && v2 [ j ] != ' ' ) { vnum2 = vnum2 * 10 + ( v2 [ j ] - ' ' ) ; j ++ ; } if ( vnum1 > vnum2 ) return 1 ; if ( vnum2 > vnum1 ) return - 1 ; vnum1 = vnum2 = 0 ; i ++ ; j ++ ; } return 0 ; } var version1 = " " ; var version2 = " " ; if ( versionCompare ( version1 , version2 ) < 0 ) document . write ( version1 + " " + " " ) ; else if ( versionCompare ( version1 , version2 ) > 0 ) document . write ( version2 + " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
let MAX_CHAR = 256 ; function isPalindrome ( str , l , h ) { while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ; return true ; } function check ( str ) { let n = str . length ; let freq = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; if ( freq [ str [ i ] . charCodeAt ( 0 ) ] > 2 ) return true ; } let k = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( freq [ str [ i ] . charCodeAt ( 0 ) ] > 1 ) str . replace ( str [ k ++ ] , str [ i ] ) ; str . replace ( str [ k ] , ' \0 ' ) ; if ( isPalindrome ( str , 0 , k - 1 ) ) { if ( ( k & 1 ) == 1 ) { if ( k / 2 >= 1 ) return ( str [ Math . floor ( k / 2 ) ] == str [ Math . floor ( k / 2 ) - 1 ] ) ; } return false ; } return true ; } let str = " " ; if ( check ( str ) ) document . write ( " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, k
Accumulator variables: h, i, k, l
Iterator variables: i
Javascript program:
function prevPermutation ( str ) { let n = str . length - 1 ; let i = n ; while ( i > 0 && str [ i - 1 ] . charCodeAt ( 0 ) <= str [ i ] . charCodeAt ( 0 ) ) { i -- ; } if ( i <= 0 ) { return false ; } let j = i - 1 ; while ( j + 1 <= n && str [ j + 1 ] . charCodeAt ( 0 ) <= str [ i - 1 ] . charCodeAt ( 0 ) ) { j ++ ; } let temp = str [ i - 1 ] ; str [ i - 1 ] = str [ j ] ; str [ j ] = temp ; return true ; } let str = " " . split ( " " ) ; if ( prevPermutation ( str ) ) { document . write ( " " + ( str ) . join ( " " ) ) ; } else { document . write ( " " + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function isEditDistanceOne ( s1 , s2 ) { let m = s1 . length , n = s2 . length ; if ( Math . abs ( m - n ) > 1 ) return false ; let count = 0 ; let i = 0 , j = 0 ; while ( i < m && j < n ) { if ( s1 [ i ] != s2 [ j ] ) { if ( count == 1 ) return false ; if ( m > n ) i ++ ; else if ( m < n ) j ++ ; else { i ++ ; j ++ ; } count ++ ; } else { i ++ ; j ++ ; } } if ( i < m j < n ) count ++ ; return count == 1 ; } let s1 = " " ; let s2 = " " ; if ( isEditDistanceOne ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Javascript program:
let M = 1000 ; function cntNum ( X , i , sum , tight , dp ) { if ( i >= X . length sum < 0 ) { if ( sum == 0 ) { return 1 ; } return 0 ; } if ( dp [ sum ] [ i ] [ tight ] != - 1 ) { return dp [ sum ] [ i ] [ tight ] ; } let res = 0 ; let end = tight != 0 ? X [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) : 9 ; for ( let j = 0 ; j <= end ; j ++ ) { res += cntNum ( X , i + 1 , sum - j , ( tight > 0 & ( j == end ) ) == true ? 1 : 0 , dp ) ; } return dp [ sum ] [ i ] [ tight ] = res ; } function UtilCntNumRange ( L , R , Y ) { if ( R == 0 && Y == 0 ) { return 1 ; } let str = ( R ) . toString ( ) ; let dp = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { dp [ i ] = new Array ( M ) ; for ( let j = 0 ; j < M ; j ++ ) { dp [ i ] [ j ] = new Array ( 2 ) ; for ( let k = 0 ; k < 2 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } let cntR = cntNum ( str , 0 , Y , 1 , dp ) ; str = ( L - 1 ) . toString ( ) ; for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { for ( let k = 0 ; k < 2 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } let cntL = cntNum ( str , 0 , Y , 1 , dp ) ; return ( cntR - cntL ) ; } let L = 20 , R = 10000 , Y = 14 ; document . write ( UtilCntNumRange ( L , R , Y ) ) ;

Index/key variables: i, j, k, sum, tight
Accumulator variables: i, j, k, res
Iterator variables: i, j, k
Javascript program:
function countSubStr ( str , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( str [ j ] == ' ' ) res ++ ; } } } return res ; } let string = " " ; let n = string . length ; document . write ( countSubStr ( string , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
let str ; function reverse ( low , high ) { while ( low < high ) { let t = str [ low ] ; str [ low ] = str [ high ] ; str [ high ] = t ; ++ low ; -- high ; } } function cycleLeader ( shift , len ) { let j ; let item ; for ( let i = 1 ; i < len ; i *= 3 ) { j = i ; item = str [ j + shift ] ; do { if ( j % 2 == 1 ) j = Math . floor ( len / 2 ) + Math . floor ( j / 2 ) ; else j = Math . floor ( j / 2 ) ; let t = str [ j + shift ] ; str [ j + shift ] = item ; item = t ; } while ( j != i ) ; } } function moveNumberToSecondHalf ( ) { let k , lenFirst ; let lenRemaining = str . length ; let shift = 0 ; while ( lenRemaining > 0 ) { k = 0 ; while ( Math . pow ( 3 , k ) + 1 <= lenRemaining ) k ++ ; lenFirst = Math . floor ( Math . pow ( 3 , k - 1 ) ) + 1 ; lenRemaining -= lenFirst ; cycleLeader ( shift , lenFirst ) ; reverse ( Math . floor ( shift / 2 ) , shift - 1 ) ; reverse ( shift , shift + Math . floor ( lenFirst / 2 ) - 1 ) ; reverse ( Math . floor ( shift / 2 ) , shift + Math . floor ( lenFirst / 2 ) - 1 ) ; shift += lenFirst ; } } let st = " " ; str = st . split ( " " ) ; moveNumberToSecondHalf ( ) ; document . write ( str . join ( " " ) ) ;

Index/key variables: high, low
Accumulator variables: i, k, lenRemaining, shift
Iterator variables: i
Javascript program:
function removeDuplicate ( str , n ) { var s = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) s . add ( str [ i ] ) ; for ( const v of s ) { document . write ( v ) ; } } var str = " " ; var n = str . length ; removeDuplicate ( str , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, v
Javascript program:
var ROW = 0 ; var COL = 0 ; class Point { constructor ( ) { this . x = 0 ; this . y = 0 ; } } ; function newPoint ( x , y ) { var temp = new Point ( ) ; temp . x = x ; temp . y = y ; return temp ; } class Node { constructor ( ) { this . pt = null ; this . dist = 0 ; } } ; function newNode ( p , dist ) { var temp = new Node ( ) ; temp . pt = p ; temp . dist = dist ; return temp ; } function isValid ( row , col ) { return ( row >= 0 ) && ( col >= 0 ) && ( row < ROW ) && ( col < COL ) ; } var dRow = [ - 1 , 0 , 0 , 1 ] ; var dCol = [ 0 , - 1 , 1 , 0 ] ; function pathMoves ( mat , src , dest ) { var d = Array . from ( Array ( ROW ) , ( ) => Array ( COL ) ) ; for ( var i = 0 ; i < ROW ; i ++ ) { for ( var j = 0 ; j < COL ; j ++ ) d [ i ] [ j ] = - 1 ; } d [ src . x ] [ src . y ] = 0 ; var visited = Array . from ( Array ( ROW ) , ( ) => Array ( COL ) ) ; visited [ src . x ] [ src . y ] = true ; var q = [ ] ; var s = newNode ( src , 0 ) ; q . push ( s ) ; var ok = false ; while ( q . length > 0 ) { var curr = q [ 0 ] ; q . shift ( ) ; var pt = curr . pt ; if ( pt . x == dest . x && pt . y == dest . y ) { var xx = pt . x , yy = pt . y ; var dist = curr . dist ; d [ pt . x ] [ pt . y ] = dist ; var pathmoves = " " ; while ( xx != src . x yy != src . y ) { if ( xx > 0 && d [ xx - 1 ] [ yy ] == dist - 1 ) { pathmoves += ' ' ; xx -- ; } if ( xx < ROW - 1 && d [ xx + 1 ] [ yy ] == dist - 1 ) { pathmoves += ' ' ; xx ++ ; } if ( yy > 0 && d [ xx ] [ yy - 1 ] == dist - 1 ) { pathmoves += ' ' ; yy -- ; } if ( yy < COL - 1 && d [ xx ] [ yy + 1 ] == dist - 1 ) { pathmoves += ' ' ; yy ++ ; } dist -- ; } for ( var i = pathmoves . length - 1 ; i >= 0 ; -- i ) document . write ( pathmoves [ i ] ) ; ok = true ; break ; } if ( q . length > 0 ) { q . shift ( ) ; } for ( var i = 0 ; i < 4 ; i ++ ) { var row = pt . x + dRow [ i ] ; var col = pt . y + dCol [ i ] ; if ( isValid ( row , col ) && ( mat [ row ] [ col ] == ' ' mat [ row ] [ col ] == ' ' mat [ row ] [ col ] == ' ' ) && ! visited [ row ] [ col ] ) { visited [ row ] [ col ] = true ; var adjCell = newNode ( newPoint ( row , col ) , curr . dist + 1 ) ; q . push ( adjCell ) ; d [ row ] [ col ] = curr . dist + 1 ; } } } if ( ok == false ) document . write ( - 1 ) ; } var mat = [ [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] ] ; ROW = mat . length ; COL = mat [ 0 ] . length ; var src = newPoint ( 0 , 3 ) ; var dest = newPoint ( 3 , 0 ) ; pathMoves ( mat , src , dest ) ;

Index/key variables: col, i, j, row, xx, yy
Accumulator variables: dist, i, j, pathmoves, xx, yy
Iterator variables: i, j
Boolean variables: ok
Class/struct names: Node, Point