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

253 Views
Suppose we have three integers a, b and c. Suppose in an infinite sequence, a is the first term, and c is a common difference. We have to check whether b is present in the sequence or not. Suppose the values are like a = 1, b = 7 and c = 3, Then the sequence will be 1, 4, 7, 10, …, so 7 is present in the sequence, so the output will be ‘yes’.To solve this problem, we have to follow these two steps −When c = 0, and a = b, then print yes, and if a ... Read More

346 Views
Consider we have an expression exp, and we have to check whether the exp has a duplicate set of parentheses around it or not. An expression will have duplicate parentheses if one sub-expression will be surrounded by more than one parentheses set. For example, if the expression is like −(5+((7−3)))Here the sub-expression (7 – 3) is surrounded by two parentheses pair, so these are duplicate parentheses.To solve this problem, we will use stacks. We will iterate through each character in the exp, and if the character is opening parentheses ‘(’, or any of the operator or operand, then push it ... Read More

191 Views
Suppose we have a string s, and another array of strings A. We have to find whether the array is containing a string with the one-character difference from the current string of different lengths. Suppose the string is like “banana”, and the array looks like [“bana”, “orange”, “banaba”, “banapy”], the result will be true, as there is one string banaba, here only one character is different than a banana.To solve this problem, we will follow some steps −Traverse through given string s, and check for every string in the array, then follow these steps for every string in arr −Check ... Read More

83 Views
We have to find the GCD of two numbers of which one number can be as big as (109 ^ 109), which cannot be stored in some data types like long or any other. So if the numbers are a = 10248585, n = 1000000, b = 12564, then result of GCD(a^n, b) will be 9.As the numbers are very long, we cannot use the Euclidean algorithm. We have to use the modular exponentiation with O(log n) complexity.Example Live Demo#include #include using namespace std; long long power(long long a, long long n, long long b) { long long res = ... Read More

330 Views
Suppose we have an array of integers. The array is A, and the size is n. Our task is to find the frequency of all elements in the array less than O(n) time. The size of the elements must be less than one value say M. Here we will use the binary search approach. Here we will recursively divide the array into two parts if the end elements are different, if both its end elements are the same, it means all elements in the array are the same as the array is already sorted.Example Live Demo#include #include using namespace std; void ... Read More

820 Views
Suppose we have a list of integers. Our task is to find four distinct integers as two pairs like (a, b) and (c, d), such that a+b = c+d. If there are multiple answers, then print only one. Suppose the array elements are like: A = [7, 5, 9, 3, 6, 4, 2], then pairs can be (7, 3) and (6, 4)Here we will use the hashing technique. We use the sum as key as pair as the value in the hash table. We have to follow these steps to solve this problem.For i in range 0 to n – ... Read More

403 Views
Suppose we have three sorted arrays A, B and C, and three elements i, j and k from A, B and C respectively such that max(|A[i] – B[i]|, |B[j] – C[k]|, |C[k] – A[i]|) is minimized. So if A = [1, 4, 10], B = [2, 15, 20], and C = [10, 12], then output elements are 10, 15, 10, these three from A, B and C.Suppose the size of A, B and C are p, q and r respectively. Now follow these steps to solve this −i := 0, j := 0 and k := 0Now do the following ... Read More

145 Views
Consider we have an array with size n. This array is sorted. There is one element whose frequency is greater than or equal to n/2, where n is the number of elements in the array. So if the array is like [3, 4, 5, 5, 5], then the output will be 5.If we closely observe these type of array, we can easily notice that the number whose frequency is greater than or equal to n/2, will be present at index n/2 also. So the element can be found at position n/2Example Live DemoSource Code: #include using namespace std; int higherFreq(int arr[], ... Read More

1K+ Views
Suppose, we have an integer N, We have to find the sum of the odd place digits and the even place digits. So if the number is like 153654, then odd_sum = 9, and even_sum = 15.To solve this, we can extract all digits from last digit, if the original number has odd number of digits, then the last digit must be odd positioned, else it will be even positioned. After process a digit, we can invert the state from odd to even and vice versa.Example Live Demo#include using namespace std; bool isOdd(int x){ if(x % 2 == 0) ... Read More

138 Views
Suppose we have a list of numbers from 0 to n-1. A number can be repeated as many as a possible number of times. We have to find the repeating numbers without taking any extra space. If the value of n = 7, and list is like [5, 2, 3, 5, 1, 6, 2, 3, 4, 5]. The answer will be 5, 2, 3.To solve this, we have to follow these steps −for each element e in the list, do the following steps −sign := A[absolute value of e]if the sign is positive, then make it negativeOtherwise, it is a ... Read More