dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function find_permutations ( arr ) { var cnt = 0 ; var max_ind = - 1 , min_ind = 10000000 ; var n = arr . length ; var index_of = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { index_of . set ( arr [ i ] , i + 1 ) ; } for ( var i = 1 ; i <= n ; i ++ ) { max_ind = Math . max ( max_ind , index_of . get ( i ) ) ; min_ind = Math . min ( min_ind , index_of . get ( i ) ) ; if ( max_ind - min_ind + 1 == i ) cnt ++ ; } return cnt ; } var nums = [ ] ; nums . push ( 2 ) ; nums . push ( 3 ) ; nums . push ( 1 ) ; nums . push ( 5 ) ; nums . push ( 4 ) ; document . write ( find_permutations ( nums ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function calgcd ( a , b ) { if ( b == 0 ) return a ; return calgcd ( b , a % b ) ; } function getCount ( a , n ) { let gcd = 0 ; for ( let i = 0 ; i < n ; i ++ ) gcd = calgcd ( gcd , a [ i ] ) ; let cnt = 0 ; for ( let i = 1 ; i * i <= gcd ; i ++ ) { if ( gcd % i == 0 ) { if ( i * i == gcd ) cnt ++ ; else cnt += 2 ; } } return cnt ; } let a = [ 4 , 16 , 1024 , 48 ] ; let n = a . length ; document . write ( getCount ( a , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function delCost ( s , cost ) { var visited = Array ( s . length ) . fill ( false ) ; var ans = 0 ; for ( i = 0 ; i < s . length ; i ++ ) { if ( visited [ i ] ) { continue ; } var maxDel = 0 ; var totalCost = 0 ; visited [ i ] = true ; for ( j = i ; j < s . length ; j ++ ) { if ( s . charAt ( i ) == s . charAt ( j ) ) { maxDel = Math . max ( maxDel , cost [ j ] ) ; totalCost += cost [ j ] ; visited [ j ] = true ; } } ans += totalCost - maxDel ; } return ans ; } var s = " " ; var cost = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; document . write ( delCost ( s , cost ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j, totalCost
Iterator variables: i, j
Javascript program:
function checkXOR ( arr , N ) { if ( N % 2 == 0 ) { let xro = 0 ; for ( let i = 0 ; i < N ; i ++ ) { xro ^= arr [ i ] ; } if ( xro != 0 ) { document . write ( - 1 + " " ) ; return ; } for ( let i = 0 ; i < N - 3 ; i += 2 ) { document . write ( i + " " + ( i + 1 ) + " " + ( i + 2 ) + " " ) ; } for ( let i = 0 ; i < N - 3 ; i += 2 ) { document . write ( i + " " + ( i + 1 ) + " " + ( N - 1 ) + " " ) ; } } else { for ( let i = 0 ; i < N - 2 ; i += 2 ) { document . write ( i + " " + ( i + 1 ) + " " + ( i + 2 ) + " " ) ; } for ( let i = 0 ; i < N - 2 ; i += 2 ) { document . write ( i + " " + ( i + 1 ) + " " + ( N - 1 ) + " " ) ; } } } let arr = [ 4 , 2 , 1 , 7 , 2 ] ; let N = arr . length ; checkXOR ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, xro
Iterator variables: i
Javascript program:
function make_array_element_even ( arr , N ) { let res = 0 ; let odd_cont_seg = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd_cont_seg ++ ; } else { if ( odd_cont_seg > 0 ) { if ( odd_cont_seg % 2 == 0 ) { res += odd_cont_seg / 2 ; } else { res += ( odd_cont_seg / 2 ) + 2 ; } odd_cont_seg = 0 ; } } } if ( odd_cont_seg > 0 ) { if ( odd_cont_seg % 2 == 0 ) { res += odd_cont_seg / 2 ; } else { res += odd_cont_seg / 2 + 2 ; } } return res ; } let arr = [ 2 , 4 , 5 , 11 , 6 ] ; let N = arr . length ; document . write ( make_array_element_even ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, odd_cont_seg, res
Iterator variables: i
Javascript program:
function zvalue ( nums ) { var m = max_element ( nums ) ; var cnt = 0 ; for ( i = 0 ; i <= m ; i ++ ) { cnt = 0 ; for ( j = 0 ; j < nums . length ; j ++ ) { if ( nums [ j ] >= i ) cnt ++ ; } if ( cnt == i ) return i ; } return - 1 ; } function max_element ( nums ) { var max = nums [ 0 ] ; for ( i = 1 ; i < nums . length ; i ++ ) max = Math . max ( max , nums [ i ] ) ; return max ; } nums = [ 7 , 8 , 9 , 0 , 0 , 1 ] ; document . write ( zvalue ( nums ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function lexico_smallest ( s1 , s2 ) { let M = new Map ( ) ; let S = new Set ( ) ; let pr ; for ( let i = 0 ; i <= s1 . length - 1 ; ++ i ) { if ( M . has ( s1 [ i ] ) ) { M [ s1 [ i ] ] ++ ; } else { M [ s1 [ i ] ] = 1 ; } S . add ( s1 [ i ] ) ; } for ( let i = 0 ; i <= s2 . length - 1 ; ++ i ) { if ( M . has ( s2 [ i ] ) ) { M [ s2 [ i ] ] -- ; } else { M [ s2 [ i ] ] = - 1 ; } } let c = s2 [ 0 ] ; let index = 0 ; let res = " " ; S . forEach ( function ( x ) { if ( x != c ) { for ( let i = 1 ; i <= M [ x ] ; ++ i ) { res += x ; } } else { let j = 0 ; index = res . length ; while ( s2 [ j ] == x ) { j ++ ; } if ( s2 [ j ] < c ) { res += s2 ; for ( let i = 1 ; i <= M [ x ] ; ++ i ) { res += x ; } } else { for ( let i = 1 ; i <= M [ x ] ; ++ i ) { res += x ; } index += M [ x ] ; res += s2 ; } } } ) res = " " ; pr = [ res , index ] ; return pr ; } function lexico_largest ( s1 , s2 ) { let pr = lexico_smallest ( s1 , s2 ) ; let d1 = " " ; for ( let i = pr [ 1 ] - 1 ; i >= 0 ; i -- ) { d1 += pr [ 0 ] [ i ] ; } let d2 = " " ; for ( let i = pr [ 0 ] . length - 1 ; i >= pr [ 1 ] + s2 . length ; -- i ) { d2 += pr [ 0 ] [ i ] ; } let res = d2 + s2 + d1 ; return res ; } let s1 = " " ; let s2 = " " ; document . write ( lexico_smallest ( s1 , s2 ) [ 0 ] + " " ) ; document . write ( lexico_largest ( s1 , s2 ) ) ;

Index/key variables: i, j, x
Accumulator variables: d1, d2, i, index, j, res
Iterator variables: i
Javascript program:
var sz = 100005 ; var tree = Array . from ( Array ( sz ) , ( ) => Array ( ) ) var n ; var vis = Array ( sz ) ; var subtreeSize = Array ( sz ) ; function addEdge ( a , b ) { tree [ a ] . push ( b ) ; tree [ b ] . push ( a ) ; } function dfs ( x ) { vis [ x ] = true ; subtreeSize [ x ] = 1 ; tree [ x ] . forEach ( i => { if ( ! vis [ i ] ) { dfs ( i ) ; subtreeSize [ x ] += subtreeSize [ i ] ; } } ) ; } function countPairs ( a , b ) { var sub = Math . min ( subtreeSize [ a ] , subtreeSize [ b ] ) ; document . write ( sub * ( n - sub ) + " " ) ; } n = 6 ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 4 ) ; addEdge ( 3 , 5 ) ; dfs ( 0 ) ; countPairs ( 1 , 3 ) ; countPairs ( 0 , 2 ) ;

Index/key variables: a, b, i, x
Javascript program:
function findPermutation ( arr , N ) { var pos = arr . size + 1 ; if ( pos > N ) return 1 ; var res = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( ! arr . has ( i ) ) { if ( i % pos == 0 pos % i == 0 ) { arr . add ( i ) ; res += findPermutation ( arr , N ) ; arr . delete ( i ) ; } } } return res ; } var N = 5 ; var arr = new Set ( ) ; document . write ( findPermutation ( arr , N ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function solve ( arr , n , X , Y ) { var diff = Y - X ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != 1 ) { diff = diff % ( arr [ i ] - 1 ) ; } } if ( diff == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 1 , 2 , 7 , 9 , 10 ] ; var n = arr . length ; var X = 11 , Y = 13 ; solve ( arr , n , X , Y ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxN = 100001 ; let adj = new Array ( maxN ) ; adj . fill ( 0 ) ; let height = new Array ( maxN ) ; height . fill ( 0 ) ; let dist = new Array ( maxN ) ; dist . fill ( 0 ) ; function addEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function dfs1 ( cur , par ) { for ( let u = 0 ; u < adj [ cur ] . length ; u ++ ) { if ( adj [ cur ] [ u ] != par ) { dfs1 ( adj [ cur ] [ u ] , cur ) ; height [ cur ] = Math . max ( height [ cur ] , height [ adj [ cur ] [ u ] ] ) ; } } height [ cur ] += 1 ; } function dfs2 ( cur , par ) { let max1 = 0 ; let max2 = 0 ; for ( let u = 0 ; u < adj [ cur ] . length ; u ++ ) { if ( adj [ cur ] [ u ] != par ) { if ( height [ adj [ cur ] [ u ] ] >= max1 ) { max2 = max1 ; max1 = height [ adj [ cur ] [ u ] ] ; } else if ( height [ adj [ cur ] [ u ] ] > max2 ) { max2 = height [ adj [ cur ] [ u ] ] ; } } } let sum = 0 ; for ( let u = 0 ; u < adj [ cur ] . length ; u ++ ) { if ( adj [ cur ] [ u ] != par ) { sum = ( ( max1 == height [ adj [ cur ] [ u ] ] ) ? max2 : max1 ) ; if ( max1 == height [ adj [ cur ] [ u ] ] ) dist [ adj [ cur ] [ u ] ] = 1 + Math . max ( 1 + max2 , dist [ cur ] ) ; else dist [ adj [ cur ] [ u ] ] = 1 + Math . max ( 1 + max1 , dist [ cur ] ) ; dfs2 ( adj [ cur ] [ u ] , cur ) ; } } } let n = 6 ; for ( let i = 0 ; i < adj . length ; i ++ ) adj [ i ] = [ ] ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 5 , 6 ) ; dfs1 ( 1 , 0 ) ; dfs2 ( 1 , 0 ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( ( Math . max ( dist [ i ] , height [ i ] ) - 1 ) + " " ) ;

Index/key variables: cur, i, u, v
Accumulator variables: i, u
Iterator variables: i, u
Javascript program:
function selectionSort ( arr , n ) { let i , j , min_idx ; for ( i = 0 ; i < n - 1 ; i ++ ) { min_idx = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] < arr [ min_idx ] ) min_idx = j ; let temp = arr [ min_idx ] ; arr [ min_idx ] = arr [ i ] ; arr [ i ] = temp ; } } function printArray ( arr , size ) { let i ; for ( i = 0 ; i < size ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let arr = [ 64 , 25 , 12 , 22 , 11 ] ; let n = arr . length ; selectionSort ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i, j, min_idx
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkStr1CanConStr2 ( str1 , str2 ) { var N = str1 . length ; var M = str2 . length ; var st1 = new Set ( ) ; var st2 = new Set ( ) ; var hash1 = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { hash1 [ str1 [ i ] . charCodeAt ( 0 ) ] ++ ; } for ( var i = 0 ; i < N ; i ++ ) { st1 . add ( str1 [ i ] ) ; } for ( var i = 0 ; i < M ; i ++ ) { st2 . add ( str2 [ i ] ) ; } if ( st1 . size != st2 . size ) { return false ; } var hash2 = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < M ; i ++ ) { hash2 [ str2 [ i ] . charCodeAt ( 0 ) ] ++ ; } hash1 . sort ( ( a , b ) => a - b ) ; hash2 . sort ( ( a , b ) => a - b ) ; for ( var i = 0 ; i < 256 ; i ++ ) { if ( hash1 [ i ] != hash2 [ i ] ) { return false ; } } return true ; } var str1 = " " ; var str2 = " " ; if ( checkStr1CanConStr2 ( str1 , str2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function swap ( arr , xp , yp ) { var temp = arr [ xp ] ; arr [ xp ] = arr [ yp ] ; arr [ yp ] = temp ; } function partSort ( arr , N , a , b ) { var l = Math . min ( a , b ) ; var r = Math . max ( a , b ) ; var i , j ; for ( i = l ; i < r + 1 + 1 ; i ++ ) { for ( j = l ; j < r - i + 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { swap ( arr , j , j + 1 ) ; } } } for ( i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; } var arr = [ 7 , 8 , 4 , 5 , 2 ] ; var a = 1 , b = 4 ; var N = arr . length ; partSort ( arr , N , a , b ) ;

Index/key variables: i, j, xp, yp
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let INF = Number . MAX_VALUE , N = 4 ; function minCost ( cost ) { let dist = new Array ( N ) ; dist . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) dist [ i ] = INF ; dist [ 0 ] = 0 ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = i + 1 ; j < N ; j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ; return dist [ N - 1 ] ; } let cost = [ [ 0 , 15 , 80 , 90 ] , [ INF , 0 , 40 , 50 ] , [ INF , INF , 0 , 70 ] , [ INF , INF , INF , 0 ] ] ; document . write ( " " + " " + N + " " + minCost ( cost ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function largest_alphabet ( a , n ) { let max = ' ' ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] . charCodeAt ( ) > max . charCodeAt ( ) ) max = a [ i ] ; return max ; } function smallest_alphabet ( a , n ) { let min = ' ' ; for ( let i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] . charCodeAt ( ) < min . charCodeAt ( ) ) min = a [ i ] ; return min ; } let a = " " ; let size = a . length ; document . write ( " " ) ; document . write ( largest_alphabet ( a , size ) + " " ) ; document . write ( smallest_alphabet ( a , size ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumPalinUsingKChanges ( str , k ) { let palin = str . split ( " " ) ; let ans = " " ; let l = 0 ; let r = str . length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { palin [ l ] = palin [ r ] = String . fromCharCode ( Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ) ; k -- ; } l ++ ; r -- ; } if ( k < 0 ) { return " " ; } l = 0 ; r = str . length - 1 ; while ( l <= r ) { if ( l == r ) { if ( k > 0 ) { palin [ l ] = ' ' ; } } if ( palin [ l ] < ' ' ) { if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) { k -= 2 ; palin [ l ] = palin [ r ] = ' ' ; } else if ( k >= 1 && ( palin [ l ] != str [ l ] palin [ r ] != str [ r ] ) ) { k -- ; palin [ l ] = palin [ r ] = ' ' ; } } l ++ ; r -- ; } for ( let i = 0 ; i < palin . length ; i ++ ) ans += palin [ i ] ; return ans ; } let str = " " ; let k = 3 ; document . write ( maximumPalinUsingKChanges ( str , k ) ) ;

Index/key variables: i, l, r
Accumulator variables: ans, i, k, l, r
Iterator variables: i
Javascript program:
var min = 10000 ; function parity ( even , odd , v , i ) { if ( i == v . length even . length == 0 && odd . length == 0 ) { var count = 0 ; for ( var j = 0 ; j < v . length - 1 ; j ++ ) { if ( v [ j ] % 2 != v [ j + 1 ] % 2 ) count ++ ; } if ( count < min ) min = count ; return min ; } if ( v [ i ] != - 1 ) min = parity ( even , odd , v , i + 1 ) ; else { if ( even . length != 0 ) { var x = even . back ( ) ; even . pop ( ) ; v [ i ] = x ; min = parity ( even , odd , v , i + 1 ) ; even . push ( x ) ; } if ( odd . length != 0 ) { var x = odd [ odd . length - 1 ] ; odd . pop ( ) ; v [ i ] = x ; min = parity ( even , odd , v , i + 1 ) ; odd . push ( x ) ; } } return min ; } function minDiffParity ( v , n ) { var even = [ ] ; var odd = [ ] ; var m = new Map ( ) ; for ( var i = 1 ; i <= n ; i ++ ) m . set ( i , 1 ) ; for ( var i = 0 ; i < v . length ; i ++ ) { if ( v [ i ] != - 1 ) m . delete ( v [ i ] ) ; } m . forEach ( ( value , key ) => { if ( i . first % 2 == 0 ) even . push ( key ) ; else odd . push ( key ) ; } ) ; min = parity ( even , odd , v , 0 ) ; document . write ( min ) ; } var n = 8 ; var v = [ 2 , 1 , 4 , - 1 , - 1 , 6 , - 1 , 8 ] ; minDiffParity ( v , n ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let MAX = 100005 ; let adjacent = [ ] ; let visited = new Array ( MAX ) ; let startnode , endnode , thirdnode ; let maxi = - 1 , N ; let parent = new Array ( MAX ) ; let vis = new Array ( MAX ) ; function dfs ( u , count ) { visited [ u ] = true ; let temp = 0 ; for ( let i = 0 ; i < adjacent [ u ] . length ; i ++ ) { if ( ! visited [ adjacent [ u ] [ i ] ] ) { temp ++ ; dfs ( adjacent [ u ] [ i ] , count + 1 ) ; } } if ( temp == 0 ) { if ( maxi < count ) { maxi = count ; startnode = u ; } } } function dfs1 ( u , count ) { visited [ u ] = true ; let temp = 0 ; for ( let i = 0 ; i < adjacent [ u ] . length ; i ++ ) { if ( ! visited [ adjacent [ u ] [ i ] ] ) { temp ++ ; parent [ adjacent [ u ] [ i ] ] = u ; dfs1 ( adjacent [ u ] [ i ] , count + 1 ) ; } } if ( temp == 0 ) { if ( maxi < count ) { maxi = count ; endnode = u ; } } } function dfs2 ( u , count ) { visited [ u ] = true ; let temp = 0 ; for ( let i = 0 ; i < adjacent [ u ] . length ; i ++ ) { if ( ! visited [ adjacent [ u ] [ i ] ] && ! vis [ adjacent [ u ] [ i ] ] ) { temp ++ ; dfs2 ( adjacent [ u ] [ i ] , count + 1 ) ; } } if ( temp == 0 ) { if ( maxi < count ) { maxi = count ; thirdnode = u ; } } } function findNodes ( ) { dfs ( 1 , 0 ) ; for ( let i = 0 ; i <= N ; i ++ ) visited [ i ] = false ; maxi = - 1 ; dfs1 ( startnode , 0 ) ; for ( let i = 0 ; i <= N ; i ++ ) visited [ i ] = false ; let x = endnode ; vis [ startnode ] = true ; while ( x != startnode ) { vis [ x ] = true ; x = parent [ x ] ; } maxi = - 1 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( vis [ i ] ) dfs2 ( i , 0 ) ; } } for ( let i = 0 ; i < MAX ; i ++ ) adjacent . push ( [ ] ) ; N = 4 ; adjacent [ 1 ] . push ( 2 ) ; adjacent [ 2 ] . push ( 1 ) ; adjacent [ 1 ] . push ( 3 ) ; adjacent [ 3 ] . push ( 1 ) ; adjacent [ 1 ] . push ( 4 ) ; adjacent [ 4 ] . push ( 1 ) ; findNodes ( ) ; document . write ( " " + startnode + " " + endnode + " " + thirdnode + " " ) ;

Index/key variables: i, startnode, u, x
Accumulator variables: i, temp
Iterator variables: i
Javascript program:
function maxvolume ( s ) { let maxvalue = 0 ; for ( let i = 1 ; i <= s - 2 ; i ++ ) { for ( let j = 1 ; j <= s - 1 ; j ++ ) { let k = s - i - j ; maxvalue = Math . max ( maxvalue , i * j * k ) ; } } return maxvalue ; } let s = 8 ; document . write ( maxvolume ( s ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxvolume ( s ) { let length = parseInt ( s / 3 ) ; s -= length ; let breadth = parseInt ( s / 2 ) ; let height = s - breadth ; return length * breadth * height ; } let s = 8 ; document . write ( maxvolume ( s ) ) ;

Accumulator variables: s
Javascript program:
function performQuery ( arr , Q ) { for ( let i = 0 ; i < Q . length ; i ++ ) { let or = 0 ; let x = Q [ i ] [ 0 ] ; arr [ x - 1 ] = Q [ i ] [ 1 ] ; for ( let j = 0 ; j < arr . length ; j ++ ) { or = or | arr [ j ] ; } document . write ( or + " " ) ; } } let arr = [ 1 , 2 , 3 ] ; let Q = [ [ 1 , 4 ] , [ 3 , 0 ] ] ; performQuery ( arr , Q ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function smallest ( k , d ) { let cnt = 1 ; let m = d % k ; let v = new Array ( k ) . fill ( 0 ) ; v [ m ] = 1 ; while ( 1 ) { if ( m == 0 ) return cnt ; m = ( ( ( m * ( 10 % k ) ) % k ) + ( d % k ) ) % k ; if ( v [ m ] == 1 ) return - 1 ; v [ m ] = 1 ; cnt ++ ; } return - 1 ; } let d = 1 ; let k = 41 ; document . write ( smallest ( k , d ) ) ;

Index/key variables: m
Accumulator variables: cnt
Javascript program:
function checkCommonDivisor ( arr , N , X ) { var G = 0 ; for ( i = 0 ; i < N ; i ++ ) { G = gcd ( G , arr [ i ] ) ; } var copy_G = G ; for ( divisor = 2 ; divisor <= X ; divisor ++ ) { while ( G % divisor == 0 ) { G = G / divisor ; } } if ( G <= X ) { document . write ( " " ) ; for ( i = 0 ; i < N ; i ++ ) document . write ( ( arr [ i ] / copy_G ) + " " ) ; document . write ( ) ; } else document . write ( " " ) ; } function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } var arr = [ 6 , 15 , 6 ] ; var X = 6 ; var N = arr . length ; checkCommonDivisor ( arr , N , X ) ;

Index/key variables: i
Accumulator variables: divisor, i
Iterator variables: divisor, i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . prev = null ; this . next = null ; } } function reverse ( head_ref ) { var temp = null ; var current = head_ref ; while ( current != null ) { temp = current . prev ; current . prev = current . next ; current . next = temp ; current = current . prev ; } if ( temp != null ) head_ref = temp . prev ; return head_ref ; } function merge ( first , second ) { if ( first == null ) return second ; if ( second == null ) return first ; if ( first . data < second . data ) { first . next = merge ( first . next , second ) ; first . next . prev = first ; first . prev = null ; return first ; } else { second . next = merge ( first , second . next ) ; second . next . prev = second ; second . prev = null ; return second ; } } function sort ( head ) { if ( head == null head . next == null ) return head ; var current = head . next ; while ( current != null ) { if ( current . data < current . prev . data ) break ; current = current . next ; } if ( current == null ) return head ; current . prev . next = null ; current . prev = null ; current = reverse ( current ) ; return merge ( head , current ) ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } function printList ( head ) { if ( head == null ) document . write ( " " ) ; while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = null ; head = push ( head , 1 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 10 ) ; head = push ( head , 12 ) ; head = push ( head , 7 ) ; head = push ( head , 5 ) ; head = push ( head , 2 ) ; document . write ( " " ) ; printList ( head ) ; head = sort ( head ) ; document . write ( " " ) ; printList ( head ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( key ) { this . data = key ; this . next = null ; } } function printlist ( head ) { if ( head == null ) { document . write ( " " ) ; return ; } while ( head != null ) { document . write ( head . data + " " ) ; if ( head . next != null ) document . write ( " " ) ; head = head . next ; } document . write ( " " ) ; } function isVowel ( x ) { return ( x == ' ' x == ' ' x == ' ' x == ' ' x == ' ' ) ; } function arrange ( head ) { let newHead = head ; let latestVowel ; let curr = head ; if ( head == null ) return null ; if ( isVowel ( head . data ) == true ) latestVowel = head ; else { while ( curr . next != null && ! isVowel ( curr . next . data ) ) curr = curr . next ; if ( curr . next == null ) return head ; latestVowel = newHead = curr . next ; curr . next = curr . next . next ; latestVowel . next = head ; } while ( curr != null && curr . next != null ) { if ( isVowel ( curr . next . data ) == true ) { if ( curr == latestVowel ) { latestVowel = curr = curr . next ; } else { let temp = latestVowel . next ; latestVowel . next = curr . next ; latestVowel = latestVowel . next ; curr . next = curr . next . next ; latestVowel . next = temp ; } } else { curr = curr . next ; } } return newHead ; } let head = new Node ( ' ' ) ; head . next = new Node ( ' ' ) ; head . next . next = new Node ( ' ' ) ; head . next . next . next = new Node ( ' ' ) ; head . next . next . next . next = new Node ( ' ' ) ; head . next . next . next . next . next = new Node ( ' ' ) ; head . next . next . next . next . next . next = new Node ( ' ' ) ; head . next . next . next . next . next . next . next = new Node ( ' ' ) ; document . write ( " " ) ; printlist ( head ) ; head = arrange ( head ) ; document . write ( " " ) ; printlist ( head ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . left = null ; this . right = null ; } } function newNode ( data ) { var temp = new Node ( ) ; temp . data = data ; temp . right = null ; temp . left = null ; return temp ; } function KthLargestUsingMorrisTraversal ( root , k ) { var curr = root ; var Klargest = null ; var count = 0 ; while ( curr != null ) { if ( curr . right == null ) { if ( ++ count == k ) Klargest = curr ; curr = curr . left ; } else { var succ = curr . right ; while ( succ . left != null && succ . left != curr ) succ = succ . left ; if ( succ . left == null ) { succ . left = curr ; curr = curr . right ; } else { succ . left = null ; if ( ++ count == k ) Klargest = curr ; curr = curr . left ; } } } return Klargest ; } root = newNode ( 4 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 7 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 10 ) ; document . write ( " " + KthLargestUsingMorrisTraversal ( root , 2 ) . data ) ;

Class/struct names: Node