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

149 Views
Suppose we have a string. We have to minimize the sum of ASCII values, of each character to the string, after removing every occurrence of a particular character. Suppose a string is given like “hello” the sum of ASCII characters is (104 + 101 + 108 + 108 + 111) = 532. Now check occurrences of each characters.h has occurred one time, so cost is 1 * 104 = 104e has occurred one time, so cost is 1 * 101 = 101l has occurred one time, so cost is 2 * 108 = 216o has occurred one time, so cost ... Read More

389 Views
Consider we have an array of size n, we have to find the Median and Mode using the counting sort technique. This technique is useful, when the array elements are in limited range. Suppose the elements are {1, 1, 1, 2, 7, 1}, then the Mode is 1, and Median is 1.5. Let us see what is Median and what is Mode −Median is the middle number in a sorted list of numbersMode is the element whose occurrences are maximum in the listTo get the Median and Mode, we have to follow these steps −Assume that the size of the ... Read More

1K+ Views
In this article, we have an array of integers. Our task is to find the maximum sum of a sub-array using divide and conquer algorithm. A sub-array is a continuous part of an array with consecutive array elements. For example: {2, 3, 4} is sub-array of {1, 2, 3, 4, 5} but {1, 4, 5} is not. What is Divide and Conquer Algorithm? The Divide and Conquer algorithm divides a problem into smaller sub-problems, and then each sub-problem is solved independently. We keep dividing the sub-problems till we reach a stage where no more division ... Read More

229 Views
Suppose we have a complete graph; we have to count number of Edge Disjoint Spanning trees. The Edge Disjoint Spanning trees are spanning trees, where no two trees in the set have an edge in common. Suppose the N (number of vertices) is 4, then output will be 2. The complete graph using 4 vertices is like below −Two edge disjoint spanning trees are like −The maximum number of edge disjoint spanning tree from a complete graph, with N vertices will be $[\frac{n}{2}]$Example#include #include using namespace std; int maxEdgeDisjointSpanningTree(int n){ return floor(n/2); } int main() { int n = 4; cout

898 Views
Suppose we have two different arrays. We have to sort one array based on the other array using C++ STL pair class. Consider two arrays are like A1 = [2, 1, 5, 4, 9, 3, 6, 7, 10, 8], and another array is like A2 = [A, B, C, D, E, F, G, H, I, J], The output will be like: A1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], A2 = [B, A, F, D, C, G, H, J, E, I]Here we are using the pairs of C++ STL. The pair is formed by taking one ... Read More

372 Views
Suppose we have an array of strings, and another string is there for the reference. We have to take the reference string and using the order of the characters in the reference string we will sort the string array. Here we are considering the strings in the array, and the reference string is in lower case letters.Suppose the string array is like: [“hello”, “programming”, “science”, “computer”, “india”], the reference string is like: “pigvxbskyhqzelutoacfjrndmw”, After sorting the output string will be like [“programming”, “india”, “science”, “hello”, “computer”]The task is simple. We have to traverse the reference string, then store the character ... Read More

151 Views
Suppose we have an array A, and another integer K. We have to sort the elements that are in between any two multiples of K. Suppose A is like [2, 13, 3, 1, 21, 7, 8, 13, 12], and K = 2. The output will be [2, 1, 3, 7, 13, 21, 8, 13, 12]. Here multiple of 2 are 2, 8 and 12, the elements in between 2 and 8 are 13, 3, 1, 21, 7, they will be sorted as 1, 3, 7, 13, 21, the elements between 8 and 12 is only 13, so that is already ... Read More

234 Views
Here we will see one problem, that can tell that whether a string or a number is a concatenation of 1, 14 or 144 only. Suppose a string is “111411441”, this is valid, but “144414” is not valid.The task is simple, we have to fetch a single digit, double-digit and triple-digit number from the last, and check whether they match with any of these three (1, 14 and 144), if we get one match, divide the number with it, and repeat this process until the entire number is not exhausted.Example#include #include using namespace std; bool checkNumber(long long number) ... Read More

190 Views
Here we will see one program, that can check whether a number is divisible by 41 or not. Suppose a number 104413920565933 is given. This is divisible by 41.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timesubtract 4 * (last digit of the number calculated previous) to the truncated numberRepeat these steps as long as necessary.30873, so 3087 - 4*3 = 3075 3075, so 307 - 4 * 5 = 287 287, so 28 – 4 * 7 = 0 So, 30873 is divisible by 41.Example Live Demo#include #include ... Read More

217 Views
Here we will see one program, that can check whether a number is divisible by 23 or not. Suppose a number 1191216 is given. This is divisible by 23.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timeadd 7 * (last digit of the number calculated previous) to the truncated numberRepeat these steps as long as necessary.17043, so 1704 + 7*3 = 1725 1725, so 172 + 7 * 5 = 207 207, this is 9 * 23, so 17043 is divisible by 23.Example Live Demo#include #include using namespace ... Read More