- 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)
247 Views
Suppose we have an array of n integers called nums and we also have a target, we have to find the number of index triplets (i, j, k) here i, j, k all are in range 0 to n - 1 and that satisfy the condition nums[i] + nums[j] + nums[k] < target.So, if the input is like nums = [-2, 0, 1, 3], and target = 2, then the output will be 2, as there are two triplets which sums are less than 2: [-2, 0, 1] and [-2, 0, 3].To solve this, we will follow these steps −ret ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
98 Views
Suppose we have a sequence of numbers; we have to check whether it is the correct preorder traversal sequence of a binary search tree. We can assume that each number in the sequence is unique. Consider the following binary search tree −So, if the input is like [5, 2, 1, 3, 6], then the output will be trueTo solve this, we will follow these steps −itr := -1low := -infinityfor initialize i := 0, when i < size of preorder, update (increase i by 1), do −x := preorder[i]if x < low, then −return falsewhile (itr >= 0 and preorder[itr] ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
198 Views
Suppose we have a number. The numbers can be regarded as a product of its factors. So, 8 = 2 x 2 x 2; = 2 x 4. We have to make one function that takes an integer n and return all possible combinations of its factors.So, if the input is like 12, then the output will be [[2, 6], [2, 2, 3], [3, 4]]To solve this, we will follow these steps −Define a function solve(), this will take n, target, start, define one list of lists called retif n is same as 1, then −return retif n is not ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
843 Views
Suppose there is an array of meeting time intervals. There are two times start and end times [[s1,e1],[s2,e2],...] and each pair satisfies the rule (si < ei), We have to find the minimum number of conference rooms required.So, if the input is like [[0, 30], [5, 10], [15, 20]], then the output will be 2.To solve this, we will follow these steps −define one priority queue pqsort the intervals arrayret := 0for initialize i := 0, when i < size of intervals, update (increase i by 1), do −while (not pq is empty and top element of pq
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
431 Views
Suppose we have a 2D vector, we have to design and implement an iterator to flatten that 2d vector. There will be different methods as follows −next() − This will return the next element of the current elementhasNext() − This will check whether next element is present or notSo, if the input is like [[1, 2], [3], [4]] then if we call the functions as follows −iterator.next();iterator.next();iterator.next();iterator.hasNext();iterator.hasNext();iterator.next();iterator.hasNext();then the output will be [1, 2, 3, true, true, 4, false]To solve this, we will follow these steps −Define one 2D array vDefine initializer this will take one 2D array v, rowPointer := ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
199 Views
Suppose we have a binary tree; we have to count the number of uni-value subtrees. Here the Uni-value subtree indicates all nodes of the subtree have the same value.So, if the input is like root = [5, 1, 5, 5, 5, null, 5], then the output will be 4To solve this, we will follow these steps −Define a function solve(), this will take node, if node is empty, then −return trueleft := solve(left of node)right := solve(right of node)if left is false or right is false, then −return falseif left of node is present and val of node is not ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
116 Views
Suppose we have a string, we can "shift" each of its letter to its successive letter, so: "abc" can be changed to "bcd". We can keep doing this operation which forms the sequence: "abc" -> "bcd" -> ... -> "xyz". If we have a list of non-empty strings that contains only lowercase alphabets, we have to group all strings that belong to the same shifting sequence.So, if the input is like ["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"], then the output will be [ ["abc", "bcd", "xyz"], ["az", "ba"], ["acef"], ["a", "z"] ]To solve this, we will follow these ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
399 Views
Suppose we have a length n. We have to find all strobogrammatic numbers that are of length n.As we know that a strobogrammatic number is a number that looks the same when rotated 180 degrees.So, if the input is like n = 2, then the output will be ["11", "69", "88", "96"]To solve this, we will follow these steps −Define an array retif n is odd, then −insert "0" at the end of retinsert "1" at the end of retinsert "8" at the end of retOtherwiseinsert blank string at the end of retfor n > 1, update n := n ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
141 Views
Suppose we have a list of words and another two words called word1 and word2, we have to find the shortest distance between these two words in the list. Here word1 and word2 may be the same and they represent two individual words in the list. Let us assume that words = ["practice", "makes", "perfect", "skill", "makes"].So, if the input is like word1 = “makes”, word2 = “skill”, then the output will be 1To solve this, we will follow these steps −ret := 10^9, l1 := 10^9, l2 := -10^9n := size of wordsfor initialize i := 0, when i ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
285 Views
Suppose there is a class that receives a list of words in the constructor, there will be a method that takes two words word1 and word2 and find the shortest distance between these two words in the list. That method will be called repeatedly many times with different parameters.Let us assume that words = ["practice", "makes", "perfect", "skill", "makes"].So, if the input is like word1 = “skill”, word2 = “practice”, then the output will be 3To solve this, we will follow these steps −Define one map mThe initializer takes an array of wordsfor initialize i := 0, when i < ... Read More