dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isPossiblePalindrome ( str ) { let n = str . length ; for ( let i = 0 ; i < Math . floor ( n / 2 ) ; i ++ ) { if ( str [ i ] != ' ' && str [ n - i - 1 ] != ' ' && str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } function smallestPalindrome ( str ) { if ( ! isPossiblePalindrome ( str ) ) document . write ( " " ) ; let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) { if ( str [ n - i - 1 ] != ' ' ) str [ i ] = str [ n - i - 1 ] ; else str [ i ] = str [ n - i - 1 ] = ' ' ; } } for ( let i = 0 ; i < n ; i ++ ) document . write ( str [ i ] + " " ) ; } let str = " " ; let s = str . split ( " " ) ; smallestPalindrome ( s ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function flip ( ch ) { return ( ch == ' ' ) ? ' ' : ' ' ; } function getFlipWithStartingCharcter ( str , expected ) { let flipCount = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str . charAt ( i ) != expected ) flipCount ++ ; expected = flip ( expected ) ; } return flipCount ; } function minFlipToMakeStringAlternate ( str ) { return Math . min ( getFlipWithStartingCharcter ( str , ' ' ) , getFlipWithStartingCharcter ( str , ' ' ) ) ; } let str = " " ; document . write ( minFlipToMakeStringAlternate ( str ) ) ;

Accumulator variables: flipCount, i
Iterator variables: i
Javascript program:
function remainderWith7 ( num ) { series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ] var series_index = 0 ; for ( var i = num . length - 1 ; i >= 0 ; i -- ) { var digit = num [ i ] - ' ' ; result += digit * series [ series_index ] ; series_index = ( series_index + 1 ) % 6 ; result %= 7 ; } if ( result < 0 ) result = ( result + 7 ) % 7 ; return result ; } var str = " " ; document . write ( " " + remainderWith7 ( str ) ) ;

Index/key variables: i, series_index
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function isReversible ( str ) { var i = 0 , j = str . length - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } var str = " " ; if ( isReversible ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
let CHAR_SIZE = 256 ; function checkPattern ( str , pat ) { let label = new Array ( CHAR_SIZE ) ; for ( let i = 0 ; i < CHAR_SIZE ; i ++ ) label [ i ] = - 1 ; let order = 1 ; for ( let i = 0 ; i < pat . length ; i ++ ) { label [ pat [ i ] . charCodeAt ( 0 ) ] = order ; order ++ ; } let last_order = - 1 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( label [ str [ i ] . charCodeAt ( 0 ) ] != - 1 ) { if ( label [ str [ i ] . charCodeAt ( 0 ) ] < last_order ) return false ; last_order = label [ str [ i ] . charCodeAt ( 0 ) ] ; } } return true ; } let str = " " ; let pattern = " " ; document . write ( checkPattern ( str , pattern ) ) ;

Index/key variables: i
Accumulator variables: i, order
Iterator variables: i
Javascript program:
function followsPattern ( str , pattern ) { let patternSet = new Set ( ) ; for ( let i = 0 ; i < pattern . length ; i ++ ) patternSet . add ( pattern [ i ] ) ; let modifiedString = ( str ) . split ( " " ) ; for ( let i = str . length - 1 ; i >= 0 ; i -- ) if ( ! patternSet . has ( modifiedString [ i ] ) ) modifiedString . splice ( i , 1 ) ; for ( let i = modifiedString . length - 1 ; i > 0 ; i -- ) if ( modifiedString [ i ] == modifiedString [ i - 1 ] ) modifiedString . splice ( i , 1 ) ; if ( pattern . length != modifiedString . length ) return false ; for ( let i = 0 ; i < pattern . length ; i ++ ) if ( pattern [ i ] != modifiedString [ i ] ) return false ; return true ; } let str = " " ; let pattern = " " ; document . write ( " " + followsPattern ( str , pattern ) + " " ) ; str = " " ; pattern = " " ; document . write ( " " + followsPattern ( str , pattern ) + " " ) ; str = " " ; pattern = " " ; document . write ( " " + followsPattern ( str , pattern ) + " " ) ; str = " " ; pattern = " " ; document . write ( " " + followsPattern ( str , pattern ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function encodedChar ( str , k ) { let expand = " " ; for ( let i = 0 ; i < str . length ; ) { while ( i < str . length && str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { temp += str [ i ] ; i ++ ; } while ( i < str . length && str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { freq = freq * 10 + str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; i ++ ; } for ( let j = 1 ; j <= freq ; j ++ ) expand += temp ; } if ( freq == 0 ) expand += temp ; return expand [ k - 1 ] ; } let str = " " ; let k = 21 ; document . write ( encodedChar ( str , k ) ) ;

Index/key variables: i
Accumulator variables: expand, i, j, temp
Iterator variables: i, j
Javascript program:
function to_upper ( In ) { let n = In . length ; for ( let i = 0 ; i < In . length ; i ++ ) if ( ' ' <= In [ i ] && In [ i ] <= ' ' ) In [ i ] = String . fromCharCode ( In [ i ] . charCodeAt ( 0 ) & ( ~ ( 1 << 5 ) ) ) ; return ( In ) . join ( " " ) ; } let str = " " ; document . write ( to_upper ( str . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function commonPrefixUtil ( str1 , str2 ) { let result = " " ; let n1 = str1 . length , n2 = str2 . length ; for ( let i = 0 , j = 0 ; i <= n1 - 1 && j <= n2 - 1 ; i ++ , j ++ ) { if ( str1 [ i ] != str2 [ j ] ) { break ; } result += str1 [ i ] ; } return ( result ) ; } function commonPrefix ( arr , low , high ) { if ( low == high ) { return ( arr [ low ] ) ; } if ( high > low ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; let str1 = commonPrefix ( arr , low , mid ) ; let str2 = commonPrefix ( arr , mid + 1 , high ) ; return ( commonPrefixUtil ( str1 , str2 ) ) ; } return null ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; let ans = commonPrefix ( arr , 0 , n - 1 ) ; if ( ans . length != 0 ) { document . write ( " " + ans ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j, low
Accumulator variables: i, j, result
Iterator variables: i
Javascript program:
function commonPrefixUtil ( str1 , str2 ) { let result = " " ; let n1 = str1 . length , n2 = str2 . length ; for ( let i = 0 , j = 0 ; i <= n1 - 1 && j <= n2 - 1 ; i ++ , j ++ ) { if ( str1 [ i ] != str2 [ j ] ) { break ; } result += str1 [ i ] ; } return ( result ) ; } function commonPrefix ( arr , n ) { let prefix = arr [ 0 ] ; for ( let i = 1 ; i <= n - 1 ; i ++ ) { prefix = commonPrefixUtil ( prefix , arr [ i ] ) ; } return ( prefix ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; let ans = commonPrefix ( arr , n ) ; if ( ans . length > 0 ) { document . write ( " " , ans ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i
Javascript program:
function flip ( c ) { return ( c == ' ' ) ? ' ' : ' ' ; } function printOneAndTwosComplement ( bin ) { var n = bin . length ; var i ; var ones , twos ; ones = twos = " " ; for ( i = 0 ; i < n ; i ++ ) ones += flip ( bin [ i ] ) ; twos = ones ; twos = twos . split ( ' ' ) for ( i = n - 1 ; i >= 0 ; i -- ) { if ( ones [ i ] == ' ' ) twos [ i ] = ' ' ; else { twos [ i ] = ' ' ; break ; } } twos = twos . join ( ' ' ) if ( i == - 1 ) twos = ' ' + twos ; document . write ( " " + ones + " " ) ; document . write ( " " + twos + " " ) ; } var bin = " " ; printOneAndTwosComplement ( bin ) ;

Index/key variables: i
Accumulator variables: i, ones
Iterator variables: i
Javascript program:
function zigZagConcat ( s , n ) { if ( n <= 1 ) { return s ; } let result = [ ] ; for ( let rowNum = 0 ; rowNum < n ; rowNum ++ ) { let i = rowNum ; let up = true ; while ( i < s . length ) { result . push ( s [ i ] ) ; if ( rowNum == 0 rowNum == n - 1 ) { i += ( 2 * n - 2 ) ; } else { if ( up ) { i += ( 2 * ( n - rowNum ) - 2 ) ; } else { i += rowNum * 2 ; } up ^= true ; } } } return result . join ( " " ) ; } let str = " " ; let n = 3 ; document . write ( zigZagConcat ( str , n ) ) ;

Index/key variables: i
Accumulator variables: i, rowNum, up
Iterator variables: rowNum
Boolean variables: up
Javascript program:
function pattern ( str , len ) { for ( var i = 0 ; i < len ; i ++ ) { var j = len - 1 - i ; for ( var k = 0 ; k < len ; k ++ ) { if ( k == i k == j ) document . write ( str . charAt ( k ) ) ; else document . write ( " " ) ; } document . write ( ' ' ) ; } } var str = " " ; var len = str . length ; pattern ( str , len ) ;

Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
let NO_OF_CHARS = 256 ; function canFormPalindrome ( str ) { let count = Array ( NO_OF_CHARS ) . fill ( 0 ) ; for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] . charCodeAt ( ) ] ++ ; let odd = 0 ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( ( count [ i ] & 1 ) == 1 ) odd ++ ; if ( odd > 1 ) return false ; } return true ; } if ( canFormPalindrome ( " " ) ) document . write ( " " ) ; else document . write ( " " ) ; if ( canFormPalindrome ( " " ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Javascript program:
function generateGray ( n ) { if ( n <= 0 ) { let temp = [ " " ] ; return temp ; } if ( n == 1 ) { let temp = [ " " , " " ] ; return temp ; } let recAns = generateGray ( n - 1 ) ; let mainAns = [ ] ; for ( let i = 0 ; i < recAns . length ; i ++ ) { let s = recAns [ i ] ; mainAns . push ( " " + s ) ; } for ( let i = recAns . length - 1 ; i >= 0 ; i -- ) { let s = recAns [ i ] ; mainAns . push ( " " + s ) ; } return mainAns ; } function generateGrayarr ( n ) { let arr = [ ] ; arr = generateGray ( n ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } generateGrayarr ( 3 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let NO_OF_CHARS = 256 ; function areAnagram ( str1 , str2 ) { let count1 = new Array ( NO_OF_CHARS ) ; let count2 = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { count1 [ i ] = 0 ; count2 [ i ] = 0 ; } let i ; for ( i = 0 ; i < str1 . length && i < str2 . length ; i ++ ) { count1 [ str1 [ i ] . charCodeAt ( 0 ) ] ++ ; count2 [ str1 [ i ] . charCodeAt ( 0 ) ] ++ ; } if ( str1 . length != str2 . length ) return false ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ; return true ; } let str1 = ( " " ) . split ( " " ) ; let str2 = ( " " ) . split ( " " ) ; if ( areAnagram ( str1 , str2 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var no_of_chars = 256 ; function findSubString ( str , pat ) { var len1 = str . length ; var len2 = pat . length ; if ( len1 < len2 ) { document . write ( " " ) ; return " " ; } var hash_pat = Array . from ( { length : no_of_chars } , ( _ , i ) => 0 ) ; var hash_str = Array . from ( { length : no_of_chars } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < len2 ; i ++ ) hash_pat [ pat . charAt ( i ) . charCodeAt ( 0 ) ] ++ ; var start = 0 , start_index = - 1 , min_len = Number . MAX_VALUE ; var count = 0 ; for ( var j = 0 ; j < len1 ; j ++ ) { hash_str [ str . charAt ( j ) . charCodeAt ( 0 ) ] ++ ; if ( hash_str [ str . charAt ( j ) . charCodeAt ( 0 ) ] <= hash_pat [ str . charAt ( j ) . charCodeAt ( 0 ) ] ) count ++ ; if ( count == len2 ) { while ( hash_str [ str . charAt ( start ) . charCodeAt ( 0 ) ] > hash_pat [ str . charAt ( start ) . charCodeAt ( 0 ) ] || hash_pat [ str . charAt ( start ) . charCodeAt ( 0 ) ] == 0 ) { if ( hash_str [ str . charAt ( start ) . charCodeAt ( 0 ) ] > hash_pat [ str . charAt ( start ) . charCodeAt ( 0 ) ] ) hash_str [ str . charAt ( start ) . charCodeAt ( 0 ) ] -- ; start ++ ; } var len_window = j - start + 1 ; if ( min_len > len_window ) { min_len = len_window ; start_index = start ; } } } if ( start_index == - 1 ) { document . write ( " " ) ; return " " ; } return str . substring ( start_index , start_index + min_len ) ; } var str = " " ; var pat = " " ; document . write ( " " + findSubString ( str , pat ) ) ;

Accumulator variables: count, i, j, start
Iterator variables: i, j
Javascript program:
function removeDuplicate ( str , n ) { var index = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var j ; for ( j = 0 ; j < i ; j ++ ) { if ( str [ i ] == str [ j ] ) { break ; } } if ( j == i ) { str [ index ++ ] = str [ i ] ; } } return str . join ( " " ) . slice ( str , index ) ; } var str = " " . split ( " " ) ; var n = str . length ; document . write ( removeDuplicate ( str , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, index, j
Iterator variables: i, j
Javascript program:
let DirX = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ] ; let DirY = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ] ; function isSafe ( i , j , n , Board ) { return i >= 0 && j >= 0 && i < n && j < n && Board [ i ] [ j ] == 0 ; } let isPossible = false ; function knightTour ( ChessBoard , N , x , y , visited = 1 ) { ChessBoard [ x ] [ y ] = visited ; if ( visited == N * N ) { isPossible = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( ChessBoard [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } document . write ( " " ) ; ChessBoard [ x ] [ y ] = 0 ; return ; } for ( let i = 0 ; i < 8 ; i ++ ) { let newX = x + DirX [ i ] ; let newY = y + DirY [ i ] ; if ( isSafe ( newX , newY , N , ChessBoard ) && ! ChessBoard [ newX ] [ newY ] ) { knightTour ( ChessBoard , N , newX , newY , visited + 1 ) ; } } ChessBoard [ x ] [ y ] = 0 ; } let ChessBoard = new Array ( 5 ) . fill ( 0 ) . map ( ( ) => new Array ( 5 ) . fill ( 0 ) ) ; let N = ChessBoard . length ; let X = 1 ; let Y = 1 ; knightTour ( ChessBoard , N , X - 1 , Y - 1 ) ; if ( ! isPossible ) { document . write ( " " ) ; }

Index/key variables: i, j, newX, newY, x, y
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: isPossible
Javascript program:
function getans ( i , v , q ) { if ( i == q . length ) return true ; for ( let j = 0 ; j < v . length ; j ++ ) { if ( v [ j ] >= q [ i ] ) { v [ j ] -= q [ i ] ; if ( getans ( i + 1 , v , q ) ) { return true ; } v [ j ] += q [ i ] ; } } return false ; } function Check ( c , b ) { let m = new Map ( ) ; for ( let i = 0 ; i < b . length ; i ++ ) { if ( m . has ( b [ i ] ) ) { m . set ( b [ i ] , m . get ( b [ i ] ) + 1 ) ; } else { m . set ( b [ i ] , 1 ) ; } } let v = [ ] ; for ( i of m ) { v . push ( i [ 1 ] ) ; } let check = getans ( 0 , v , c ) ; if ( check ) document . write ( " " ) ; else document . write ( " " ) ; } let c = [ 1 , 3 , 3 ] ; let b = [ 2 , 2 , 2 , 2 , 4 , 4 , 4 ] ; Check ( c , b ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumXOR ( arr , n , K ) { K ++ ; let maxXor = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { if ( ( i ) . toString ( 2 ) . split ( ' ' ) . filter ( x => x == ' ' ) . length == K ) { let cur_xor = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) cur_xor = cur_xor ^ arr [ j ] ; } maxXor = Math . max ( maxXor , cur_xor ) ; } } return maxXor ; } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; let M = 2 ; document . write ( maximumXOR ( arr , N , M ) ) ;

Index/key variables: j
Accumulator variables: K, i, j
Iterator variables: i, j
Javascript program:
function TowerOfHanoi ( N ) { for ( let x = 1 ; x <= Math . pow ( 2 , N ) - 1 ; x ++ ) { document . write ( " " + ( ( x & x - 1 ) % 3 + 1 ) + " " + ( ( ( x x - 1 ) + 1 ) % 3 + 1 ) + " " ) ; } } let N = 3 ; TowerOfHanoi ( N ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function isValid ( board , i , j , K ) { if ( board [ i ] [ j ] <= K ) { return true ; } return false ; } function findPath ( board , X , Y , M , N , K ) { if ( X < 0 X == M Y < 0 Y == N ) { return true ; } if ( isValid ( board , X , Y , K ) ) { let board_XY = board [ X ] [ Y ] ; board [ X ] [ Y ] = Number . MAX_VALUE ; if ( findPath ( board , X + 1 , Y , M , N , K - board_XY ) || findPath ( board , X - 1 , Y , M , N , K - board_XY ) || findPath ( board , X , Y + 1 , M , N , K - board_XY ) || findPath ( board , X , Y - 1 , M , N , K - board_XY ) ) { return true ; } board [ X ] [ Y ] = board_XY ; } return false ; } let grid = [ [ 25 , 5 , 25 , 25 , 25 , 25 ] , [ 25 , 1 , 1 , 5 , 12 , 25 ] , [ 25 , 1 , 12 , 0 , 15 , 25 ] , [ 22 , 1 , 11 , 2 , 19 , 15 ] , [ 25 , 2 , 2 , 1 , 12 , 15 ] , [ 25 , 9 , 10 , 1 , 11 , 25 ] , [ 25 , 25 , 25 , 25 , 25 , 25 ] ] ; let K = 17 ; let M = grid . length ; let N = grid [ 0 ] . length ; let X = 2 , Y = 3 ; if ( findPath ( grid , X , Y , M , N , K ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: X, Y, i, j
Javascript program:
function isPerfect ( x ) { var sum_div = 1 ; for ( var i = 2 ; i <= parseInt ( x / 2 ) ; ++ i ) { if ( x % i == 0 ) { sum_div += i ; } } if ( sum_div == x ) { return 1 ; } else return 0 ; } function subsetSum ( arr , n ) { var total = 1 << n ; for ( i = 0 ; i < total ; i ++ ) { var sum = 0 ; for ( j = 0 ; j < n ; j ++ ) if ( ( i & ( 1 << j ) ) != 0 ) sum += arr [ j ] ; if ( isPerfect ( sum ) != 0 ) { document . write ( sum + " " ) ; } } } var arr = [ 5 , 4 , 6 ] ; var N = arr . length ; subsetSum ( arr , N ) ;

Index/key variables: j
Accumulator variables: i, j, sum, sum_div
Iterator variables: i, j
Javascript program:
function solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) { if ( N == 0 || ( QuitP1 && QuitP2 ) ) { document . write ( " " + " " + N + " " ) ; document . write ( " " + " " + P1 + " " ) ; document . write ( " " + " " + P2 + " " ) ; return ; } if ( Move == 0 && QuitP1 == false ) { let req_P1 = ( Math . pow ( 2 , X ) ) ; if ( req_P1 <= N ) { P1 += req_P1 ; N -= req_P1 ; } else { QuitP1 = true ; } } else if ( Move == 1 && QuitP2 == false ) { let req_P2 = ( Math . pow ( 3 , X ) ) ; if ( req_P2 <= N ) { P2 += req_P2 ; N -= req_P2 ; } else { QuitP2 = true ; } } X ++ ; Move = ( ( Move == 1 ) ? 0 : 1 ) ; solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) ; } function PenGame ( N ) { let P1 = 0 ; let P2 = 0 ; let X = 0 ; let Move = 0 ; let QuitP1 = false ; let QuitP2 = false ; solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) ; } let N = 22 ; PenGame ( N ) ;

Accumulator variables: N, P1, P2, X
Boolean variables: QuitP1, QuitP2
Javascript program:
function checkUntil ( num , K , N , ans ) { if ( N == 1 ) { ans . push ( num ) ; return ; } if ( ( num % 10 + K ) <= 9 ) checkUntil ( 10 * num + ( num % 10 + K ) , K , N - 1 , ans ) ; if ( K > 0 ) { if ( ( num % 10 - K ) >= 0 ) checkUntil ( 10 * num + num % 10 - K , K , N - 1 , ans ) ; } } function check ( K , N , ans ) { for ( let i = 1 ; i <= 9 ; i ++ ) { checkUntil ( i , K , N , ans ) ; } } function print ( ans ) { for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let N = 4 , K = 8 ; let ans = [ ] check ( K , N , ans ) ; print ( ans ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( f , s ) { this . first = f ; this . second = s ; } } var minSum = 100000000 ; function getMinPathSum ( graph , visited , necessary , src , dest , currSum ) { if ( src == dest ) { var flag = true ; for ( var i of necessary ) { if ( ! visited [ i ] ) { flag = false ; break ; } } if ( flag ) minSum = Math . min ( minSum , currSum ) ; return ; } else { visited [ src ] = true ; for ( var node of graph [ src ] ) { if ( ! visited [ node . first ] ) { visited [ node . first ] = true ; getMinPathSum ( graph , visited , necessary , node . first , dest , currSum + node . second ) ; visited [ node . first ] = false ; } } visited [ src ] = false ; } } var graph = Array . from ( Array ( 7 ) , ( ) => Array ( ) ) ; graph [ 0 ] . push ( new pair ( 1 , 2 ) ) ; graph [ 0 ] . push ( new pair ( 2 , 3 ) ) ; graph [ 0 ] . push ( new pair ( 3 , 2 ) ) ; graph [ 1 ] . push ( new pair ( 4 , 4 ) ) ; graph [ 1 ] . push ( new pair ( 0 , 1 ) ) ; graph [ 2 ] . push ( new pair ( 4 , 5 ) ) ; graph [ 2 ] . push ( new pair ( 5 , 6 ) ) ; graph [ 3 ] . push ( new pair ( 5 , 7 ) ) ; graph [ 3 ] . push ( new pair ( 0 , 1 ) ) ; graph [ 4 ] . push ( new pair ( 6 , 4 ) ) ; graph [ 5 ] . push ( new pair ( 4 , 2 ) ) ; graph [ 6 ] . push ( new pair ( 7 , 11 ) ) ; var n = 7 ; var source = 0 ; var dest = 6 ; var visited = Array ( n ) . fill ( false ) ; var necessary = [ ] ; necessary . push ( 2 ) ; necessary . push ( 4 ) ; getMinPathSum ( graph , visited , necessary , source , dest , 0 ) ; if ( minSum == 100000000 ) document . write ( - 1 ) ; else document . write ( minSum ) ;

Index/key variables: i, src
Iterator variables: i, node
Boolean variables: flag
Class/struct names: pair
Javascript program:
function comb ( arr , len , r , ipos , op , opos , sum ) { if ( opos == r ) { let sum2 = 0 ; for ( let i = 0 ; i < opos ; i ++ ) { sum2 = sum2 + op [ i ] ; } if ( sum == sum2 ) { for ( let i = 0 ; i < opos ; i ++ ) document . write ( op [ i ] + " " ) ; document . write ( ) ; } return ; } if ( ipos < len ) { comb ( arr , len , r , ipos + 1 , op , opos , sum ) ; op [ opos ] = arr [ ipos ] ; comb ( arr , len , r , ipos + 1 , op , opos + 1 , sum ) ; } } let arr = [ 4 , 6 , 8 , 2 , 12 ] ; let K = 3 ; let S = 20 ; let N = arr . length ; let op = Array . from ( { length : N } , ( _ , i ) => 0 ) ; comb ( arr , N , K , 0 , op , 0 , S ) ;

Index/key variables: i, ipos, opos
Accumulator variables: i
Iterator variables: i
Javascript program:
let k1 = 0 , k2 = 0 ; let flag = true ; function traverseMatrixDiagonally ( m , i , j , row , col ) { if ( i >= row j >= col ) { if ( flag ) { let a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; k1 ++ ; } else { let a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; } document . write ( " " ) ; return false ; } document . write ( m [ i ] [ j ] + " " ) ; if ( traverseMatrixDiagonally ( m , i + 1 , j + 1 , row , col ) ) { return true ; } if ( traverseMatrixDiagonally ( m , k1 , k2 , row , col ) ) { return true ; } return true ; } let mtrx = [ [ 10 , 11 , 12 , 13 , 14 ] , [ 15 , 16 , 17 , 18 , 19 ] , [ 20 , 21 , 22 , 23 , 24 ] , [ 25 , 26 , 27 , 28 , 29 ] , [ 30 , 31 , 32 , 33 , 34 ] ] ; traverseMatrixDiagonally ( mtrx , 0 , 0 , 5 , 5 ) ;

Index/key variables: i, j
Accumulator variables: k1
Boolean variables: flag
Javascript program:
const n = 5 , m = 7 ; let g = new Array ( ) ; for ( let i = 0 ; i < m ; i ++ ) { g . push ( [ ] ) } let col = new Array ( n ) . fill ( 0 ) ; let cyc ; let res = new Array ( m ) ; function dfs ( v ) { col [ v ] = 1 ; for ( let p of g [ v ] ) { let to = p [ 0 ] let id = p [ 1 ] ; if ( col [ to ] == 0 ) { dfs ( to ) ; res [ id ] = 1 ; } else if ( col [ to ] == 2 ) { res [ id ] = 1 ; } else { res [ id ] = 2 ; cyc = true ; } } col [ v ] = 2 ; } g [ 0 ] . push ( [ 1 , 0 ] ) ; g [ 0 ] . push ( [ 2 , 1 ] ) ; g [ 1 ] . push ( [ 2 , 2 ] ) ; g [ 1 ] . push ( [ 3 , 3 ] ) ; g [ 2 ] . push ( [ 3 , 4 ] ) ; g [ 3 ] . push ( [ 4 , 5 ] ) ; g [ 4 ] . push ( [ 2 , 6 ] ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( col [ i ] == 0 ) { dfs ( i ) ; } } document . write ( ( cyc ? 2 : 1 ) + " " ) ; for ( let i = 0 ; i < m ; ++ i ) { document . write ( res [ i ] + ' ' ) ; }

Index/key variables: i, id, to, v
Accumulator variables: i
Iterator variables: i, p
Boolean variables: cyc
Javascript program:
function sumSubsets ( set , n , target ) { let x = new Array ( set . length ) ; let j = set . length - 1 ; while ( n > 0 ) { x [ j ] = n % 2 ; n = Math . floor ( n / 2 ) ; j -- ; } let sum = 0 ; for ( let i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) sum = sum + set [ i ] ; if ( sum == target ) { document . write ( " " ) ; for ( let i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) document . write ( set [ i ] + " " ) ; document . write ( " " ) ; } } function findSubsets ( arr , K ) { let x = Math . pow ( 2 , arr . length ) ; for ( let i = 1 ; i < x ; i ++ ) sumSubsets ( arr , i , K ) ; } let arr = [ 5 , 10 , 12 , 13 , 15 , 18 ] ; let K = 30 ; findSubsets ( arr , K ) ;

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