- 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++
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
154 Views
In this problem, we are given a string and an integer M. our task is to print all distinct circular strings of length M in lexicographical order (alphabetical order).Let’s take an example to understand the problem, Input: str= “ssssn” M=3 Output: nss sns ssn sssExplanation − all possible circular strings of length 3 are: sss sss ssn sns nss. Distinct elements in lexicographical order are sss ssn sns nss.To solve this problem, we will iterate over the elements of the string and generate all possible substrings of length M. we will store this generated string in a set that stores ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
654 Views
In this problem, we are given an array of integer values. Our task is to print all distinct elements of the array. The output should contain only distinct values.Let’s take an example to understand the problemInput: array = {1, 5, 7, 12, 1, 6, 10, 7, 5} Output: 1 5 7 12 6 10To solve this problem, we will have to check elements of the array for uniqueness. For this, we will use two nested loops, the outer one will take values and the inner one will check the rest of the values with it. If more than one values ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
185 Views
In this problem, we are given an array of N integers and a number K. Our task is to print all distinct numbers that can be created by adding any K elements from the array. While choosing any number can be repeated K times.Let’s take an example to understand the problem −Input: array = {2, 5, 13, 9} K = 2 Output: 2, 7, 15, 11, 10, 18, 14, 26, 22 Explaination: 2 elements added : 2+2=4, 2+5=7, 2+13=15, 2+9=11, 5+5=10, 5+13=18, 5+9=14, 13+13=26, 13+9=22, 9+9=18To solve this problem, we will find all combinations of the k element from the ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
219 Views
In this problem, we are given a string that may contain duplicate characters. Our task is to print all distinct permutations of the strings.Let’s take an example to understand the problem −Input: string = “XYZ” Output: XYZ XZY YXZ YZX ZYX ZXYTo solve this problem, we have to fix one element of the string. And then iterate all the elements of the strings.ExampleProgram to implement our solution, Live Demo#include #include using namespace std; int compare(const void* a, const void* b) { return (*(char*)a - *(char*)b); } void swapChar(char* a, char* b) { char t = *a; ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
271 Views
In this problem, we are given a binary search tree. Our task is to print all even valued nodes of the binary search tree.The binary search tree is a binary tree that follows the following condition −The left sub-tree always contains nodes with smaller values than the parent node.Right, sub-tree always contains nodes with greater values than the parent node.All nodes have to follow the above 2 rules.Example of a binary search tree −Let’s take an example to understand the problem −Output − 2 4 6 8To solve this problem, we will have to traverse all nodes of the binary ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
462 Views
In this problem, we are given a binary tree. Our task is to print all nodes of the tree that are full nodes.The binary tree is a tree in which a node can have a maximum of 2 child nodes. Node or vertex can have no nodes, one child or two child nodes.Example −A full node is a node that has both its left and right child available. In other words, a node with the left and right child is a full node. In the above binary tree, 4 and 9 are full nodes.Let’s take an example to understand the ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
148 Views
In this problem, we are given a sentence. Our task is to print all strings from the sentence that are funny words.Funny word is a word that follows the condition - The absolute difference between adjacent characters of the string and its reverse string is equal.|string[0] - string[1]| = |revstring[0]-revstring[1]|Let’s take an example to understand the problem −Input: string = ‘ABRS’ Output: Yes Explanation: Reverse string = SRBA |A-B| = 1 = |S-R| |B-R| = 16 = |R-B| |B-A| = 1 = |R-S|To solve this problem, we have to extract each string from the given sentence. And print if the ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
654 Views
In this problem, we are given three values L, R, and d. Our task is to print all good numbers within the range L to R that do not contain the d as its digit.A good number is a number in which every digit is larger than the sum of digits of its right (all less significant bits than it). For example, 732 is a good number, 7> 3+2 and 3>2.Now, let’s take an example to understand the problem, Input: L = 400 , R = 500 , k = 3 Output: 410, 420, 421Explanation − good numbers between 400 ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
391 Views
In this problem, we are given two integers K and n. Our task is to print all increasing sequences of length K using first n natural numbers.The increasing sequence is a sequence of numbers in which the value of the next element is greater than the previous one.Let’s take an example to understand the problem −Input: n = 4, K = 2 Output: 1 2 1 3 1 4 2 3 2 4 3 4To solve this problem, we will create a k length array that stores the current sequence of the array. And for every position in the array, ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
147 Views
In this problem, we are given two numbers a and b and an integer bound and we have to print all values less than binding which is the sum of squares of a and b.Bound >= ai + bjLet’s take an example to understand the problem −Input: a=2, b=3, bound=8 Output: 2 3 4 5 7To solve this problem, we will use nested loops using two variables i and j from 0. The outer loop will have ending condition xi = bound and the inner loop will have ending condition xi + yj > bound. For each iteration of the ... Read More