Reconstruct Original Digits from English in C++

Arnab Chakraborty
Updated on 28-Apr-2020 12:32:27

420 Views

Suppose we have a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order. There are some properties −Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as "abc" or "zerone" are not permitted.Input length is less than 50, 000.So if the input is like “fviefuro”, then the output will be 45.To solve this, we will follow these steps −nums := an array that is holding the numbers in English letter from 0 to 9.make one array count of size 10ans := an empty ... Read More

Partition Equal Subset Sum in C++

Arnab Chakraborty
Updated on 28-Apr-2020 12:28:44

422 Views

Suppose we have a non-empty array containing only positive numbers, we have to find if the array can be partitioned into two subsets such that the sum of elements in both subsets is the same. So if the input is like [1, 5, 11, 5], the output will be true. As this array can be partitioned as [1, 5, 5] and [11]To solve this, we will follow these steps −n := size of the arraysum := 0for i := 0 to n – 1sum := sum + nums[i]if sum is odd, return falsesum := sum / 2create one array called ... Read More

Queue Reconstruction by Height in C++

Arnab Chakraborty
Updated on 28-Apr-2020 12:23:17

369 Views

Consider we have a random list of people standing in a queue. If each person is described by a pair of integers (h, k), where h is the height and k is the number of people in front of him, who have a height greater than or equal to h. We have to define one method to reconstruct the queue. So if the given array is like [[7, 0], [4, 4], [7, 1], [5, 0], [6, 1], [5, 2]], then the output will be [[5, 0], [7, 0], [5, 2], [6, 1], [4, 4], [7, 1]]To solve this, we will ... Read More

Longest Substring with at Least K Repeating Characters in C++

Arnab Chakraborty
Updated on 28-Apr-2020 12:18:21

309 Views

Suppose we have a string s, and we have to find the length of the longest substring T of that given string (consists of lowercase letters only) such that every character in T appears no less than k times. So if the string is “ababbc” and k = 2, then the output will be 3 and longest substring will be “ababb”, as there are two a’s and three b’s.To solve this, we will follow these steps −create one recursive function called longestSubstring(), this takes string s and size kif k = 1, then return the size of the stringif size ... Read More

Decode String in C++

Arnab Chakraborty
Updated on 28-Apr-2020 12:10:27

3K+ Views

Suppose we have an encoded string; we have to return its decoded string. The rule for encoding is: k[encoded_string], this indicates where the encoded_string inside the square brackets is being repeated exactly k times. We can assume that the original data does not contain any numeric characters and that digits are only for those repeat numbers, k. So if the input is like “1[ba]2[na]”, then the output will be “banana”.To solve this, we will follow these steps −create one empty stack, set i := 0while i < size of a stringif s[i] is ‘]’res := delete element from the stack ... Read More

Combination Sum IV in C++

Arnab Chakraborty
Updated on 28-Apr-2020 11:53:24

286 Views

Suppose we have an integer array with all positive numbers and all elements are unique, find the number of possible combinations, so that if we add up, we will get positive integer target.So if the array is [1, 2, 3] and the target is 4, then the possible combinations will be [[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 3], [3, 1], [2, 2]], so output will be 7.To solve this, we will follow these steps −Suppose we have one recursive function called solve(), this is taking array, target and another array for dynamic ... Read More

Coin Change Problem in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:50:21

5K+ Views

Suppose we have coins of different denominations and a total amount of money amount. We have to define one function to compute the fewest number of coins that we need to make up that amount. When that amount of money cannot be accommodated by any combination of the coins, return -1. So if the input is [1, 2, 5], and the amount is 11, the output is 3. This is formed using 5 + 5 + 1 = 11.To solve this, we will follow these steps −if amount = 0, then return 0if minimum of coins array > amount, then ... Read More

Sum Root to Leaf Numbers in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:45:08

457 Views

Suppose we have a binary tree containing digits from 0-9 only, here all root-to-leaf path could represent a number.So if the tree is like −This is representing two paths 21 and 23, so the output will be 21 + 23 = 44.To solve this, we will follow these steps −Create one recursive function called dfs(), this will take root, and num. initially num = 0if the node is not nullnum := num * 10 + value of nodeif node right is not null and node left is not null, then’sum := sum + numnum := num / 10return from the ... Read More

Importance of jdeps Tool in Java 9

raja
Updated on 28-Apr-2020 11:33:16

497 Views

The jdeps is a Java Class Dependency Analyzer tool, which is a command-line tool to show the package-level or class-level dependencies of given Java class files. The input classes can be given as a path-name to a .class file, a directory, a jar file, or it will be a fully qualified class name to analyze all class files."jdeps" has included in the jdk installation since jdk 8 and, it is represented by the "%java_home%\bin\jdeps.exe" program file. If we have "%java_home%\bin" directory included in the "path" environment variable, we will run "jdeps --help" command to see a complete list of all options. Below, we can ... Read More

Unique Binary Search Trees II in C++

Arnab Chakraborty
Updated on 28-Apr-2020 11:21:10

437 Views

Suppose we have an integer n, we have to generate all structurally unique binary search trees that store values from 1 to n. So if the input is 3, then the trees will be −To solve this, we will follow these steps −Define one recursive function called generate(), this will take low and highdefine one tree node called temp.if low > high, then insert null into the temp, and return tempfor i in range low to highleft_subtree := generate(low, i – 1)right_subtree := generate(i + 1, high)current := ifor j in range 0 to size of the left_subtreefor k in ... Read More

Advertisements