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

134 Views
In this problem, we are given an array arr[] of size N and an integer value M. Our task is to find the position of the last removed element from the array.The removal of values from the array is based on the operations −For an element in the array arr[i]. If arr[i] > M, pop the value and push arr[i] - M to the end of the array. Otherwise remove it from the array.Perform the operations till the array consists of elements.Let’s take an example to understand the problem, Inputarr[] = {5, 4, 8}, M = 3Output3ExplanationRemoving values using operations, ... Read More

268 Views
In this problem, we are given two arrays arr1[] and arr2[] consisting of unique values. Our task is to find the overlapping sum of two arrays.All elements of the arrays are distinct. And we need to return the sum of elements which are common for both arraysLet’s take an example to understand the problem, Inputarr1[] = {5, 4, 9, 2}, arr2[] = {6, 3, 9, 4}Output2ExplanationThe elements that are present in both arrays are 9 and 4. The sum is 9 + 9 + 4 + 4 = 26Solution ApproachA simple solution to the problem is traversing one array say ... Read More

200 Views
In this problem, we are given the coordinates of two points of a line starting point A(xA, yA) and midpoint M(xM, yM) .Our task is to find the other end point of a line with given one end and mid.Let’s take an example to understand the problem, InputA = [1, 2], M = [3, 0]Output[5, -2]ExplanationThe line is −Solution ApproachTo solve the problem, we will be using the concepts of geometry we have learned in mathematics. If you remember there is a midpoint formula for every line which is, mid(x) = (x1 + x2) / 2 mid(y) = (y1 + ... Read More

206 Views
In this problem, we are given an unordered array arr[] of size N containing values from 1 to N-1 with one value occuring twice in the array. Our task is to find the only repetitive element between 1 to n-1.Let’s take an example to understand the problem, Inputarr[] = {3, 5, 4, 1, 2, 1}Output1Solution ApproachA simple solution to the problem is traversing the array and for each value find whether the element exists somewhere else in the array. Return the value with double occurrence.Example 1Program to illustrate the working of our solution#include using namespace std; int findRepValArr(int arr[], ... Read More

333 Views
In this problem, we are given an arr[] of size N containing values from 1 to N-1 with one value occuring twice in the array. Our task is to find the only repeating element in a sorted array of size n.Let’s take an example to understand the problem, Inputarr[] = {1, 2, 3, 4, 5, 5, 6, 7}Output5Solution ApproachA simple approach to solve the problem is by using linear search and checking if arr[i] and arr[i+1] have the same value. In this case, return arr[i] which is the value repeated.Example 1Program to illustrate the working of our solution#include using ... Read More

2K+ Views
In this problem, we are given an arr[] of size N containing values from 1 to N with one value missing in the array. Our task is to find the only missing number in a sorted array.Let’s take an example to understand the problem, Inputarr[] = {1, 2, 3, 5, 6, 7}Output4Solution ApproachA simple solution to the problem is by traversing the sorted array linearly. And then check for the missing value using the fact that arr[i] = (i + 1).Example 1Program to illustrate the working of our solution#include using namespace std; int findMissingValArray(int arr[], int N){ for(int ... Read More

152 Views
In this problem, we are given an arr[] of size n and two integers a and b. Our task is to find the only element that appears b times.All values of the array occur a time except one value which occurs b times in the array and we need to find that value.Let’s take an example to understand the problem, Inputarr[] = {3, 3, 3, 3, 5, 5, 5, 1, 1, 1, 1} a = 4, b = 3Output5Solution ApproachA simple solution to the problem is by counting the occurrence of each element and then storing it in a 2D ... Read More

240 Views
In this problem, we are given an arr[] of size n. Our task is to find the only different element in an array.There are only two different types of elements in the array. All the elements are the same except one.Let’s take an example to understand the problem, Inputarr[] = {1, 1, 1, 2, 1, 1, 1, 1}Output2Solution ApproachA simple approach to solve the problem, we need to traverse the array and find elements which are different from other elements of the array. This approach needs a time complexity of O(N2).Another approach to solve the problem in O(N) is by ... Read More

571 Views
In this problem, we are given an arr[] of size n. Our task is to find the one missing number in range.The array consists of all values ranging from smallest value to (smallest + n). One element of the range is missing from the array. And we need to find this missing value.Let’s take an example to understand the problem, Inputarr[] = {4, 8, 5, 7}Output6Solution ApproachA simple solution to the problem is by searching the missing element by sorting the array and then finding the first element of range starting from minimum value which is not present in the ... Read More

6K+ Views
In this problem, we are given an input string of lowercase characters. Our task is to maximum occurring character in an input string.In case of multiple values with the same frequency of occurrence, we need to print lexicographically smaller values.Let’s take an example to understand the problem, Inputstring = “programming”OutputgSolution ApproachTo find the solution to the problem, we need to sort the read string and then traverse the string so that we could find the character which has maximum occurrence in the string. We would use hashing method (hash table method) to conquer this problem. Traversing and hashing the each ... Read More