- 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++
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
745 Views
Discuss a problem to rearrange a string of alphabets in sorted order and add all the integers present in the string, for exampleInput : str = “adv4fc3” Output : “ acdfv7” Explanation: all the letters have been sorted to “acdfv” followed by the sum of integers 4 and 3. Input: str = “ h2d7e3f ” Output: “ defh12” Explanation: all the letters have been sorted to “defh” followed by the sum of integers 2, 7, and 3.Approach to Find the SolutionWe have two tasks to perform in this problem, one is sorting the string, and the other is adding ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
99 Views
Discuss a problem where we are given a ratio of sums of m and n terms of A.P. We need to find the ratio of mth and nth terms.Input: m = 8, n = 4 Output: 2.142 Input: m = 3, n = 2 Output: 1.666 Input: m = 7, n = 3 Output: 2.6Approach to Find the SolutionTo find the ratio of mth and nth terms using code, we need to simplify the formula. Let Sm be the sum of first m terms and Sn be the sum of the first n terms of the A.P.a - ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
239 Views
Given a n*n grid maze. Our rat is present in the top left corner of the grid. Now rats can only move down or forward, and if and only if the block has a non-zero value to it now in this variation rat is allowed to have multiple jumps. The maximum jump that the rat can take from the current cell is the number present in the cell, and now you are tasked to find if the rat can reach the bottom right corner of the grid, for example −Input : { { {1, 1, 1, 1}, {2, 0, 0, ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
211 Views
Sparsh Table is a data structure, which is used to give results of range queries. It provides the result of most range queries in O(logN) complexity. For maximum range queries, it can also compute the result in O(1).This tutorial will discuss the problem of a range sum query using a sparse table where we are given an array. We need to find the sum of all elements in range L and R, for example.Input: arr[ ] = { 2, 4, 1, 5, 6, 3 } query(1, 3), query(0, 2), query(1, 5). Output: 10 7 19 Input: arr[ ] ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
249 Views
Given an array and several queries. Also, there are two types of query, i.e., update[ L, R ] means update elements from L to R with their square roots, and query[ L, R ] means to calculate the sum of elements from L to R.We are assuming a 1-based indexed array, for exampleInput: nums[ ] = { 0, 9, 4, 1, 5, 2, 3 }, Query[ ] = { {1, 1, 3}, {2, 1, 2}, {1, 2, 5}, { 1, 4, 5}} Output: 14 10 7 1st element of 1st query is 1 means we need to calculate range sum ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
155 Views
Discuss a problem to answer queries to the given array. For each query index, we need to find the number of ones and zeros to the left of the index, for example.Input: arr[ ] = { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0}, queries[ ] = { 2, 4, 1, 0, 5 } Output: query 1: zeros = 1, ones = 1 query 2: zeros = 1, ones = 3 query 3: zeros = 1, ones = 0 query 4: zeros = 0, ones = 0 query 5: zeros = 2, ones = 3 Input: arr[ ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
164 Views
To calculate the XOR of all the subarrays present in the given range and print it. For exampleInput : arr[] = { 4, 1, 2, 3, 5 }, Q = 3 Queries q1 = { 1, 2 } q2 = { 2, 4 } q3 = { 1, 4 } Output : 0 2 0 Explanation : As the given problem states that we need to find XOR of all the subarrays present in the given range so as for query 2 the subarrays are : {1}, {2}, {3}, {1, 2}, {2, 3}, (1, 2, 3} So ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
107 Views
Given an array of N integers and Q queries of ranges. For each query, we need to return the XOR of the greatest odd divisor of each number in the range.The greatest odd divisor is the greatest odd number which can divide number N, e.g . The greatest odd divisor of 6 is 3, for example.Input: nums[ ] = { 3, 6, 7, 10 }, query[ ] = { { 0, 2 }, { 1, 3 } } Output: query1: 7 query2: 1 Explanation: greatest odd divisors of nums array are { 3, 3, 7, 5 }. For query ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
328 Views
In the given problem, we are given a string consisting of 0’s and 1’s; we are required to find the total number of permutations such that the string starts with 1’s. As the answer can be a vast number, so we print as a mod with 1000000007.Input : str ="10101001001" Output : 210 Input : str ="101110011" Output : 56We will solve the given problem by applying some combinatorics and building up some formulas to solve this problem.Approach to find The SolutionIn the approach, we will calculate the number of 0's and 1's. Now let's suppose n is the ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
1K+ Views
We require the appropriate knowledge to create several unique pairs in an array syntax in C++. In finding the number of unique pairs, we count all unique pairs in a given array, i.e., all possible pairs can be formed where each pair should be unique. For example −Input : array[ ] = { 5, 5, 9 } Output : 4 Explanation : The number of all unique pairs are (5, 5), (5, 9), (9, 5) and (9, 9). Input : array[ ] = { 5, 4, 3, 2, 2 } Output : 16Approach to find The SolutionThere are Two ... Read More