dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } class BinaryTree { constructor ( ) { this . root = null ; } printSingles ( node ) { if ( node == null ) { return ; } if ( node . left != null && node . right != null ) { this . printSingles ( node . left ) ; this . printSingles ( node . right ) ; } else if ( node . right != null ) { document . write ( node . right . data + " " ) ; this . printSingles ( node . right ) ; } else if ( node . left != null ) { document . write ( node . left . data + " " ) ; this . printSingles ( node . left ) ; } } } var tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . right = new Node ( 4 ) ; tree . root . right . left = new Node ( 5 ) ; tree . root . right . left . right = new Node ( 6 ) ; tree . printSingles ( tree . root ) ;

Class/struct names: BinaryTree, Node
Javascript program:
class Node { constructor ( item ) { this . left = null ; this . right = null ; this . data = item ; } } let root ; function kDistantFromLeafUtil ( node , path , visited , pathLen , k ) { if ( node == null ) return ; path [ pathLen ] = node . data ; visited [ pathLen ] = false ; pathLen ++ ; if ( node . left == null && node . right == null && ( pathLen - k - 1 ) >= 0 && visited [ pathLen - k - 1 ] == false ) { document . write ( path [ pathLen - k - 1 ] + " " ) ; visited [ pathLen - k - 1 ] = true ; return ; } kDistantFromLeafUtil ( node . left , path , visited , pathLen , k ) ; kDistantFromLeafUtil ( node . right , path , visited , pathLen , k ) ; } function printKDistantfromLeaf ( node , k ) { let path = new Array ( 1000 ) ; path . fill ( 0 ) ; let visited = new Array ( 1000 ) ; visited . fill ( false ) ; kDistantFromLeafUtil ( node , path , visited , 0 , k ) ; } 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 . right . left . right = new Node ( 8 ) ; document . write ( " " ) ; printKDistantfromLeaf ( root , 2 ) ;

Index/key variables: pathLen
Accumulator variables: pathLen
Class/struct names: Node
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } class BinaryTree { constructor ( ) { this . root = null ; } printKDistantfromLeaf ( node , k ) { if ( node == null ) return - 1 ; var lk = this . printKDistantfromLeaf ( node . left , k ) ; var rk = this . printKDistantfromLeaf ( node . right , k ) ; var isLeaf = lk == - 1 && lk == rk ; if ( lk == 0 || rk == 0 || ( isLeaf && k == 0 ) ) document . write ( " " + node . data ) ; if ( isLeaf && k > 0 ) return k - 1 ; if ( lk > 0 && lk < k ) return lk - 1 ; if ( rk > 0 && rk < k ) return rk - 1 ; return - 2 ; } } var tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . right . left . right = new Node ( 8 ) ; document . write ( " " ) ; tree . printKDistantfromLeaf ( tree . root , 2 ) ;

Class/struct names: BinaryTree, Node
Javascript program:
let COUNT = 10 ; class Node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } function print2DUtil ( root , space ) { if ( root == null ) return ; space += COUNT ; print2DUtil ( root . right , space ) ; document . write ( " " ) ; for ( let i = COUNT ; i < space ; i ++ ) document . write ( " " ) ; document . write ( root . data + " " ) ; print2DUtil ( root . left , space ) ; } function print2D ( root ) { print2DUtil ( root , 0 ) ; } 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 ( 10 ) ; root . left . right . right = new Node ( 11 ) ; root . right . left . left = new Node ( 12 ) ; root . right . left . right = new Node ( 13 ) ; root . right . right . left = new Node ( 14 ) ; root . right . right . right = new Node ( 15 ) ; print2D ( root ) ;

Accumulator variables: i, space
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } var root ; var max_level = 0 ; function leftViewUtil ( node , level ) { if ( node == null ) { return ; } if ( max_level < level ) { document . write ( " " + node . data ) ; max_level = level ; } leftViewUtil ( node . left , level + 1 ) ; leftViewUtil ( node . right , level + 1 ) ; } function leftView ( ) { leftViewUtil ( root , 1 ) ; } root = new Node ( 12 ) ; root . left = new Node ( 10 ) ; root . right = new Node ( 30 ) ; root . right . left = new Node ( 25 ) ; root . right . right = new Node ( 40 ) ; leftView ( ) ;

Class/struct names: Node
Javascript program:
function rotate ( arr , N , X ) { let nextPower = 1 ; while ( nextPower <= N ) nextPower *= 2 ; if ( X == 1 ) return nextPower - N ; let prevPower = nextPower / 2 ; return 2 * ( N - prevPower ) + 1 ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let X = 1 ; let N = arr . length ; document . write ( rotate ( arr , N , X ) ) ;

Accumulator variables: nextPower
Javascript program:
function findRotation ( mat , T ) { if ( T . length != mat . length T [ 0 ] . length != mat [ 0 ] . length ) { return " " ; } let m = new Map ( ) ; for ( let i = 0 ; i < mat . length ; i ++ ) { if ( m . has ( mat [ i ] ) ) { m . set ( mat [ i ] , m . get ( mat [ i ] ) + 1 ) } else { m . set ( mat [ i ] , 1 ) } mat [ i ] . reverse ( ) ; if ( m . has ( mat [ i ] ) ) { m . set ( mat [ i ] , m . get ( mat [ i ] ) + 1 ) } else { m . set ( mat [ i ] , 1 ) } } for ( let i = 0 ; i < mat [ 0 ] . length ; i ++ ) { let r = [ ] ; for ( let j = 0 ; j < mat . length ; j ++ ) { r . push ( mat [ j ] [ i ] ) ; } if ( m . has ( r ) ) { m . set ( r , m . get ( r ) + 1 ) } else { m . set ( r , 1 ) } r . reverse ( ) ; if ( m . has ( r ) ) { m . set ( r , m . get ( r ) + 1 ) } else { m . set ( r , 1 ) } } for ( let i = 0 ; i < T . length ; i ++ ) { if ( m . get ( T [ i ] ) <= 0 ) { return " " ; } m . set ( T [ i ] , m . get ( T [ i ] ) - 1 ) ; } for ( let i = 0 ; i < T [ 0 ] . length ; i ++ ) { let r = [ ] ; for ( let j = 0 ; j < T . length ; j ++ ) { r . push ( T [ j ] [ i ] ) ; } if ( m . get ( r ) <= 0 ) { return " " ; } m . set ( r , m . get ( r ) - 1 ) ; } return " " ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; let T = [ [ 3 , 6 , 9 ] , [ 2 , 5 , 8 ] , [ 1 , 4 , 7 ] ] ; document . write ( findRotation ( mat , T ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMaximumZeros ( str , n ) { var c0 = 0 ; var i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] == ' ' ) c0 ++ ; } if ( c0 == n ) { document . write ( n ) ; return ; } var s = str + str ; var mx = 0 ; var j ; for ( i = 0 ; i < n ; ++ i ) { var cs = 0 ; var ce = 0 ; for ( j = i ; j < i + n ; ++ j ) { if ( s [ j ] == ' ' ) cs ++ ; else break ; } for ( j = i + n - 1 ; j >= i ; -- j ) { if ( s [ j ] == ' ' ) ce ++ ; else break ; } var val = cs + ce ; mx = Math . max ( val , mx ) ; } document . write ( mx ) ; } var s = " " ; var n = s . length ; findMaximumZeros ( s , n ) ;

Index/key variables: i, j
Accumulator variables: c0, ce, cs
Iterator variables: i, j
Javascript program:
function findMaximumZeros ( str , n ) { var c0 = 0 ; for ( var i = 0 ; i < n ; ++ i ) { if ( str [ i ] == ' ' ) c0 ++ ; } if ( c0 == n ) { document . write ( n ) ; return ; } var mx = 0 ; var cnt = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) cnt ++ ; else { mx = Math . max ( mx , cnt ) ; cnt = 0 ; } } mx = Math . max ( mx , cnt ) ; var start = 0 , end = n - 1 ; cnt = 0 ; while ( str [ start ] != ' ' && start < n ) { cnt ++ ; start ++ ; } while ( str [ end ] != ' ' && end >= 0 ) { cnt ++ ; end -- ; } mx = Math . max ( mx , cnt ) ; document . write ( mx ) ; } var s = " " ; var n = s . length ; findMaximumZeros ( s , n ) ;

Index/key variables: end, i, start
Accumulator variables: c0, cnt, end, i, start
Iterator variables: i
Javascript program:
function reverse ( arr , start , end ) { while ( start < end ) { let temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; start ++ ; end -- ; } } function rotateMatrix ( mat ) { let i = 0 ; for ( let rows = 0 ; rows < mat . length ; rows ++ ) { reverse ( mat [ rows ] , 0 , mat [ rows ] . length - 1 ) ; reverse ( mat [ rows ] , 0 , i - 1 ) ; reverse ( mat [ rows ] , i , mat [ rows ] . length - 1 ) ; i ++ ; } for ( let rows = 0 ; rows < mat . length ; rows ++ ) { for ( let cols = 0 ; cols < mat [ rows ] . length ; cols ++ ) { document . write ( mat [ rows ] [ cols ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; rotateMatrix ( mat ) ;

Index/key variables: cols, end, rows, start
Accumulator variables: cols, end, i, rows, start
Iterator variables: cols, rows
Javascript program:
function stringShift ( s , shift ) { var val = 0 ; for ( var i = 0 ; i < shift . length ; ++ i ) val += shift [ i ] [ 0 ] == 0 ? - shift [ i ] [ 1 ] : shift [ i ] [ 1 ] ; var len = s . length ; val = val % len ; var result = " " ; if ( val > 0 ) result = s . substring ( len - val , len ) + s . substring ( 0 , len - val ) ; else result = s . substring ( - val , len ) + s . substring ( 0 , - val ) ; document . write ( result ) ; } var s = " " ; var shift = [ [ 0 , 1 ] , [ 1 , 2 ] ] ; stringShift ( s , shift ) ;

Index/key variables: i
Accumulator variables: val
Iterator variables: i
Javascript program:
function rotateArray ( arr , N ) { let v = arr ; v . sort ( ( a , b ) => a - b ) ; for ( let i = 1 ; i <= N ; ++ i ) { let x = arr [ N - 1 ] ; i = N - 1 ; while ( i -- ) { arr [ i ] = arr [ i - 1 ] ; arr [ 0 ] = x ; } let isEqual = arr . every ( ( e , i ) => { return arr [ i ] == v [ i ] } ) if ( isEqual ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let arr = [ 3 , 4 , 5 , 1 , 2 ] ; let N = arr . length ; rotateArray ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findLargestRotation ( num ) { let ans = num ; let len = Math . floor ( Math . log10 ( num ) + 1 ) ; let x = Math . pow ( 10 , len - 1 ) ; for ( let i = 1 ; i < len ; i ++ ) { let lastDigit = num % 10 ; num = parseInt ( num / 10 ) ; num += ( lastDigit * x ) ; if ( num > ans ) { ans = num ; } } document . write ( ans ) ; } let N = 657 ; findLargestRotation ( N ) ;

Accumulator variables: i, num
Iterator variables: i
Javascript program:
function numberOfDigit ( N ) { let digit = 0 ; while ( N > 0 ) { digit ++ ; N = Math . floor ( N / 10 ) ; } return digit ; } function rotateNumberByK ( N , K ) { let X = numberOfDigit ( N ) ; K = ( ( K % X ) + X ) % X ; let left_no = Math . floor ( N / Math . floor ( Math . pow ( 10 , X - K ) ) ) ; N = N % Math . floor ( Math . pow ( 10 , X - K ) ) ; let left_digit = numberOfDigit ( left_no ) ; N = ( N * Math . floor ( Math . pow ( 10 , left_digit ) ) ) + left_no ; document . write ( N ) ; } let N = 12345 , K = 7 ; rotateNumberByK ( N , K ) ;

Accumulator variables: digit
Javascript program:
function minMovesToSort ( arr , N ) { let count = 0 ; let index = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] < arr [ i + 1 ] ) { count ++ ; index = i ; } } if ( count == 0 ) { document . write ( " " ) ; } else if ( count == N - 1 ) { document . write ( N - 1 ) ; } else if ( count == 1 && arr [ 0 ] <= arr [ N - 1 ] ) { document . write ( index + 1 ) ; } else { document . write ( " " ) ; } } let arr = [ 2 , 1 , 5 , 4 , 2 ] ; let N = arr . length ; minMovesToSort ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let N = 3 ; function findMaximumDiagonalSumOMatrixf ( A ) { let maxDiagonalSum = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let curr = 0 ; for ( let j = 0 ; j < N ; j ++ ) { curr += A [ j ] [ ( i + j ) % N ] ; } maxDiagonalSum = Math . max ( maxDiagonalSum , curr ) ; } for ( let i = 0 ; i < N ; i ++ ) { let curr = 0 ; for ( let j = 0 ; j < N ; j ++ ) { curr += A [ ( i + j ) % N ] [ j ] ; } maxDiagonalSum = Math . max ( maxDiagonalSum , curr ) ; } return maxDiagonalSum ; } let mat = [ [ 1 , 1 , 2 ] , [ 2 , 1 , 2 ] , [ 1 , 2 , 2 ] ] ; document . write ( findMaximumDiagonalSumOMatrixf ( mat ) ) ;

Index/key variables: j
Accumulator variables: curr, i, j
Iterator variables: i, j
Javascript program:
function diagonalSumPerfectSquare ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( arr [ ( j + i ) % 7 ] + " " ) ; } document . write ( " " ) ; } } let N = 7 ; let arr = new Array ( N ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = i + 1 ; } diagonalSumPerfectSquare ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function MaxSum ( arr , n , k ) { var i , max_sum = 0 , sum = 0 ; for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } max_sum = sum ; while ( i < n ) { sum = sum - arr [ i - k ] + arr [ i ] ; if ( max_sum < sum ) { max_sum = sum ; } i ++ ; } return max_sum ; } function gcd ( n1 , n2 ) { if ( n2 == 0 ) { return n1 ; } else { return gcd ( n2 , n1 % n2 ) ; } } function RotateArr ( arr , n , d ) { var i = 0 , j = 0 ; d = d % n ; var no_of_sets = gcd ( d , n ) ; for ( i = 0 ; i < no_of_sets ; i ++ ) { var temp = arr [ i ] ; j = i ; while ( true ) { var k = j + d ; if ( k >= n ) k = k - n ; if ( k == i ) break ; arr [ j ] = arr [ k ] ; j = k ; } arr [ j ] = temp ; } return arr ; } function performQuery ( arr , Q , q ) { var N = arr . length ; for ( i = 0 ; i < q ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { arr = RotateArr ( arr , N , Q [ i ] [ 1 ] ) ; for ( var t = 0 ; t < arr . length ; t ++ ) { document . write ( arr [ t ] + " " ) ; } document . write ( " " ) ; } else { document . write ( MaxSum ( arr , N , Q [ i ] [ 1 ] ) + " " ) ; } } } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var q = 5 ; var Q = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 1 , 3 ] , [ 1 , 1 ] , [ 2 , 4 ] ] ; performQuery ( arr , Q , q ) ;

Index/key variables: i, j, k, t
Accumulator variables: i, sum, t
Iterator variables: i, t
Javascript program:
function getMinimumRemoval ( str ) { var n = str . length ; var ans = n ; if ( n % 2 === 0 ) { var freqEven = new Array ( 128 ) . fill ( 0 ) ; var freqOdd = new Array ( 128 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( i % 2 === 0 ) { freqEven [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } else { freqOdd [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } } var evenMax = 0 , oddMax = 0 ; for ( var chr = " " . charCodeAt ( 0 ) ; chr <= " " . charCodeAt ( 0 ) ; chr ++ ) { evenMax = Math . max ( evenMax , freqEven [ chr ] ) ; oddMax = Math . max ( oddMax , freqOdd [ chr ] ) ; } ans = ans - evenMax - oddMax ; } else { var freq = new Array ( 128 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } var strMax = 0 ; for ( var chr = " " . charCodeAt ( 0 ) ; chr <= " " . charCodeAt ( 0 ) ; chr ++ ) { strMax = Math . max ( strMax , freq [ chr ] ) ; } ans = ans - strMax ; } return ans ; } var str = " " ; document . write ( getMinimumRemoval ( str ) ) ;

Index/key variables: chr, i
Accumulator variables: chr, i
Iterator variables: chr, i
Javascript program:
function findAltSubSeq ( s ) { var n = s . length , ans = - 1000000000 ; for ( var i = 0 ; i < 10 ; i ++ ) { for ( var j = 0 ; j < 10 ; j ++ ) { var cur = 0 , f = 0 ; for ( var k = 0 ; k < n ; k ++ ) { if ( f == 0 && s [ k ] - ' ' == i ) { f = 1 ; cur ++ ; } else if ( f == 1 && s [ k ] - ' ' == j ) { f = 0 ; cur ++ ; } } if ( i != j && cur % 2 == 1 ) cur -- ; ans = Math . max ( cur , ans ) ; } } return ans ; } var s = " " ; document . write ( findAltSubSeq ( s ) ) ;

Index/key variables: k
Accumulator variables: cur, i, j, k
Iterator variables: i, j, k
Javascript program:
function getFirstElement ( a , N , K , M ) { K %= N ; let index ; if ( K >= M ) index = ( N - K ) + ( M - 1 ) ; else index = ( M - K - 1 ) ; let result = a [ index ] ; return result ; } let a = [ 1 , 2 , 3 , 4 , 5 ] ; let N = 5 ; let K = 3 , M = 2 ; document . write ( getFirstElement ( a , N , K , M ) ) ;

Index/key variables: index
Javascript program:
function getFirstElement ( a , N , K , M ) { K %= N ; var index = ( K + M - 1 ) % N ; var result = a [ index ] ; return result ; } var a = [ 3 , 4 , 5 , 23 ] ; var N = a . length ; var K = 2 , M = 1 ; document . write ( getFirstElement ( a , N , K , M ) ) ;

Index/key variables: index
Javascript program:
function left_rotate ( arr ) { let last = arr [ 1 ] ; for ( let i = 3 ; i < 6 ; i = i + 2 ) { arr [ i - 2 ] = arr [ i ] ; } arr [ 6 - 1 ] = last ; } function right_rotate ( arr ) { let start = arr [ 6 - 2 ] ; for ( let i = 6 - 4 ; i >= 0 ; i = i - 2 ) { arr [ i + 2 ] = arr [ i ] ; } arr [ 0 ] = start ; } function rotate ( arr ) { left_rotate ( arr ) ; right_rotate ( arr ) ; for ( let i = 0 ; i < 6 ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; rotate ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumMatchingPairs ( perm1 , perm2 , n ) { var left = Array ( n ) ; var right = Array ( n ) ; var mp1 = new Map ( ) , mp2 = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { mp1 . set ( perm1 [ i ] , i ) ; } for ( var j = 0 ; j < n ; j ++ ) { mp2 . set ( perm2 [ j ] , j ) ; } for ( var i = 0 ; i < n ; i ++ ) { var idx2 = mp2 . get ( perm1 [ i ] ) ; var idx1 = i ; if ( idx1 == idx2 ) { left [ i ] = 0 ; right [ i ] = 0 ; } else if ( idx1 < idx2 ) { left [ i ] = ( n - ( idx2 - idx1 ) ) ; right [ i ] = ( idx2 - idx1 ) ; } else { left [ i ] = ( idx1 - idx2 ) ; right [ i ] = ( n - ( idx1 - idx2 ) ) ; } } var freq1 = new Map ( ) , freq2 = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freq1 . has ( left [ i ] ) ) freq1 . set ( left [ i ] , freq1 . get ( left [ i ] ) + 1 ) else freq1 . set ( left [ i ] , 1 ) if ( freq2 . has ( right [ i ] ) ) freq2 . set ( right [ i ] , freq2 . get ( right [ i ] ) + 1 ) else freq2 . set ( right [ i ] , 1 ) } var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , Math . max ( freq1 . get ( left [ i ] ) , freq2 . get ( right [ i ] ) ) ) ; } return ans ; } var P1 = [ 5 , 4 , 3 , 2 , 1 ] ; var P2 = [ 1 , 2 , 3 , 4 , 5 ] ; var n = P1 . length ; document . write ( maximumMatchingPairs ( P1 , P2 , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countRotation ( arr , n ) { for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { return i ; } } return 0 ; } let arr1 = [ 4 , 5 , 1 , 2 , 3 ] ; document . write ( countRotation ( arr1 , arr1 . length ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countRotation ( arr , low , high ) { if ( low > high ) { return 0 ; } let mid = low + Math . floor ( ( high - low ) / 2 ) ; if ( mid < high && arr [ mid ] > arr [ mid + 1 ] ) { return mid + 1 ; } if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) { return mid ; } if ( arr [ mid ] > arr [ low ] ) { return countRotation ( arr , mid + 1 , high ) ; } if ( arr [ mid ] < arr [ high ] ) { return countRotation ( arr , low , mid - 1 ) ; } else { let rightIndex = countRotation ( arr , mid + 1 , high ) ; let leftIndex = countRotation ( arr , low , mid - 1 ) ; if ( rightIndex == 0 ) { return leftIndex ; } return rightIndex ; } } let arr1 = [ 4 , 5 , 1 , 2 , 3 ] ; document . write ( countRotation ( arr1 , 0 , arr1 . length - 1 ) ) ;

Index/key variables: high, low, mid
Javascript program:
function rotatedSumQuery ( arr , n , query , Q ) { let prefix = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { prefix [ i ] = arr [ i ] ; prefix [ i + n ] = arr [ i ] ; } for ( let i = 1 ; i < 2 * n ; i ++ ) prefix [ i ] += prefix [ i - 1 ] ; let start = 0 ; for ( let q = 0 ; q < Q ; q ++ ) { if ( query [ q ] [ 0 ] == 1 ) { let k = query [ q ] [ 1 ] ; start = ( start + k ) % n ; } else if ( query [ q ] [ 0 ] == 2 ) { let L , R ; L = query [ q ] [ 1 ] ; R = query [ q ] [ 2 ] ; if ( start + L == 0 ) document . write ( prefix [ start + R ] + " " ) ; else document . write ( prefix [ start + R ] - prefix [ start + L - 1 ] + " " ) ; } } } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let Q = 5 ; let query = [ [ 2 , 1 , 3 ] , [ 1 , 3 ] , [ 2 , 0 , 3 ] , [ 1 , 4 ] , [ 2 , 3 , 5 ] ] ; let n = arr . length ; rotatedSumQuery ( arr , n , query , Q ) ;

Index/key variables: i, q
Accumulator variables: i, q
Iterator variables: i, q
Javascript program:
function isConversionPossible ( s1 , s2 , x ) { let diff = 0 , n ; n = s1 . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s1 [ i ] == s2 [ i ] ) continue ; diff = ( ( s2 [ i ] . charCodeAt ( 0 ) - s1 [ i ] . charCodeAt ( 0 ) ) + 26 ) % 26 ; if ( diff > x ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let s1 = " " ; let s2 = " " ; let x = 6 ; isConversionPossible ( s1 , s2 , x ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countRotation ( n ) { let count = 0 ; do { let digit = n % 10 ; if ( digit == 0 ) count ++ ; n = parseInt ( n / 10 ) ; } while ( n != 0 ) ; return count ; } let n = 10203 ; document . write ( countRotation ( n ) ) ;

Accumulator variables: count
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } document . write ( " " ) ; } function rightRotate ( head , k ) { if ( head == null ) return head ; var tmp = head ; var len = 1 ; while ( tmp . next != null ) { tmp = tmp . next ; len ++ ; } if ( k > len ) k = k % len ; k = len - k ; if ( k == 0 k == len ) return head ; var current = head ; var cnt = 1 ; while ( cnt < k && current != null ) { current = current . next ; cnt ++ ; } if ( current == null ) return head ; var kthnode = current ; tmp . next = head ; head = kthnode . next ; kthnode . next = null ; return head ; } var head = null ; head = push ( head , 5 ) ; head = push ( head , 4 ) ; head = push ( head , 3 ) ; head = push ( head , 2 ) ; head = push ( head , 1 ) ; var k = 2 ; var updated_head = rightRotate ( head , k ) ; printList ( updated_head ) ;

Accumulator variables: cnt, len
Class/struct names: Node