- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7347 Articles for C++
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
127 Views
We are given an array of positive integers. The goal is to find the count of distinct pairs of elements of an array that have at-least one prime member. If the array is [1, 2, 3, 4] then pairs would be (1, 2), (1, 3), (2, 3), (2, 4) and (3, 4).Let us understand with examplesInput − arr[] = { 1, 2, 4, 8, 10 };Output − Count of pairs in an array such that at least one element is prime are − 4Explanation − The only prime element is 2 and pairing it with all others will give − ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
172 Views
We are given an array of positive integers. The goal is to find the count of pairs of elements of arr[] such that condition LCM( arr[i], arr[j] ) > minimum of ( arr[i], arr[j] ). That is, the lowest common multiple of elements in a pair is greater than the minimum of both.Note − pair ( arr[i], arr[j] ) is the same as ( arr[j], arr[i] ). Don’t count it twice.Let us understand with examples.Input − arr[] = [ 1, 5, 4, 2 ]Output − Count of pairs in an array such that LCM(arr[i], arr[j]) > min(arr[i], arr[j]) are − ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
140 Views
We are given an array of numbers. The goal is to find the pair of elements of array such that they hold the conditionIf (i*arr[i] > j*arr[j]) then (arr[i], arr[j]) is a valid pair.If the array is [ 5, 4, 3, 2, 1 ] then pairs will be [3, 1] and [2, 1].Let us understand with examples.Input − arr[] = [ 1, 5, 4, 1, 2, 8, 3 ]Output − Count of pairs in an array that hold i*arr[i] > j*arr[j] are − 3Explanation − Pairs are (5, 1), (4, 1), (8, 3)Input − arr[] = [ -1, -2, 3, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
228 Views
We have a sequence generator that starts with 1. At each step 0 becomes 10 and 1 becomes 01. So following changes will occur at consecutive steps −Step 1 − 01Step 2 − 1001Step 3 − 01101001 ……The goal is to find the number of pairs of consecutive 0’s for a given number of steps.If input step is 1 pair of 0’s - 0, input step is 2 pair of 0’s - 1, input step is 3 pair of 0’s 1Step 4 − 1001011001101001Step 5 − 01101001100101101001011001101001We can observe that sequence is increasing in powers of 2 and repeats itself ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
2K+ Views
We are given a string containing an English sentence. The goal is to find the number of words in the string that are palindromes. Palindrome words are those that when read from start or end have the same alphabet sequence. If the sentence is “Madam speaks good Malayalam”, then count of palindrome words is 2. (Madam and Malayalam)Note − Words can contain both upper and lowercase alphabets.Let us understand with examples.Input − str = "My Mom and Anna left at Noon";Output − Count of palindrome words in a sentence are − 3Explanation − Palindrome words in above sentence are − ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
358 Views
We are given variables x1, x2, y1, y2 representing two points on a 2D coordinate system as (x1, y1) and (x2, y2). The goal is to find all the paths that will have distance equal to the Manhattan distance between these two points.Manhattan DistanceManhattan Distance between two points (x1, y1) and (x2, y2) is −MD= |x1 – x2| + |y1 – y2|Let’s take A= |x1 – x2| and B= |y1 – y2|All paths with Manhattan distance equal to MD will have edges count as (A+B). A horizontal edge and B vertical edges. So possible combination of (A+B) edges divided into ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
903 Views
We gave three input variables as ‘start’, ‘end’ and ‘number’. The goal is to find pairs of numbers between start and end that have GCD value equal to ‘number’. For example GCD(A, B)=number and both A, B are in range [start, end].Let us understand with examples.Input − start=5 end=20 number=8Output − Count of pairs of natural numbers with GCD equal to given number are − 3Explanation − Pairs between 5 to 20 such that GCD is 8 are − (8, 8), (8, 16), (16, 8)Input − start=5 end=20 number=7Output − Count of pairs of natural numbers with GCD equal to ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
194 Views
We are given an array of integers such that each element of the array is in the range [- 1000, 1000]. The goal is to find pairs of elements of the array such that their average is also present in that array. If array is arr[]= [1, 2, 3, 4]. Then pairs would be (1, 3) and (2, 4) as the average of 1, 3 is 2 and the average of 2, 4 is 3 and both 2 and 3 are present in the array. Count would be 2.Let us understand with examples.Input − arr[]= { -1, 2, 5, -3, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
138 Views
We are given a number N. The goal is to find the pairs of numbers from 1 to N such that the product of pairs is equal to the sum of pairs.Let us understand with examples.Input − N=11Output − Count of pairs of no. from 1 to N with Product divisible by their Sum are − 1Explanation − Numbers 3 and 6 have product 18 and their sum 9 fully divides 18.Input − N=30Output − Count of pairs of no. from 1 to N with Product divisible by their Sum are − 12Explanation − Pairs are − (3, 6), (4, ... Read More