- 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++
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
260 Views
Suppose we have two numbers m and d. Consider a calendar where week days are represented as columns and rows are current days. We want to know how many columns in the calendar should have given the month m and the weekday of the first date of that month d (Assuming that the year is not leap-year).So, if the input is like m = 11; d = 6, then the output will be 5, because 1-st November is Saturday and 5 columns is enough.StepsTo solve this, we will follow these steps −Define an array a of size: 13 := { ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
113 Views
Suppose we have an array A with n elements, the elements are in range -1 to 1. And have another array of pairs for m queries Q like Q[i] = (li, ri). The response to the query will be 1 when the elements of array a can be rearranged so as the sum Q[li] + ... + Q[ri] = 0, otherwise 0. We have to find answers of all queries.So, if the input is like A = [-1, 1, 1, 1, -1]; Q = [[1, 1], [2, 3], [3, 5], [2, 5], [1, 5]], then the output will be [0, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
218 Views
Suppose we have two numbers n and h, and another array of m triplets T, where T[i] = (li, ri, xi). On a road, there are n places where we can make houses. The spots are numbered as 1 to n. The house height can be from 0 to h. In each spot if we make a house of height k, we will gain k^2 amount of money from it. There are m zone restrictions. The ith restriction says: The tallest house from spots li to ri, must be at most xi. We want to make houses to maximize our ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
175 Views
Suppose we have one n x n matrix. The matrix is said to be a good matrix where every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. We have to check whether given matrix is good or not.So, if the input is like112231641Then the output will be True, because the 6 in the bottom left corner is valid because when the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
180 Views
Suppose we have an array A with n elements and have another number s. There is one empty water mug and n non-empty water mugs on the table. In a game, there are few players. In each move, a player takes a non-empty mug of water and pours all water from it into the cup. If it overfills, the player will lost. We have to check whether all of them will be winner or not (the cup will not overfill). If one up is already filled completely, the next player will not play his/her move. Here s is the capacity ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
315 Views
Suppose we have a number p and another array X with n elements. There is a hash table with p buckets. The buckets are numbered from 0 to p-1. We want to insert n numbers from X. We are assuming for X[i], its bucket will be selected by the hash function h(X[i]), where h(k) = k mod p. One bucket cannot hold more than one element. If We want to insert an number into a bucket which is already filled, we say a "collision" happens. We have to return the index where collision has happened. If there is no collision, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
152 Views
Suppose we have an array A with n elements, and another number d. According to the regulations of Dreamland's army, a reconnaissance unit should have exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. There are n soldiers whose heights are stored in the array A. Some soldiers are of the same height. We have to find how many ways exist to form a reconnaissance unit from these n soldiers.So, if the input is like A = [10, 20, 50, 60, 65]; d = 10, then the output will be ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
277 Views
Suppose we have a 3 x 3 matrix with 'X' and '.'. We have to check whether the pattern is centersymmetrical or not. (More on center symmetry − http://en.wikipedia.org/wiki/Central_symmetry)So, if the input is likeXX.....XXthen the output will be True.StepsTo solve this, we will follow these steps −if M[0, 0] is same as M[2, 2] and M[0, 1] is same as M[2, 1] and M[0, 2] is same as M[2, 0] and M[1, 0] is same as M[1, 2], then: return true Otherwise return falseExampleLet us see the following implementation to get better understanding −#include using namespace std; ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
158 Views
Suppose we have a string S with n characters. S is a single-space separated words, consisting of small and capital English letters. Volume of the word is number of capital letters in the given word. And volume of the text is maximum volume of all words in the text. We have to find the volume of the given text.So, if the input is like S = "Paper MILL", then the output will be 4, because volume of first word is 1 and second word is 4, so maximum is 4.StepsTo solve this, we will follow these steps −ans := 0 ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
125 Views
Suppose we have a number n. We can split n as a nonincreasing sequence of positive integers, whose sum is n. The weight of a split is the number of elements in the split that are equal to the first element. So, the weight of the split [1, 1, 1, 1, 1] is 5, the weight of the split [5, 5, 3, 3, 3] is 2 and the weight of the split [9] equals 1. We have to find out the number of different weights of n's splits.So, if the input is like n = 7, then the output will ... Read More