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

405 Views
Given an array of numbers and an integer x as input. The goal is to find all the subsets of arr[] such that individual elements of that set as well as the sum of them fully divisible by x.For ExampleInputarr[] = {1, 2, 3, 4, 5, 6} x=3OutputCount of subsets that satisfy the given condition :3ExplanationThe subsets will be: [3], [6], [3, 6]Inputarr[] = {1, 2, 3, 4, 5, 6} x=4OutputCount of subsets that satisfy the given condition :1ExplanationThe subsets will be: [4]Approach used in the below program is as follows −In this approach we will count the elements of ... Read More

295 Views
Given two strings numo and demo as input. The goal is to find the number of common divisors of both the strings. The divisors of a string are found using following technique: If string str has sub1 as its divisor then we can construct str using sub1 by repeating it any number of times till str is generated. Example: str=abcabcabc sub1=abcFor ExampleInputnumo = "abababab" demo = "abababababababab"OutputCount of number of common divisors of the given strings are: 2ExplanationThe strings can be generated using following divisor substrings : “ab”, “abab”Inputnumo = "pqqppqqp" demo = "pqpq"OutputCount of number of common divisors of ... Read More

501 Views
Given vertices of a forest ( collection of trees). The goal is to find the number of trees in that forest. We will do this by running a DFS (depth first search) algorithm on the forest.For ExampleInputedges = { { 1, 3 }, {2, 8}, {2, 6}, {3, 5}, {3, 7}, {4, 8} }OutputCount of number of trees in a forest are: 3ExplanationThe number of trees that are present in the forest are −Approach used in the below program is as follows −In this approach we apply Depth First search algorithm on the graph recursively. We will increment count if ... Read More

589 Views
Given an array arr[ ] containing integers only and an odd number sum. The goal is to create a sum array arr_2[ ] such each arr_2[i] is the sum of previous sum/2 elements of arr[] + arr[i] + next sum/2 elements of arr[]. If sum is 1 then arr_2[i]=arr[i]For ExampleInputarr[] = { 4, 1, 7, 5, 2, 9} sum=3OutputConstruction of sum-array with sum of elements in given range are: 5 12 13 14 16 17 17 9 3ExplanationThe sum array is constructed as: arr_2[0]=arr[0]+arr[1] = 4+1 = 5 arr_2[1]=arr[0]+arr[1]+arr[2] = 4+1+7 = 12 arr_2[2]=arr[1]+arr[2]+arr[3] = 1+7+5 = 13 arr_2[3]=arr[2]+arr[3]+arr[4] = ... Read More

691 Views
Given an amount in rupees that one has to pay, say pay_rupees and an unlimited amount of banknotes that have value as Rupees_amount_1 and Rupees_amount_2. The goal is to pay pay_rupees using exactly the total number of notes=distribution_total and count the number of type Rupees_amount_1 notes required. If there is no solution to pay then return −1 as answer.For ExampleInputRupees_amount_1 = 1, Rupees_amount_2 = 5, pay_Rupees = 11 distribution_total = 7OutputCount of number of currency notes needed are − 6Explanation6*1 + 5*1 = 11 and notes=6+1=7InputRupees_amount_1 = 2, Rupees_amount_2 = 3, pay_Rupees = 10 distribution_total = 4OutputCount of number of ... Read More

380 Views
Given three numbers R, G and B and letters ‘R’, ‘G’ and ‘B’ only. The goal is to find the count of possible strings that can be made using at least R Rs, at least G Gs and at least B Bs in it. The numbers R, G and B have sum less than or equal to the length of strings possible.For ExampleInputR = 1, G = 1, B = 1 length=3OutputCount of number of strings (made of R, G and B) using given combination are − 6ExplanationThe possible strings will be : “RGB”, “RBG”, “BRG”, “BGR”, “GRB”, “GBR”. That ... Read More

413 Views
Given an array arr[ ] containing positive integers and a value match. The goal is to find the subsets of arr[] that contain elements that have XOR = match.For ExampleInputarr[] = {4, 2, 8, 10} match=12OutputCount of number of subsets having a particular XOR value are: 2ExplanationSubsets of arr with XOR of elements as 0 are − [ 4, 8 ], [4, 2, 10]Inputarr[] = {3, 5, 2, 7} match=5OutputCount of number of subsets having a particular XOR value are− 2Explanationubsets of arr with XOR of elements as 0 are− [ 5 ], [2, 7]Approach used in the below program ... Read More

388 Views
Given an array arr[] containing positive integers. The goal is to find the number of subarrays of length at least 1 which are non−increasing. If arr[]= {1, 3, 2}, then subarrays will be {1}, {2}, {3}, {3, 2}. Count is 4.For ExampleInputarr[] = {5, 4, 5}OutputCount of number of non-increasing subarrays are: 7ExplanationThe subarrays will be − {5}, {4}, {5}, {5, 4}Inputarr[] = {10, 9, 8, 7}OutputCount of number of non−increasing subarrays are − 10ExplanationThe subarrays will be − {10}, {9}, {8}, {7}, {10, 9}, {9, 8}, {8, 7}, {10, 9, 8}, {9, 8, 7}, {10, 9, 8, 7}Approach used ... Read More

526 Views
Given an array of holes[10] containing a number of holes in numbers 0 to 9. The goal is to find the number of holes in an integer number given as input. Given − holes[] = { 2, 1, 1, 0, 0, 1, 1, 1, 0 }For ExampleInputnumber = 239143OutputCount the number of holes in an integer are: 3ExplanationWe will count holes given in holes[] 239143 ( 1+0+0+2+0+0 )Inputnumber = 12345OutputCount the number of holes in an integer are: 3ExplanationWe will count holes given in holes[] 12345 ( 1+1+0+0+1)Approach used in the below program is as follows −Simply take each leftmost ... Read More

417 Views
Given a 2D array arr[][] containing intervals and a number ‘value’. The goal is to find the number of intervals present in arr between which value lies. For example intervals are [ [1, 5], [3, 7] ] and value=4 then it lies in both these intervals and count would be 2.For ExampleInputarr[4][2] = { { 1, 20 }, { 12, 25 }, { 32, 40 }, { 15, 18 } } value=16OutputCount of number of intervals in which a given value lies are: 3ExplanationThe value 16 lies between 1−20, 12−25 and 15−18Inputarr[4][2] = {{ 1, 20 }, { 20, 30 ... Read More