 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
C++ Articles - Page 315 of 719
 
 
			
			383 Views
In this problem, we are given an arr[] and Q queries each consisting of a value m. Our task is to create a program to solve the Queries for counts of multiples in an array in C++.Problem DescriptionFor solving the queries, we need to count all the numbers that are multiples of m. For this we will check for elements divisible by m.Let’s take an example to understand the problem, Input:arr[] = {4, 7, 3, 8, 12, 15}Q = 3 query[] = {2, 3, 5}Ouput:3 3 1ExplanationQuery 1: m = 2, multiples in the array = 4, 8, 12. Count ... Read More
 
 
			
			176 Views
In this problem, we are given a number N. Our task is to find the sum of first N natural numbers which are divisible by 2 and 7.So, here we will be given a number N, the program will find the sum of numbers between 1 to N that is divisible by 2 and 7.Let’s take an example to understand the problem, Input −N = 10Output −37Explanation −sum = 2 + 4 + 6 + 7 + 8 + 10 = 37So, the basic idea to solve the problem is to find all the numbers that are divisible by 2 ... Read More
 
 
			
			281 Views
In this problem, we are given a set S of n number. Our task is to create a program to find the sum of subset difference which is the difference of last and first elements of subset.The formula is, sumSubsetDifference = Σ [last(s) - first(s)] s are subsets of the set S.Let’s take an example to understand the problem, Input −S = {1, 2, 9} n = 3Output −Explanation − All subset are −{1}, last(s) - first(s) = 0 {2}, last(s) - first(s) = 0 {9}, last(s) - first(s) = 0 {1, 2}, last(s) - first(s) = 1 {1, 9}, last(s) ... Read More
 
 
			
			252 Views
In this problem, we are given string str. Our task is to create a program to find the sum of similarities of the string with all of its suffixes.Suffixes of string str are all the strings that are created by eliminating starting characters of the string.Similarities of string str1 and str2 is the length of the longest prefix common to both the string. For example, str1 = ‘abbac’ and str2 = ‘abb’ is 3.While str1 = ‘abca’ and str2 = ‘ca’ is 0. As we count from start.Let’s take an example to understand the problem, Input − str = ‘xyxyx’Output ... Read More
 
 
			
			472 Views
In this problem, we are given a number n of the series. Our task is to find the sum of series 1^2 + 3^2 + 5^2 +... + (2*n - 1)^2 for the given value of n.Let’s take an example to understand the problem,Input −n = 5Output −84Explanation −sum = 1^2 + 3^2 + 5^2 + 7^2 + 9^2 = 1 + 9 + 25 + 49 = 84A basic approach to solve this problem is by directly applying the formula for the sum of series.Example Live Demo#include using namespace std; int calcSumOfSeries(int n) { int sum = 0; for (int i = 1; i
 
 
			
			206 Views
In this problem, we are given 3 array X, Y, Z. Our task is to create a program to find the Sum of special triplets having elements from 3 arrays.Special Triplet is a special type of triplet that hold the following property −For (a, b, c): a ≤ b and b ≥ c, i.e the middle element of the triplet should be greeter that the other two.And, the value of the triplet is given by the formula −f(a, b, c) = (a+b) * (b+c)To create this triplet we need to use one element from each other the three arrays given.Let’s ... Read More
 
 
			
			143 Views
In this problem, we are given a linked list with a node consisting of two values and a pointer. Our task is to create a program to find the sum of smaller elements of a node in a linked list.Here, in the linked list we have two elements say X and Y. The program will find a minimum of x and y. The minimum elements from all nodes are added which is the required result.Input −(5, 2)->(7, 9)->(6, 3)->(36, 24)->(19, 26)->nullOutput −55Explanation −Let’s take the minimum of X and Y from each node −node1 - mini = 5 node2 - ... Read More
 
 
			
			1K+ Views
The block swap algorithm for array rotation is an efficient algorithm that is used for array rotation. It can do your work in O(n) time complexity.So, in array rotation, we are given an array arr[] of size n and a number k that define the no. of the element to be rotated.Let’s see an example on array rotations −Input −arr[] = {4, 6, 1, 8, 9, 2}, k = 2 (number of rotations.)Output −{1, 8, 9, 2, 4, 6}Explanation − On rotation, we will shift the one element to the last position and shift the next elements to one position.Element ... Read More
 
 
			
			362 Views
BK tree or Burkhard tree is a form of a data structure usually used to perform spell checks based on Levenshtein distance. It is also used for string matching Autocorrect feature can be used making this data structure. Let's say we have some words in a dictionary and we need to check some other words for spelling errors. We need to have a collection of words that is close to the given word whose spelling is to be checked. For example, if we have the word “uck” The correct word can be (truck, duck, duck, suck). Therefore spelling mistakes can ... Read More
 
 
			
			847 Views
In this problem, we are given a number N. Our task is to find all prime numbers smaller than N using Bitwise Sieve.Bitwise sieve is an optimized version of Sieve of Eratosthenes which is used to find all prime numbers smaller than the given number.Let’s take an example to understand the problem, Input − N = 25Output − 2 3 5 7 11 13 17 19 23The bitwise sieve works in the same ways as the normal sieve. It just we will use the bits of integers of represent primes instead of a boolean type. This will reduce the space ... Read More