Given a string 'a' and a character 'char', the task is to print the distance of 'char' from each character of the given string. The size of the distance array is same as the size of the string, since we have to find the distance of the character from each character of the given string.For ExampleInput-1:a = “tutorialspoint”char = “o”Output: [ 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3]Explanation: In the given string, the distance of the character from each character of the given string is [3, 2, 1, 0, 1, 2, 3, 4, 5, 6, ... Read More
Let us suppose we have a Binary Tree having a root node and its left child and right child. The task is to find the total sum of leaf nodes of the tree which are left to its parent node.For ExampleInput-1: Output:15Explanation: In the given input Binary Tree, the sum of all the left leaf nodes is 9+4+2 = 15. So, the output is 15.Approach to Solve this ProblemWe have a Binary Tree and the task is to find the sum of all the leaf nodes which are left to its parent.The recursive approach to solve this problem is to ... Read More
A Linked List is a linear data structure in which each node has 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 the other nodes in the list. The task is to find the node at which two linked lists intersect each other. If they don't intersect, then return NULL or empty as output.For ExampleInput-1: Output:2Explanation: Since the given linked ... 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 = 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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP