
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7197 Articles for C++

266 Views
Given a linked list in this tutorial, and we need to keep all the numbers smaller than x at the start of the list and the others at the back. We also need to retain their order the same as previously. for exampleInput : 1->4->3->2->5->2->3, x = 3 Output: 1->2->2->3->3->4->5 Input : 1->4->2->10 x = 3 Output: 1->2->4->10 Input : 10->4->20->10->3 x = 3 Output: 3->10->4->20->10To solve this problem, we need to make three linked lists now. When we encounter a number smaller than x, then we insert it into the first list. Now for a value equal ... Read More

583 Views
A number that contains all the digits from 0 to base B is called the Pandigital number in that base. However, some numbers have digits from 1 to 9 and are called zeroless pandigital numbers. Some Examples of pandigital numbers are 0123456789, 0789564312, etc.In this tutorial, we will discuss a problem where we are given a number and a base, and we need to check whether the number is pandigital in the given base or not, for example −Input: num = “9651723467380AZ”, base = 10 Output: YES Explanation: num contains all the digits in the base 10 i.e from 0 ... Read More

411 Views
To solve a problem in which we are required to swap the pairwise nodes present in a linked list and then print it, for exampleInput : 1->2->3->4->5->6->NULL Output : 2->1->4->3->6->5->NULL Input : 1->2->3->4->5->NULL Output : 2->1->4->3->5->NULL Input : 1->NULL Output : 1->NULLThere are two ways to approach the solution both to have a time complexity of O(N), where N is the size of our provided linked list, so now we are going to explore both of the approachesIterative ApproachWe will iterate through the linked list elements in this approach, and pairwise swap them until they ... Read More

321 Views
Given a binary tree. The task is to pairwise swap the leaf nodes, for example −Input −Output −We will keep track of two pointers that point to the two adjacent leaf nodes and swap their values in the given problem.Approach to Find the SolutionIn this approach, we traverse the tree, find the leaf nodes, and keep track of our counter to check the current count. The main trick is that our counter is odd, so our first pointer points to that node now. When our counter becomes even, we swap the data, and hence our leaf nodes are swapped.ExampleC++ Code ... Read More

225 Views
To find the largest subset from the given array in which the sum of every pair is a prime number. Assuming maximum element is 100000, for example −Input: nums[ ] = { 3, 2, 1, 1 } Output: size = 3, subset = { 2, 1, 1 } Explanation: Subsets can be formed: {3, 2}, {2, 1} and { 2, 1, 1}, In {2, 1, 1} sum of pair (2, 1) is 3 which is prime, and the sum of pairs (1, 1) is 2 which is also a prime number. Input: nums[ ] = {1, 4, 3, 2} ... Read More

182 Views
Given a binary tree. Now we are tasked to find the largest subtree having an equal number of 1's and 0's; the tree only contains 0's and 1's.Approach to Find the SolutionIn this approach, we are going to replace all the nodes with values of 0 to -1. Doing this will make our program simpler as we now need to find the largest subtree with a sum equal to 0.ExampleC++ Code for the Above Approach #include using namespace std; int maxi = -1; struct node { // structure of our tree node int data; struct ... Read More

290 Views
This tutorial will discuss a problem where we are given an array of distinct positive integers. We need to find the largest subset such that for every pair larger element is divided by a smaller element, for example −Input: nums[ ] = { 1, 4, 2, 6, 7} Output: 1 2 4 Explanation: All Divisible subsets are: (1, 2, 4), (1, 2, 6), (1, 7), etc We have 2 subsets of length 3 in which all the pairs satisfy the condition. Input: nums[ ] = { 1, 2, 3, 6 } Output: 6 2 1Approach to Find the SolutionThere ... Read More

214 Views
To solve a problem in which we are given an array consisting of distinct elements. Now our task is to find the subset such that every pair is evenly divisible, i.e, every large element is divisible by every smaller element, for example.Input : arr[] = {10, 5, 3, 15, 20} Output : 3 Explanation: The largest subset is 10, 5, 20. 10 is divisible by 5, and 20 is divisible by 10. Input : arr[] = {18, 1, 3, 6, 13, 17} Output : 4 Explanation: The largest subset is 18, 1, 3, 6, In the subsequence, 3 is ... Read More

154 Views
To solve a problem where we are given an array, and we need to find all possible integers which are bitwise AND of at least one not empty subarray, for example −Input : nums[ ] = { 3, 5, 1, 2, 8 } Output : { 2, 5, 0, 3, 8, 1 } Explanation: 2 is the bitwise AND of subarray {2}, 5 is the bitwise AND of subarray {5}, 0 is the bitwise AND of subarray {1, 2}, {2, 8} and {1, 2, 8}, 3 is the bitwise AND of subarray {3}, 8 is the bitwise AND of subarray ... Read More

224 Views
The sum of its digit can find the digital root of a number; if the sum is a single digit, it is a digital root. In this tutorial, we will discuss a problem where we are given a range of numbers and an integer X, and we need to count how many numbers in the range have digital roots as X where X is a single-digit number, for exampleInput: l = 13, r = 25, X = 4 Output: 2 Explanation: Numbers in the range (13, 25) having digit sum 4 are 13 and 22. Input: l = 11, ... Read More