- 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++
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
116 Views
We are a variable num. The goal is to find the count of permutations of numbers between [1, num] in which numbers are first decreasing then increasing. For example if num=3 then numbers are 1, 2, 3. The permutations will be [ 3, 1, 2 ] and [2, 1, 3] and count is 2.We know that in every permutation the change from decreasing of numbers to increasing of numbers will be decided based on position of 1 which is smallest. After each 1 the numbers will start increasing. For a permutation to decrease and then increase, 1 should lie between ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
202 Views
We are two variables n and m representing a grid of size n x m and initial point x, y to start from.Also given pairs of steps/moves that can be taken to traverse inside the grid as moves ( (1, 1), (2, 2) ) etc. Each pair of moves represents the unit of steps taken in the x, y axis. The goal is to find the total steps that can be taken to traverse inside the grid within boundaries [1, n] X [1, m] If n is 5 and m is 4 and current position is 2, 2 and step ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
681 Views
We are given a string containing the parentheses and the task is to calculate the count of pairs of parentheses sequences that can be formed such that the parentheses are balanced.Parentheses are said to be balanced when there are equal numbers of opening and closing brackets. The parentheses used once can’t be considered twice for forming the pair.Input − string paran[] = { ")()())", "(", ")(", ")(", ")" }Output − Count of pairs of parentheses sequences such that parentheses are balanced are: 1Explanation − we will take every set of string to calculate the count better. Lets take the first ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
173 Views
We are given a string which can contain “ab” and the task is to calculate the count of operations required to remove or delete “ab” from the string. So, our task is to firstly check whether the string contains “ab” or not if yes then we have to make string “ab” free.Input − string str = "ababaa"Output − Count of operations to make a binary string “ab” free are − 4Explanation − As we can see in the string “ab” pattern is occurring two times so we will replace “ab” with “bba” so the count of operations is 1 and ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
198 Views
We are given an array of integer elements and the task is to calculate the count of sub-arrays that can be formed from the given array such that its elements can form a valid palindrome. Palindromes are the sequences that are arranged similarly from start and the end.Input − int arr[] = { 3, 3, 1, 4, 2, 1, 5}Output − Count of sub-arrays whose elements can be re-arranged to form palindromes are − 9Explanation − The valid sub-arrays whose elements can be arranged to form a palindrome are {3}, {3}, {1}, {4}, {2}, {1}, {5}, {1, 2, 1} and ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
277 Views
We are given two strings i.e. str1 and str2 and the task is to calculate the count of strings that can completely be generated from another string, but we can use one character once for forming the string. Like, we will take two strings str1 and str2 and check for the occurrence of str2 in str1 by using the character of str1 exactly once.Input − str_1 = "technical learning", str_2 = "learning"Output − Count of strings that can be formed from another string using each character at-most once are − 1Explanation − As we can see str_2 occurs in str_1 ... Read More
Count pairs (p, q) such that p occurs in array at least q times and q occurs at least p times in C++
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
175 Views
We are given an array of positive integers. The goal is to find the count of pairs of elements of arr[] such that pairs have elements ( p, q ) where p occurs in array for at least q times and q occurs in array for at-least p times.Let us understand with examples.Input − int arr[] = { 3, 3, 3, 5, 5, 6, 6}Output − Count of pairs in an array such that frequency of one is at least value of other are − 1Explanation − The valid pairs in an array where p occurs q times and q ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
231 Views
We are given an array of positive integers. The goal is to find the count of pairs of elements of arr[] such that pairs have elements ( A, B ) where frequency of A is B times and frequency of B is A.Let us understand with examples.Input − int arr[] = { 3, 3, 3, 5, 5, 6, 6}Output − Count of pairs in an array such that frequency of one is at least value of other are − 1Explanation − The valid pairs in an array where A occurs B times and B occurs A times are (3, 3) ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
424 Views
We are given a string of binary numbers i.e. combination of 0’s and 1’s and an integer value k and the task is to calculate the count of substrings formed with the given binary string having given k 1’s.Input − string str = ‘10000100000’, k = 2Output − Count of substrings of a binary string containing K ones are − 6Explanation − Substrings that can be formed from the given string are 1, 10, 100, 1000, 10000, 010, 100001, 10001, 1001, 101, 11, 1000010. So there are 6 substrings having k number of 1’s i.e. exactly 2 ones.Input − string ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
558 Views
We are given a string str[] and a number n. The goal is to find all substrings of str[] that have length n. If string is “abcde” and n=3 then substrings of length 3 are “abc”, “bcd”, “cde” and count is 3.Let us understand with examples.Input − str[] = “computer” n=4Output − Count of substrings of length n possible from the given string are − 5Explanation − Substrings with length 4 are: “comp”, “ompu”, ”mput”, “pute”, “uter”Input − str[] = “development” n=5Output − Count of substrings of length n possible from the given string are − 7Explanation − Substrings with ... Read More