- 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)
446 Views
Suppose we have a list of lists of integers intervals where each element has interval like [start, end]. We have to find the most frequently occurred number in the intervals. If there are ties, then return the smallest number.So, if the input is like [[2, 5], [4, 6], [7, 10], [8, 10]], then the output will be 4To solve this, we will follow these steps −Define one map mcnt := 0, val := 0for each value it in x −(increase m[it[0]] by 1)decrease m[it[1] + 1] by 1last := 0for each key it in mlast := last + value of ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
220 Views
Suppose we have one number n. Here n indicates n full beer bottles. If we can exchange 3 empty beer bottles for 1 full beer bottle, we have to find the number of beer bottles we can drink.So, if the input is like 10, then the output will be 14.To solve this, we will follow these steps −Define a function solve(), this will take n, ret := 0while n >= 3, do −q := n / 3ret := ret + q * 3n := n - q * 3n := n + qret := ret + nreturn retLet us see ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
583 Views
Suppose we have a list of integers nums, we have to sort the list in this manner −First element is maximumSecond element is minimumThird element is 2nd maximumFourth element is 2nd minimumAnd so on.So, if the input is like [6,3,10,4], then the output will be [10, 3, 6, 4]To solve this, we will follow these steps −Define an array retsort the array numsj := size of nums - 1i := 0while i
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
166 Views
Suppose we have a list of unique integers called nums. We have to find the number of integers that could still be successfully found using a standard binary search.So, if the input is like [2,6,4,3,10], then the output will be 3, as if we use binary search to look for 4, we can find it at first iteration. We can also find 2 and 10 after two iterations.To solve this, we will follow these steps −Define a function help(), this will take target, an array & nums,low := 0high := size of nums - 1while low
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
157 Views
Suppose we have a non-negative integer called num, we have to check whether it is a palindrome or not, but not using a string.So, if the input is like 1331, then the output will be true.To solve this, we will follow these steps −ret := 0x := numwhile num > 0, do −d := num mod 10ret := ret * 10ret := ret + dnum := num / 10return true when x is same as retLet us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution { public: bool solve(int num) ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
210 Views
Suppose we have one binary matrix. We have to find the maximum number of 1s we can get if we flip a row and then flip a column.So, if the input is like101010100then the output will be 8To solve this, we will follow these steps −n := size of rows in matrixm := size of columns in matrixret := 0Define an array row of size nDefine an array col of size ntotal := 0for initialize i := 0, when i < n, update (increase i by 1), do −for initialize j := 0, when j < m, update (increase j ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
601 Views
Suppose we have a string s where each character is either "L", "R" or "?". "L" means moved one unit left, "R" means moved one unit right, and "?" means either "L" or "R". If we are at position 0, we have to find the maximum possible distance we could be from 0 by replacing "?" with "L" or "R".So, if the input is like "LLRRL??", then the output will be 3, replace ? using L to move 5 units left and 2 units right, so maximum displacement is 3.To solve this, we will follow these steps −op := 0, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
262 Views
Suppose we have one integer array called nums and this contains 0s and 1s. Suppose we have an operation where we pick an index i in nums and flip element at index i as well as all numbers to the right of i. We have to find the minimum number of operations required to make nums contain all 0s.So, if the input is like [1, 0, 1], then the output will be 3, operation on index 0, it will convert [0, 1, 0], then on index 1 [0, 0, 1], then index 2, [0, 0, 0].To solve this, we will ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
788 Views
Suppose we have a list of integers called nums, we have to find whether we can partition the list into two sublists (non-empty) such that every number in the left part is strictly less than every number in the right part.So, if the input is like [6, 4, 3, 8, 10], then the output will be true, as left = [6, 4, 3] and right = [8, 10]To solve this, we will follow these steps −n := size of numsDefine an array right of size nDefine an array left of size nleft[0] := nums[0]last element of right := last element ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
334 Views
Suppose we have a two-dimensional list of intervals where each interval has two values [start, end]. We have to find whether there's an interval which contains another interval.So, if the input is like [[2, 4], [5, 11], [5, 9], [10, 10]], then the output will be true as [5, 11] is containing [5, 9].To solve this, we will follow these steps −sort the array vDefine one 2D array retfor each interval it in v −if ret is empty, then −insert it at the end of retotherwise when last element of ret >= it[0], then −return trueOtherwiseinsert it at the end ... Read More