
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7197 Articles for C++

703 Views
Suppose we have an array called people. Now the i-th person has weight people[i], and each boat can carry a maximum weight of limit. If each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. We have to find the minimum number of boats to carry every given person. So if the input is like [3,2,1,2], and limit is 3, then we need three boats. [(1,2), (2), (3)].To solve this, we will follow these steps −sort the people arrayi := 0, j := size of people array – 1, ret := 0while i

573 Views
Suppose we have two players Alex and Lee they play a game with piles of stones. There are an even number of piles that are arranged in a row, and each pile has some number of stones piles[i]. The objective of the game is to end with the most stones. When the total number of stones is odd, there are no ties. Alex and Lee take turns, with Alex starting first. In each turn, a player takes the entire pile of stones from either the beginning or the end of the row. This will be continued until there are no ... Read More

444 Views
Suppose we have N piles of bananas, the i-th pile has piles[i] bananas. Here the guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed is K. Each hour, she takes some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, then she consumes all of them instead, and won't eat any more bananas during this hour. Consider Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back. We have to find the minimum integer ... Read More

154 Views
Suppose we have a sequence X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 = 3 otherwise return 0.Let us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution { public: int lenLongestFibSubseq(vector & A) { int ret = 0; unordered_map m; int n = A.size(); vector < vector > dp(n, vector (n)); for(int i = 0; i < n; i++){ ... Read More

256 Views
Suppose we have a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is non-zero. We have to check whether we can do this in a way such that the resulting number is a power of 2. So if the number is like 46, then the answer will be true.To solve this, we will follow these steps −Define a method called count, this will take x as inputret := 0while x is not 0ret := ret + 10 ^ last digit of xx := x / 10return retFrom the main ... Read More

1K+ Views
Suppose we have to find the smallest prime palindrome that is greater than or equal to N. So if the N is 13, then the smallest palindrome will be 101.To solve this, we will follow these steps −If N is in range 8 to 11, then return 11for i in range 1 to 99999s := i as a stringr := sreverse rnum := concatenate s and substring of r from index 1, then convert to numberif num >= N and num is prime, then return numreturn 0Let us see the following implementation to get better understanding −Example Live Demo#include using ... Read More

169 Views
Suppose we have a two dimensional matrix A where each value is 0 or 1. Here a move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s. Now after making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. So our task is to find the highest possible score. If the input is like −001110101100The output will be 39 as after toggling, the matrix will ... Read More

239 Views
In this tutorial, we will be discussing a program to understand map equal_range in C++ STL.This function returns a pair of iterators that bounds the range of the container in which the key equivalent to the given parameter resides.Example Live Demo#include using namespace std; int main() { //initializing container map mp; mp.insert({ 4, 30 }); mp.insert({ 1, 40 }); mp.insert({ 6, 60 }); pair it; it = mp.equal_range(1); cout

232 Views
In this tutorial, we will be discussing a program to get maximum of all subarrays of size k using set in C++ STL.For this we will be provided with a array of size N and integer K. Our task is to get the maximum element in each K elements, add them up and print it out.Example Live Demo#include using namespace std; //returning sum of maximum elements int maxOfSubarrays(int arr[], int n, int k){ set q; set::reverse_iterator it; //inserting elements for (int i = 0; i < k; i++) { q.insert(pair(arr[i], i)); } ... Read More

1K+ Views
In this tutorial, we will be discussing a program to create a menu driven program for a simple calculator.This program will give user the ability to choose among the following mathematical operations − addition, subtraction, multiplication, division, HCF and LCM.Example Live Demo#include using namespace std; //displaying the menu void menu(){ cout