codeparrot/xlcost-text-to-code huggingface dataset:
Check if any permutation of string is a K times repeated string | Function to check that permutation of the given string is a K times repeating String ; if length of string is not divisible by K ; Frequency Array ; Initially frequency of each character is 0 ; Computing the frequency of each character in the string ; Loop to check that frequency of every character of the string is divisible by K ; Driver Code
function repeatingString ( s , n , k ) { if ( n % k != 0 ) { return false ; } var frequency = new Array ( 123 ) ; for ( let i = 0 ; i < 123 ; i ++ ) { frequency [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { frequency [ s [ i ] ] ++ ; } var repeat = n / k ; for ( let i = 0 ; i < 123 ; i ++ ) { if ( frequency [ i ] % repeat != 0 ) { return false ; } } return true ; } var s = " " ; var n = s . length ; var k = 3 ; if ( repeatingString ( s , n , k ) ) { console . log ( " " ) ; } else { console . log ( " " ) ; }
Find the last two missing digits of the given phone number | Function to find the last two digits of the number and print the complete number ; Sum of the first eight digits of the number ; if sum < 10 , then the two digits are '0' and the value of sum ; if sum > 10 , then the two digits are the value of sum ; Driver code
function findPhoneNumber ( n ) { let temp = n ; let sum = 0 ; while ( temp != 0 ) { sum += temp % 10 ; temp = Math . floor ( temp / 10 ) ; } if ( sum < 10 ) document . write ( n + " " + sum ) ; else document . write ( n + " " + sum ) ; } let n = 98765432 ; findPhoneNumber ( n ) ;
Number of ways to split a binary number such that every part is divisible by 2 | Javascript implementation of the approach ; Function to return the required count ; If the splitting is not possible ; To store the count of zeroes ; Counting the number of zeroes ; Return the final answer ; Driver code
var maxN = 20 ; var maxM = 64 ; function cntSplits ( s ) { if ( s [ s . length - 1 ] == ' ' ) return 0 ; var c_zero = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) c_zero += ( s [ i ] == ' ' ) ; return Math . pow ( 2 , c_zero - 1 ) ; } var s = " " ; document . write ( cntSplits ( s ) ) ;
Count number of substrings of a string consisting of same characters | Function to return the number of substrings of same characters ; Size of the string ; Initialize count to 1 ; Initialize left to 0 and right to 1 to traverse the string ; Checking if consecutive characters are same and increment the count ; When we encounter a different characters ; Increment the result ; To repeat the whole process set left equals right and count variable to 1 ; Store the final value of result ; Driver code
function findNumbers ( s ) { var n = s . length ; var count = 1 ; var result = 0 ; var left = 0 ; var right = 1 ; while ( right < n ) { if ( s [ left ] == s [ right ] ) { count ++ ; } else { result += parseInt ( count * ( count + 1 ) / 2 ) ; left = right ; count = 1 ; } right ++ ; } result += parseInt ( count * ( count + 1 ) / 2 ) ; document . write ( result ) ; } var s = " " ; findNumbers ( s ) ;
Program to duplicate Vowels in String | Function to check for the Vowel ; Function to get the resultant string with vowels duplicated ; Another string to store the resultant string ; Loop to check for each character ; Driver Code ; Print the original string ; Print the resultant string
function isVowel ( ch ) { ch = ch . toUpperCase ( ) ; return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function duplicateVowels ( str ) { let t = str . length ; let res = " " ; for ( let i = 0 ; i < t ; i ++ ) { if ( isVowel ( str [ i ] ) ) res += str [ i ] ; res += str [ i ] ; } return res ; } let str = " " ; document . write ( " " + str + " " ) ; let res = duplicateVowels ( str ) ; document . write ( " " + res + " " ) ;
Convert a String to an Integer using Recursion | Recursive function to convert string to integer ; If the number represented as a string contains only a single digit then returns its value ; Recursive call for the sub - string starting at the second character ; First digit of the number ; First digit multiplied by the appropriate power of 10 and then add the recursive result For example , xy = ( ( x * 10 ) + y ) ; Driver code
function stringToInt ( str ) { if ( str . length == 1 ) return ( str [ 0 ] - ' ' ) ; var y = stringToInt ( str . substring ( 1 ) ) ; var x = str [ 0 ] - ' ' ; x = x * Math . pow ( 10 , str . Length - 1 ) + y ; return ( x ) ; } var str = " " . split ( ) document . write ( stringToInt ( str ) ) ;
Longest subsequence with at least one character appearing in every string | Javascript implementation of the approach ; Function to return the length of the longest sub - sequence with at least one common character in every string ; count [ 0 ] will store the number of strings which contain ' a ' , count [ 1 ] will store the number of strings which contain ' b ' and so on . . ; For every string ; Hash array to set which character is present in the current string ; If current character appears in the string then update its count ; Driver code
var MAX = 26 ; function largestSubSeq ( arr , n ) { var count = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var str = arr [ i ] ; var hash = Array ( MAX ) . fill ( 0 ) ; for ( var j = 0 ; j < str . length ; j ++ ) { hash [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = true ; } for ( var j = 0 ; j < MAX ; j ++ ) { if ( hash [ j ] ) count [ j ] ++ ; } } return count . reduce ( ( a , b ) => Math . max ( a , b ) ) ; } var arr = [ " " , " " , " " ] ; var n = arr . length ; document . write ( largestSubSeq ( arr , n ) ) ;
Generate number with given operation and check if it is palindrome | Function that returns true if str is a palindrome ; Function that returns true if the generated string is a palindrome ; sub contains N as a string ; Calculate the sum of the digits ; Repeat the substring until the length of the resultant string < sum ; If length of the resultant string exceeded sum then take substring from 0 to sum - 1 ; If the generated string is a palindrome ; Driver code
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len / 2 ; i ++ ) { if ( str [ i ] != str [ len - 1 - i ] ) return false ; } return true ; } function createStringAndCheckPalindrome ( N ) { let sub = " " + N , res_str = " " ; let sum = 0 ; while ( N > 0 ) { let digit = N % 10 ; sum += digit ; N = N / 10 ; } while ( res_str . length < sum ) res_str += sub ; if ( res_str . length > sum ) res_str = res_str . substring ( 0 , sum ) ; if ( isPalindrome ( res_str ) ) return true ; return false ; } let N = 10101 ; if ( createStringAndCheckPalindrome ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Minimize the length of string by removing occurrence of only one character | Function to find the minimum length ; Count the frequency of each alphabet ; Find the alphabets with maximum frequency ; Subtract the frequency of character from length of string ; Driver Code
function minimumLength ( s ) { var maxOcc = 0 , n = s . length ; var arr = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) arr [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] > maxOcc ) maxOcc = arr [ i ] ; return ( n - maxOcc ) ; } var str = " " ; document . write ( minimumLength ( str ) ) ;
Remove all characters other than alphabets from string | function to remove characters and print new string ; Finding the character whose ASCII value fall under this range ; erase function to erase the character ; Driver code
function removeSpecialCharacter ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] < ' ' s [ i ] > ' ' && s [ i ] < ' ' s [ i ] > ' ' ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; i -- ; } } document . write ( s ) ; } let s = " " ; removeSpecialCharacter ( s ) ;
Remove all characters other than alphabets from string | function to remove characters and print new string ; Store only valid characters ; driver code
function removeSpecialCharacter ( str ) { let s = str . split ( " " ) ; let j = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( ( s [ i ] >= ' ' && s [ i ] <= ' ' ) || ( s [ i ] >= ' ' && s [ i ] <= ' ' ) ) { s [ j ] = s [ i ] ; j ++ ; } } document . write ( ( s ) . join ( " " ) . substring ( 0 , j ) ) ; } let s = " " ; removeSpecialCharacter ( s ) ;
Find repeated character present first in a string | Javascript program to find the first character that is repeated ; This is O ( N ^ 2 ) method ; Driver code
function findRepeatFirstN2 ( s ) { let p = - 1 , i , j ; for ( i = 0 ; i < s . length ; i ++ ) { for ( j = i + 1 ; j < s . length ; j ++ ) { if ( s [ i ] == s [ j ] ) { p = i ; break ; } } if ( p != - 1 ) break ; } return p ; } let str = " " ; let pos = findRepeatFirstN2 ( str ) ; if ( pos == - 1 ) document . write ( " " ) ; else document . write ( str [ pos ] ) ;
Print characters and their frequencies in order of occurrence | Javascript implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before ; Driver Code
function prCharWithFreq ( s ) { var d = new Map ( ) ; s . split ( ' ' ) . forEach ( element => { if ( d . has ( element ) ) { d . set ( element , d . get ( element ) + 1 ) ; } else d . set ( element , 1 ) ; } ) ; s . split ( ' ' ) . forEach ( element => { if ( d . has ( element ) && d . get ( element ) != 0 ) { document . write ( element + d . get ( element ) + " " ) ; d . set ( element , 0 ) ; } } ) ; } var s = " " ; prCharWithFreq ( s ) ;
Count number of strings ( made of R , G and B ) using given combination | Function to calculate number of strings ; Store factorial of numbers up to n for further computation ; Find the remaining values to be added ; Make all possible combinations of R , B and G for the remaining value ; Compute permutation of each combination one by one and add them . ; Return total no . of strings / permutation ; Drivers code
function possibleStrings ( n , r , b , g ) { let fact = new Array ( n + 1 ) ; fact [ 0 ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) fact [ i ] = fact [ i - 1 ] * i ; let left = n - ( r + g + b ) ; let sum = 0 ; for ( let i = 0 ; i <= left ; i ++ ) { for ( let j = 0 ; j <= left - i ; j ++ ) { let k = left - ( i + j ) ; sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ; } } return sum ; } let n = 4 , r = 2 ; let b = 0 , g = 1 ; document . write ( possibleStrings ( n , r , b , g ) ) ;
Remove minimum number of characters so that two strings become anagram | function to calculate minimum numbers of characters to be removed to make two strings anagram ; make hash array for both string and calculate frequency of each character ; count frequency of each character in first string ; count frequency of each character in second string ; traverse count arrays to find number of characters to be removed ; Driver program to run the case
function remAnagram ( str1 , str2 ) { var count1 = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; var count2 = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < str1 . length ; i ++ ) count1 [ str1 . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( i = 0 ; i < str2 . length ; i ++ ) count2 [ str2 . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var result = 0 ; for ( i = 0 ; i < 26 ; i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ; return result ; } var str1 = " " , str2 = " " ; document . write ( remAnagram ( str1 , str2 ) ) ;
Check if a string has all characters with same frequency with one variation allowed | Assuming only lower case characters ; To check a string S can be converted to a valid string by removing less than or equal to one character . ; freq [ ] : stores the frequency of each character of a string ; Find first character with non - zero frequency ; Find a character with frequency different from freq1 . ; If we find a third non - zero frequency or count of both frequencies become more than 1 , then return false ; } else If we find a third non - zero freq ; If counts of both frequencies is more than 1 ; Return true if we reach here ; Driver code
let CHARS = 26 ; function isValidString ( str ) { let freq = new Array ( CHARS ) ; for ( let i = 0 ; i < CHARS ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < str . length ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let i , freq1 = 0 , count_freq1 = 0 ; for ( i = 0 ; i < CHARS ; i ++ ) { if ( freq [ i ] != 0 ) { freq1 = freq [ i ] ; count_freq1 = 1 ; break ; } } let j , freq2 = 0 , count_freq2 = 0 ; for ( j = i + 1 ; j < CHARS ; j ++ ) { if ( freq [ j ] != 0 ) { if ( freq [ j ] == freq1 ) { count_freq1 ++ ; } else { count_freq2 = 1 ; freq2 = freq [ j ] ; break ; } } } for ( let k = j + 1 ; k < CHARS ; k ++ ) { if ( freq [ k ] != 0 ) { if ( freq [ k ] == freq1 ) { count_freq1 ++ ; } if ( freq [ k ] == freq2 ) { count_freq2 ++ ; { return false ; } } if ( count_freq1 > 1 && count_freq2 > 1 ) { return false ; } } return true ; } let str = " " ; if ( isValidString ( str ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Check if a string has all characters with same frequency with one variation allowed | To check a string S can be converted to a variation string ; Run loop form 0 to length of string ; declaration of variables ; if first is true than countOfVal1 increase ; if second is true than countOfVal2 increase ; Driver code
function checkForVariation ( str ) { if ( str == null str . length == 0 ) { return true ; } let map = new Map ( ) ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( ! map . has ( str [ i ] ) ) map . set ( str [ i ] , 0 ) ; map . set ( str [ i ] , map . get ( str [ i ] ) + 1 ) ; } let first = true , second = true ; let val1 = 0 , val2 = 0 ; let countOfVal1 = 0 , countOfVal2 = 0 ; for ( let [ key , value ] of map . entries ( ) ) { let i = value ; if ( first ) { val1 = i ; first = false ; countOfVal1 ++ ; continue ; } if ( i == val1 ) { countOfVal1 ++ ; continue ; } if ( second ) { val2 = i ; countOfVal2 ++ ; second = false ; continue ; } if ( i == val2 ) { countOfVal2 ++ ; continue ; } return false ; } if ( countOfVal1 > 1 && countOfVal2 > 1 ) { return false ; } else { return true ; } } document . write ( checkForVariation ( " " ) ) ;
Pairs of complete strings in two sets of strings | Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; Consider all pairs of both strings ; Create a concatenation of current pair ; Compute frequencies of all characters in the concatenated String . ; If frequency of any character is not greater than 0 , then this pair is not complete . ; Driver code
function countCompletePairs ( set1 , set2 , n , m ) { let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let concat = set1 [ i ] + set2 [ j ] ; let frequency = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { frequency [ i ] = 0 ; } for ( let k = 0 ; k < concat . length ; k ++ ) { frequency [ concat [ k ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let k ; for ( k = 0 ; k < 26 ; k ++ ) { if ( frequency [ k ] < 1 ) { break ; } } if ( k == 26 ) { result ++ ; } } } return result ; } let set1 = [ " " , " " , " " , " " ] ; let set2 = [ " " , " " , " " ] let n = set1 . length ; let m = set2 . length ; document . write ( countCompletePairs ( set1 , set2 , n , m ) ) ;
Pairs of complete strings in two sets of strings | Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; con_s1 [ i ] is going to store an integer whose set bits represent presence / absence of characters in string set1 [ i ] . Similarly con_s2 [ i ] is going to store an integer whose set bits represent presence / absence of characters in string set2 [ i ] ; Process all strings in set1 [ ] ; initializing all bits to 0 ; Setting the ascii code of char s [ i ] [ j ] to 1 in the compressed integer . ; Process all strings in set2 [ ] ; initializing all bits to 0 ; setting the ascii code of char s [ i ] [ j ] to 1 in the compressed integer . ; assigning a variable whose all 26 ( 0. . 25 ) bits are set to 1 ; Now consider every pair of integer in con_s1 [ ] and con_s2 [ ] and check if the pair is complete . ; if all bits are set , the strings are complete ! ; Driver code
function countCompletePairs ( set1 , set2 , n , m ) { let result = 0 ; let con_s1 = new Array ( n ) ; let con_s2 = new Array ( m ) ; for ( let i = 0 ; i < n ; i ++ ) { con_s1 [ i ] = 0 ; for ( let j = 0 ; j < set1 [ i ] . length ; j ++ ) { con_s1 [ i ] = con_s1 [ i ] | ( 1 << ( set1 [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; } } for ( let i = 0 ; i < m ; i ++ ) { con_s2 [ i ] = 0 ; for ( let j = 0 ; j < set2 [ i ] . length ; j ++ ) { con_s2 [ i ] = con_s2 [ i ] | ( 1 << ( set2 [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; } } let complete = ( 1 << 26 ) - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( ( con_s1 [ i ] con_s2 [ j ] ) == complete ) { result ++ ; } } } return result ; } let set1 = [ " " , " " , " " , " " ] ; let set2 = [ " " , " " , " " ] let n = set1 . length ; let m = set2 . length ; document . write ( countCompletePairs ( set1 , set2 , n , m ) ) ;
Find all strings that match specific pattern in a dictionary | Function to encode given string ; for each character in given string ; If the character is occurring for the first time , assign next unique number to that char ; append the number associated with current character into the output string ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; encode the string ; for each word in the dictionary array ; If size of pattern is same as size of current dictionary word and both pattern and the word has same hash , print the word ; Driver code
function encodeString ( str ) { let map = new Map ( ) ; let res = " " ; let i = 0 ; let ch ; for ( let j = 0 ; j < str . length ; j ++ ) { ch = str [ j ] ; if ( ! map . has ( ch ) ) map . set ( ch , i ++ ) ; res += map . get ( ch ) ; } return res ; } function findMatchedWords ( dict , pattern ) { let len = pattern . length ; let hash = encodeString ( pattern ) ; for ( let word = 0 ; word < dict . length ; word ++ ) { if ( dict [ word ] . length == len && encodeString ( dict [ word ] ) == ( hash ) ) document . write ( dict [ word ] + " " ) ; } } let dict = [ " " , " " , " " , " " ] ; let pattern = " " ; findMatchedWords ( dict , pattern ) ;
Find all strings that match specific pattern in a dictionary | Javascript program to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; For each word in the dictionary ; Driver code
function check ( pattern , word ) { if ( pattern . length != word . length ) return false ; let ch = new Array ( 128 ) ; for ( let i = 0 ; i < 128 ; i ++ ) { ch [ i ] = 0 ; } let Len = word . length ; for ( let i = 0 ; i < Len ; i ++ ) { if ( ch [ pattern [ i ] . charCodeAt ( 0 ) ] == 0 ) { ch [ pattern [ i ] . charCodeAt ( 0 ) ] = word [ i ] ; } else if ( ch [ pattern [ i ] . charCodeAt ( 0 ) ] != word [ i ] ) { return false ; } } return true ; } function findMatchedWords ( dict , pattern ) { let Len = pattern . length ; let result = " " ; for ( let word of dict . values ( ) ) { if ( check ( pattern , word ) ) { result = word + " " + result ; } } document . write ( result ) ; } let dict = new Set ( ) ; dict . add ( " " ) ; dict . add ( " " ) ; dict . add ( " " ) ; dict . add ( " " ) ; let pattern = " " ; findMatchedWords ( dict , pattern ) ;
Count words in a given string | Function to count total number of words in the string ; Check if the string is null or empty then return zero ; Converting the given string into a character array ; Check if the character is a letter and index of character array doesn 't  equal to end of line that means, it is  a word and set isWord by true ; Check if the character is not a letter that means there is a space , then we increment the wordCount by one and set the isWord by false ; Check for the last word of the sentence and increment the wordCount by one ; Return the total number of words in the string ; Given String str ; Print the result
function countWords ( str ) { if ( str == null str . length == 0 ) return 0 ; let wordCount = 0 ; let isWord = false ; let endOfLine = str . length - 1 ; let ch = str . split ( " " ) ; for ( let i = 0 ; i < ch . length ; i ++ ) { if ( isLetter ( ch [ i ] ) && i != endOfLine ) isWord = true ; else if ( ! isLetter ( ch [ i ] ) && isWord ) { wordCount ++ ; isWord = false ; } else if ( isLetter ( ch [ i ] ) && i == endOfLine ) wordCount ++ ; } return wordCount ; } function isLetter ( c ) { return c . toLowerCase ( ) != c . toUpperCase ( ) ; } let str = " " ; document . write ( " " + countWords ( str ) ) ;
Reverse words in a given string | Reverse the string ; Check if number of words is even ; Find the middle word ; Starting from the middle start swapping words at jth position and l - 1 - j position ; Check if number of words is odd ; Find the middle word ; Starting from the middle start swapping the words at jth position and l - 1 - j position ; Return the reversed sentence ; Driver code
function RevString ( s , l ) { if ( l % 2 == 0 ) { let j = parseInt ( l / 2 , 10 ) ; while ( j <= l - 1 ) { let temp ; temp = s [ l - j - 1 ] ; s [ l - j - 1 ] = s [ j ] ; s [ j ] = temp ; j += 1 ; } } else { let j = parseInt ( ( l / 2 ) , 10 ) + 1 ; while ( j <= l - 1 ) { let temp ; temp = s [ l - j - 1 ] ; s [ l - j - 1 ] = s [ j ] ; s [ j ] = temp ; j += 1 ; } } let S = s [ 0 ] ; for ( let i = 1 ; i < 9 ; i ++ ) { S = S + " " + s [ i ] ; } return S ; } let s = " " " " ; let words = [ " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; document . write ( RevString ( words , 9 ) ) ;
Print path from root to all nodes in a Complete Binary Tree | Function to print path of all the nodes nth node represent as given node kth node represents as left and right node ; base condition if kth node value is greater then nth node then its means kth node is not valid so we not store it into the res simply we just return ; Storing node into res ; Print the path from root to node ; store left path of a tree So for left we will go node ( kThNode * 2 ) ; right path of a tree and for right we will go node ( kThNode * 2 + 1 ) ; Function to print path from root to all of the nodes ; res is for store the path from root to particulate node ; Print path from root to all node . third argument 1 because of we have to consider root node is 1 ; Given Node ; Print path from root to all node .
function printPath ( res , nThNode , kThNode ) { if ( kThNode > nThNode ) return ; res . push ( kThNode ) ; for ( var i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] + " " ) ; document . write ( " " ) ; printPath ( res , nThNode , kThNode * 2 ) ; printPath ( res , nThNode , kThNode * 2 + 1 ) ; res . pop ( ) } function printPathToCoverAllNodeUtil ( nThNode ) { var res = [ ] ; printPath ( res , nThNode , 1 ) ; } var nThNode = 7 ; printPathToCoverAllNodeUtil ( nThNode ) ;
Maximum number of region in which N non | Function to find the maximum number of regions on a plane ; print the maximum number of regions ; Driver code
function maxRegions ( n ) { let num ; num = parseInt ( n * ( n + 1 ) / 2 ) + 1 ; document . write ( num ) ; } let n = 10 ; maxRegions ( n ) ;
Check whether jigsaw puzzle solveable or not | Function to check if the jigsaw Puzzle is solveable or not ; Base Case ; By placing the blank tabs as a chain ; Driver code
function checkSolveable ( n , m ) { if ( n == 1 m == 1 ) document . write ( " " ) ; else if ( m == 2 && n == 2 ) document . write ( " " ) ; else document . write ( " " ) ; } let n = 1 , m = 3 ; checkSolveable ( n , m ) ;