- 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++
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
747 Views
In this problem, we are given two integers N and M, N is the number of people in group 1, and M is the number of people in group 2. Our task is to create a program to find the maximum number of 3-person teams formed from two groups.We will be creating teams of 3 people by selecting a person from these groups such that the maximum teams can be made. Each team must have at least one person from each group.Let’s take an example to understand the problem, Input − N = 5, M = 3Output − 2Explanation −The ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
456 Views
In this problem, we are given an array, are of n elements. Our task is to create a program to find the maximum modulo of all pairs of array where arr[i] >= arr[j].Here, we have to find the maximum value of arr[i] % arr[j] where arr[i] >= arr[j].Let’s take an example to understand the problem, Input − arr[] = {3, 5, 9}Output − 4Explanation −All possible Pairs arr[i] and arr[j], 5, 3 => 5%3 = 2 9, 3 => 9%3 = 0 9, 5 => 9%5 = 4To solve this problem, a simple and direct approach will be run two ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
250 Views
In this problem, we are given an array of characters. Our task is to create a program to print the maximum length of the subarray whose first and last elements are same in C++.Let’s take an example to understand the problem, Input − array = {‘t’, ‘u’, ‘t’, ‘o’, ‘r’, ‘i’, ‘a’, ‘l’, ‘s’, ‘p’, ‘o’, ‘i’, ‘n’, ‘t’ }Output − 14Explanation −The subarray {‘t’, ‘u’, ‘t’, ‘o’, ‘r’, ‘i’, ‘a’, ‘l’, ‘s’, ‘p’, ‘o’, ‘i’, ‘n’, ‘t’ } starts and ends with t.To solve this problem, we find the first and last occurrence a character in the array and ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
167 Views
Problem statementGiven a string comprising of ones and zeros. The task is to find the maximum length of the segments of string such that a number of 1 in each segment is greater than 0ExampleIf input string is “10111000001011” the answer will 12 as follows −First segment is of length 7 10111000001011Second segment is of length 5 10111000001011Total length is length of (segment 1 + segment 2) = (7 + 5) = 12AlgorithmIf start == n then return 0.Run a loop from start till n, computing for each subarray till n.If character is 1 then increment the count of 1 ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
108 Views
Problem statementGiven lengths of n rods in an array. If any person picks any rod, half of the longest rod (or (max + 1) / 2 ) is assigned and remaining part (max – 1) / 2 is put back. It may be assumed that sufficient number of rods are always available, answer M queries given in an array q[] to find the largest length of rod available for qith person, provided qi is a valid person number starting from 1ExampleInput : a[] = {6, 5, 9, 10, 12} q[] = {1, 3} Output : 12 9 The first ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
68 Views
Problem statementGiven an array arr[] of N elements (0 ≤ arr[i] ≤ 1000). The task is to find the maximum length of the sub-array that contains only ugly numbers.Ugly numbers are numbers whose only prime factors are 2, 3 or 5.For Example below are the few number from series: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …ExampleIf input array is {1, 2, 7, 9, 120, 810, 374} then answer is 3 as −Longest possible sub-array of ugly number sis {9, 120, 810}AlgorithmTake a unordered_set, and insert all the ugly numbers which are less than 1000 in ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
71 Views
Problem statementGiven an array, we need to find the maximum height of the triangle which we can form, from the array values such that every (i+1)th level contain more elements with the larger sum from the previous level.ExampleIf input array is {40, 100, 20, 30 } then answer is 2 as −We can have 100 and 20 at the bottom level and either 40 or 30 at the upper level of the pyramidAlgorithmOur solution just lies on the logic that if we have maximum height h possible for our pyramid then ( h * (h + 1) ) / 2 ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
420 Views
Problem statementThere are N players which are playing a tournament. We need to find the maximum number of games the winner can play. In this tournament, two players are allowed to play against each other only if the difference between games played by them is not more than oneExampleIf There are 3 players then 2 games are required to decide the winner as follows −Game – 1: player 1 vs player 2Game - 2: player 2 vs winner from Game - 1AlgorithmWe can solve this problem by first computing minimum number of players required such that the winner will play ... Read More
![Narendra Kumar](https://www.tutorialspoint.com/articles/images/user_icon.png)
99 Views
Problem statementGiven a string the task is to find the maximum length of the sub-string of that can be arranged into a Palindrome.ExampleIf input string = “5432112356” then answer is 6 as maximum palindrome substring is “321123” and its length is 6AlgorithmIf the length of the sub-string is odd, then it cannot be considered in the final solutions.If the length of the sub-string is even, then it can be a possible solution only if each character in that sub-string occurs even number of times which can be done using the dictionary count. We check if each character occurs even number ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
293 Views
In programming data type denotes the type and nature of data which is intended to be use by the user. It is the data type which compiler or interpreter going to deal with and provides corresponding storing location in main memory.Now on the basis of nature of data Data type is mainly of two types one is Fundamental Data type and other is Derived Data type. Both these data types are used in programming and are equally important when need to implement the business logic over the data.Following are the important differences between Fundamental data types and Derived data typesSr. ... Read More