
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++

940 Views
In this article, we will discuss the problem of rearranging a given array of n numbers. Basically, we have to select elements from the array. For selecting each element, we get some points that will be evaluated by the value of the current element * a number of elements selected before the current element. You should select elements to get maximum points. For Example −Input : arr[ ] = { 3, 1, 5, 6, 3 } If we select the elements in the way it is given, our points will be = 3 * 0 + 1 * ... Read More

794 Views
We are given an array; we need to arrange this array in an order that the first element should be a minimum element, the second element should be a maximum element, the third element should be 2nd minimum element, the fourth element should be the 2nd maximum element and so on for example −Input : arr[ ] = { 13, 34, 30, 56, 78, 3 } Output : { 3, 78, 13, 56, 34, 30 } Explanation : array is rearranged in the order { 1st min, 1st max, 2nd min, 2nd max, 3rd min, 3rd max } Input ... Read More

329 Views
We are given a sorted array. We need to arrange this array in maximum, minimum form, i.e., the first element is the maximum element, the second element is the minimum element, the third element is 2nd maximum element, the fourth element is 2nd minimum element, and so on, for example −Input : arr[ ] = { 10, 20, 30, 40, 50, 60 } Output : { 60, 10, 50, 20, 40, 30 } Explanation : array is rearranged in the form { 1st max, 1st min, 2nd max, 2nd min, 3rd max, 3rd min } Input : arr [ ... Read More

1K+ Views
In the given problem, we need to rank all the given elements of an array, with the smallest number having the smallest rank and the largest having the largest rank. We also need to change the ranks of a number depending on their frequencies, for examples −Input : 20 30 10 Output : 2.0 3.0 1.0 Input : 10 12 15 12 10 25 12 Output : 1.5, 4.0, 6.0, 4.0, 1.5, 7.0, 4.0 Here the rank of 10 is 1.5 because there are two 10s present in the given array now if we assume they both take ... Read More

424 Views
In this article, we will give an array of size n, which will be an integer. Then, we will compute the sum of elements from index L to index R and execute the queries multiple times, or we need to calculate the sum of the given range from [L, R]. For example −Input : arr[] = {1, 2, 3, 4, 5} L = 1, R = 3 L = 2, R = 4 Output : 9 12 Input : arr[] = {1, 2, 3, 4, 5} L = 0, R = 4 L = ... Read More

510 Views
In the given problem, we are required to print all the divisors of a given integer n.Input: 15 Output: 1 3 5 15 Explanation Divisors of 15 are: 1, 3, 5, 15 Input: 30 Output: 1 2 3 5 15 30In the given problem, we can apply the approach used in the sieve of Eratosthenes for finding all the divisors of n.Approach to find The SolutionIn the given approach, we will apply the concept in which the sieve of Eratosthenes is based and find the divisors of n.Example#include #define MOD 1000000007 using namespace std; vector divisors[100001]; ... Read More

312 Views
In this article we will discuss a problem of finding the number of elements present in the given range that have a kth bit set, for example −Input : arr[] = { 4, 5, 7, 2 } Query 1: L = 2, R = 4, K = 4 Query 2: L = 3, R = 5, K = 1 Output : 0 1We are going to solve this problem by a brute force approach and see if this approach can work for higher constraints or not. If not, then we try to think of a new efficient approach.Brute ... Read More

492 Views
In this article, we are given a problem, we are given an array, and there are two types of queries we need to answer.Type 0 − we have to calculate the number of greater elements than or equal to x(given value).Type 1 − we have to calculate the number of strictly greater elements than x(given value).So here is a simple example −Input : arr[] = { 10, 15, 30 , 40, 45 } and Q = 3 Query 1: 0 50 Query 2: 1 40 Query 3: 0 30 Output : 0 1 3 ... Read More

1K+ Views
In this article, we are given an array of integers. We are tasked to find the bitwise OR of all the numbers present in the given range, for example, Input: arr[] = {1, 3, 1, 2, 3, 4}, q[] = {{0, 1}, {3, 5}} Output: 3 7 1 OR 3 = 3 2 OR 3 OR 4 = 7 Input: arr[] = {1, 2, 3, 4, 5}, q[] = {{0, 4}, {1, 3}} Output: 7 7In the given problem, we will approach it with a brute force approach and then check if it can work for higher constraints or not. ... Read More

1K+ Views
In this article, we have given a problem in which we are given an array of integers, and we are tasked to find the bitwise AND of the given ranges, for example 7minus;Input: arr[ ] = {1, 3, 1, 2, 32, 3, 3, 4, 4}, q[ ] = {{0, 1}, {3, 5}} Output: 1 0 0 1 AND 31 = 1 23 AND 34 AND 4 = 00 Input: arr[ ] = {1, 2, 3, 4, 510, 10 , 12, 16, 8}, q[ ] = {{0, 42}, {1, 33, 4}} Output: 0 8 0We are going to apply the brute ... Read More