AmitDiwan has Published 10744 Articles

Checking for a Doubleton Number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 10:52:04

288 Views

Doubleton NumberWe will call a natural number a "doubleton number" if it contains exactly two distinct digits. For example, 23, 35, 100, 12121 are doubleton numbers, and 123 and 9980 are not.ProblemWe are required to write a JavaScript function that takes in a number and return true if it is ... Read More

Converting to hex and summing the numeral part in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 10:49:30

284 Views

ProblemWe are required to write a JavaScript function that takes in a string. Our function should convert every character of the string to the hex value of its ascii code, then the result should be the sum of the numbers in the hex strings ignoring the letters present in hex.ExampleFollowing ... Read More

Finding the nth element of the lucas number sequence in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 10:32:56

265 Views

Lucas NumbersLucas numbers are numbers in a sequence defined like this −L(0) = 2 L(1) = 1 L(n) = L(n-1) + L(n-2)ProblemWe are required to write a JavaScript function that takes in a number n and return the nth lucas number.ExampleFollowing is the code − Live Democonst num = 21; const ... Read More

Python Program to Accept Three Digits and Print all Possible Combinations from the Digits

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:45:47

2K+ Views

When it is required to print all possible combination of digits when the input is taken from the user, nested loop is used.Below is a demonstration of the same −Example Live Demofirst_num = int(input("Enter the first number...")) second_num = int(input("Enter the second number...")) third_num = int(input("Enter the third number...")) my_list = ... Read More

Python Program to Print All Permutations of a String in Lexicographic Order using Recursion

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:43:57

336 Views

When it is required to print all the permutations of a string in lexicographic order using recursion, a method is defined, that uses the ‘for’ loop to iterate over the sequence of elements, and use the ‘join’ method to join the elements.Below is the demonstration of the same −Example Live Demofrom ... Read More

Python Program to Print only Nodes in Left SubTree

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:41:26

275 Views

When it is required to print the nodes in the left subtree, a class can be created that consists of methods can be defined to set the root node, perform in order traversal, insert elements to the right of the root node, to the left of the root node, and ... Read More

Python Program to Print All Permutations of a String in Lexicographic Order without Recursion

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:38:58

457 Views

When it is required to print all the permutations of a string in the lexicographic order without using recursion, a method is defined, that takes the string as the parameter. It uses a simple ‘for’ loop to iterate over the string elements and uses ‘while’ condition to check for certain ... Read More

Python Program to Form a New String Made of the First 2 and Last 2 characters From a Given String

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:38:18

720 Views

When it is required to form a new string that is made from the first two and last two characters of a given string, a counter can be defined, and indexing can be used to access specific range of elements.Below is the demonstration of the same −Example Live Demomy_string = "Hi ... Read More

Python Program to Create a Mirror Copy of a Tree and Display using BFS Traversal

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:34:24

658 Views

When it is required to create a mirror copy of a tree, and display it using breadth first search, a binary tree class is created with methods set the root element, insert element to left, insert element to right, search for a specific element, and perform post order traversal and ... Read More

Python Program to Implement Depth First Search Traversal using Post Order

AmitDiwan

AmitDiwan

Updated on 16-Apr-2021 12:31:03

485 Views

When it is required to implement depth first search using post order traversal, a tree class is created with methods to add element, search for a specific element, and perform post order traversal and so on. An instance of the class is created, and it can be used to access ... Read More

Advertisements