- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
180 Views
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
1K+ Views
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
921 Views
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
434 Views
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
2K+ Views
Given a 32-bit Unsigned Binary Number, the task is to count the set bits, i.e., '1's present in it.For ExampleInput:N = 00000000000000100111Output:4Explanation: Total set bits present in the given unsigned number is 4, thus we will return the output as '4'.Approach to Solve this ProblemWe have given an unsigned 32-bit binary number. The task is to count how many '1's present in it.To count the number of '1's present in the given binary number, we can use the inbuilt STL function '__builin_popcount(n)' which takes a binary number as the input parameter.Take a binary number N as the input.A function count1Bit(uint32_t n) ... Read More
325 Views
Let us suppose we have an array of positive temperatures which represent the temperatures T. The task is to calculate how many days are there for the next warmer temperature in the given list.For exampleInput-1: T = [ 73, 74, 75, 71, 69, 72, 76, 73]Output: [1, 1, 4, 2, 1 ,1 ,0 ,0]Explanation: In the given list of temperatures [73, 74, 75, 71, 69, 72, 76, 73], the next greater temperature is at Day 1. Similarly, Day 6 is the warmest in all the temperatures, thus the output will be [ 1, 1, 4, 2, 1, 1, 0, 0].Approach to Solve this ... Read More
583 Views
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
268 Views
Circle Sort is an interesting sorting algorithm to sort a given array of elements. The algorithm compares the elements of the array diametrically and once the elements in one part is sorted, then continuously sort the other end of the array diametrically.ExampleLet us visualize the circle sort for an array. Let us suppose we have an array with 6 elements.Input:N = 6arr [ ] = { 2, 1, 5, 8, 7, 9 }When we draw concentric circles for each array element, then it will appear as followsOutput:1 2 5 7 8 9Explanation: After sorting the elements in the array using Circle ... Read More
3K+ Views
Given a non-negative number, the task is to find its smallest digit.For exampleInput:N = 154870Output:0Explanation: In the given number '154870', the smallest digit is '0'.Approach to Solve this ProblemThe simplest approach to solve this problem is to extract the last digit in the given number using the remainder theorem. While traversing the number, we will check if the extracted digit is less than the last digit, then return the output.Take a number n as the input.An integer function smallest_digit(int n) takes 'n' as the input and returns the smallest digit in the given number.Now initialize min as the last digit of the ... Read More
1K+ Views
Given a Binary Tree, the task is to check whether it is a Full Binary Tree or not. A Binary Tree is said to be a Full Binary Tree if every node has zero or two children.For ExampleInput-1Output:1Explanation: Every node except the leaf node has two children, so it is a full binary tree.Input-2: Output:0Explanation: Node 2 has only one child, so it is not a full binary tree.Approach to Solve this ProblemTo check whether a given binary tree is full or not, we can check recursively for the left subtree and right subtree.Input a given Binary Tree having nodes and its children.A ... Read More