Let us suppose we have two strings 'a' and 'b' and a string 'merge'. The task is to fill the string 'merge' with the characters from 'a' and 'b' in such a way that, If the string 'a' is non-empty, then remove the first character from the string 'a' and copy it into string 'merge'.If the string 'b' is non-empty, then remove the first character from the string 'b' and copy it into string 'merge'.If the strings 'a' and 'b' are non-empty, then remove the first characters from string 'a' and copy it into string 'merge' and then remove the ... Read More
Let us suppose we have three numbers. The task is to count the total number of optimal steps to make all these numbers '0'.For ExampleInput-1:a = 4 b = 4c = 6Output:7Explanation: Total number of optimal steps to make all the numbers '0' is, (4, 4, 6)Removing '1' from 1st and 2nd number = (3, 3, 6)Removing '1' from 1st and 3rd number = (2, 3, 5)Removing '1' from 1st and 3rd number = (1 ,3, 4)Removing '1' from 1st and 3rd number = (0 ,3 ,3)Removing '1' from 2nd and 3rd number = (0 ,2, 2)Removing '1' from 2nd and ... Read More
Let us suppose we have three integers 'a' and 'b' and 'limit'. The task is to print the numbers in the range [a, limit]. List of these numbers is said to be powerful integers and represented as, a^i + b^j such that i >= 0 and j >= 0For ExampleInput-1:a = 2b = 5limit = 10Output:[2, 3, 4, 5, 6, 7, 9]Explanation: for each i and j, 2^0 + 5^0 = 2 , 2^0 + 5^1= 6 2^1 + ... Read More
A string is said to be a palindromic string if it remains the same after reversing it.In this particular problem, we've given two strings 'a' and 'b' of the same length. If they are split with some indexes, then the task is to check whether the sum of the strings makes a palindrome or not.Let's say we have two string 'a' and 'b' of length '4' and after splitting both the string at the index '3' such that, aaa | b and bbb | aaaa (prefix of first string) + a(suffix of ... Read More
Let us suppose we have a binary tree and the task is to check whether it constructs a symmetry of itself or not. A Symmetric Binary tree constructs the mirror image of itself.For ExampleInput-1: Output:TrueExplanation:Since the given binary tree constructs the mirror image of itself, the output is True.Input-2: Output:FalseExplanation:Since the given binary tree doesn't make a mirror image of itself, it is not symmetric.Approach to Solve this ProblemA symmetric binary tree is a tree which is the mirror image of itself, which means we have to check whether the left and right nodes of the tree are ... Read More
In a binary tree, each node contains two children, i.e left child and right child. Let us suppose we have a binary tree and we need to check if the tree is balanced or not. A Binary tree is said to be balanced if the difference of height of left subtree and right subtree is less than or equal to '1'.ExampleInput-1: Output:TrueExplanation:The given binary tree is [1, 2, 3, NULL, NULL, 6, 7]. The height difference of its left subtree and right subtree is equal to '1', thus it is a height Balanced tree.Input-2: Output:FalseExplanation:The given ... Read More
A Linked List is a linear data structure in which each node is having two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to other nodes in the list. The task is to construct the list with the same as the original list. Copying the list from the original list which is having some random pointer is called a 'Deep Copy' of the linked list.For ... Read More
Let us suppose we have two strings 'a' and 'b' and a string 'merge'. The task is to fill the string 'merge' with the characters from 'a' and 'b' in such a way that, If the string 'a' is non-empty, then remove the first character from the string 'a' and copy it into string 'merge'.If the string 'b' is non-empty, then remove the first character from the string 'b' and copy it into string 'merge'.If the strings 'a' and 'b' are non-empty, then remove the first characters from string 'a' and copy it into string 'merge' and then remove the ... Read More
Let us suppose we have three numbers. The task is to count the total number of optimal steps to make all these numbers '0'.For ExampleInput-1:a = 4 b = 4 c = 6Output:7Explanation:The total number of optimal steps to make all the numbers '0' is, (4, 4, 6)Removing '1' from 1st and 2nd number = (3, 3, 6)Removing '1' from 1st and 3rd number = (2, 3, 5)Removing '1' from 1st and 3rd number = (1 ,3, 4)Removing '1' from 1st and 3rd number = (0 ,3 ,3)Removing '1' from 2nd and 3rd number = (0 ,2, 2)Removing '1' from ... Read More
Expression trees are those in which the leaf nodes have the values to be operated, and the internal nodes contain the operator on which the leaf node will be performed.Example: 4 + ((7 + 9) * 2) will have an expression tree like -Approach to solve this ProblemIn order to construct an Expression Tree for a given expression, we generally use Stack Data Structure. Initially we Iterate over the given postfix expression and follow the steps as given below -If we get an operand in the given expression, then push it in the stack. It will become the root of the ... Read More