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

284 Views
ConceptWith respect of a given an m x m matrix, the problem is to determine all the distinct elements common to all rows of the matrix. So the elements can be displayed in any order.Inputmat[][] = { {13, 2, 15, 4, 17}, {15, 3, 2, 4, 36}, {15, 2, 15, 4, 12}, {15, 26, 4, 3, 2}, {2, 19, 4, 22, 15} }Output2 4 15MethodsFirst Method: Implement three nested loops. Verify if an element of 1st row is present in all the subsequent rows. Here, time Complexity is O(m^3). Additional space could be required to control the duplicate elements.Second Method: ... Read More

184 Views
ConceptWith respect of two given arrays of M integers, assume an array C, where the i-th integer will be d*a[i] + b[i] where d is indicated as any arbitrary real number. Our task is to display or print d such that array C has largest number of zeros and also prints the number of zeros.Inputa[] = {15, 40, 45} b[] = {4, 5, 6}OutputValue of d is: -0.133333 The number of zeros in array C is: 1 If we choose d as -0.133333 then we get one zero in the array C which is the maximum possible.MethodsWe follow the below ... Read More

148 Views
ConceptWith respect of two given two different series arr1[b] and arr2[a] of size b and a. Our task is to determine the mean and variance of combined series.InputArr1[] = { 24, 46, 35, 79, 13, 77, 35 }; Arr2[] = { 66, 68, 35, 24, 46 };OutputMean1: 44.1429 Mean2: 47.8 StandardDeviation1: 548.694 StandardDeviation2: 294.56 Combined Mean: 45.6667 d1 square: 2.322 d2_square: 4.5511 Combined Variance: 446.056MethodNow suppose, n1= No. of observations in 'region 1'n2= No. of observations in 'region 1'X1= mean of region 1.X2=mean of region 2.S1=standard deviation of region 1.S2=standard deviation of region 2.S12 = variance of region 1.S22 = ... Read More

195 Views
ConceptWith respect of a given array of integers, our task is to determine an integer B which isthe divisor of all except for exactly one element in the given array.It should be noted that the GCD of all the elements is not 1.Input arr[] = {8, 16, 4, 24}Output 8 8 is the divisor of all except 4.Input arr[] = {50, 15, 40, 41}Output 5 5 is the divisor of all except 41.MethodWe create a prefix array A such that position or index i contains the GCD of all the elements from 1 to i. In the similar way, create a suffix array C ... Read More

161 Views
Suppose we have an array of words, we have to find any alphabetical order in the English alphabet so that the given words can be considered sorted in ascending order, if there is any such order exists, otherwise return "impossible".So, if the input is like words = ["efgh", "wxyz"], then the output will be zyxvutsrqponmlkjihgfewdcbaTo solve this, we will follow these steps −ALPHABET := 26n := size of vif n is same as 1, then −display "abcdefghijklmnopqrstuvwxyz"returnDefine an array adj of size ALPHABETDefine an array in of size ALPHABET and fill with 0pre := v[0]for initialize i := 1, when ... Read More

644 Views
Suppose we have one undirected graph and a set of vertices; we have to find all reachable nodes from every vertex present in the given set.So, if the input is likethen the output will be [1, 2, 3] and [4, 5] as these are two connected components.To solve this, we will follow these steps −nodes := number of nodes in the graphDefine an array visited of size: nodes+1. And fill with 0Define one map mcomp_sum := 0for initialize i := 0, when i < n, update (increase i by 1), do −u := arr[i]if visited[u] is false, then −(increase comp_sum ... Read More

274 Views
ConceptWith respect of given array Arr[] of non-negative integers, the task is to determine an integer X such that (Arr[0] XOR X) + (Arr[1] XOR X) + … + Arr[n – 1] XOR X is minimum possible.Input Arr[] = {3, 4, 5, 6, 7}Output X = 7, Sum = 10ApproachSo we will verify ‘i’th bit of every number of array in binary representation and consider and count those numbers containing that ‘i’th bit set to ‘1’ because these set bits will contribute to maximize the sum instead of minimize. As a result of this, we have to build this set ‘i’th bit ... Read More

361 Views
Suppose we have an array of n numbers; we have to find a non-empty subset such that the sum of elements of the subset is divisible by n. So, we have to output any such subset with its size and the indices of elements in the original array when it is present.So, if the input is like [3, 2, 7, 1, 9], then the output will be [2], [1 2].To solve this, we will follow these steps −Define one map my_mapadd := 0for initialize i := 0, when i < N, update (increase i by 1), do −add := (add ... Read More

165 Views
Suppose we want to place 1, 2, 3, 4, 5, 6, 7, 8, into the eight circles in the given figure, in this way that no number is adjacent to a number that is next to it in the sequence.So, if the input is like0-1-10-1-1-1-10-1-10then the output will beTo solve this, we will follow these steps −N := 3, M := 4NOTCONSIDERED := -1Define a function present_in_grid(), this will take grid[N][M], num, for initialize i := 0, when i < N, update (increase i by 1), do:for initialize j := 0, when j < M, update (increase j by 1), ... Read More

374 Views
ConceptWith respect of given positive number n, the task is to verify if n is a primorial prime number or not. We have to print ‘YES’ if n is a primorial prime number otherwise print ‘NO.Primorial Prime − With respect of Mathematics, a Primorial prime is defined as a prime number of the form pN# + 1 or pN# – 1 , where pN# is the primorial of pN such that the product of first N prime numbers.Input − n = 7Output − YES7 is Primorial prime of the form pN + 1 for N=2, Primorial is 2*3 = 6 ... Read More