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

402 Views
We are given with an array of N elements. The goal is to find the count of all pairs (Arr[i], Arr[j]) which have a sum which is a perfect square such that i!=j. That is Arr[i]+Arr[j] is a perfect square.We will do this by calculating the sum of pairs and check if the square root of that sum is equal to the floor value of the square root. sqrt(Arr[i]+Arr[j])-floor( sqrt(Arr[i]+Arr[j] )==0.Let’s understand with examples.Input − Arr[]= { 4, 3, 2, 1, 2, 4 } N=6Output − Count of pairs with sum as perfect square − 2Explanation −Arr[1]+Arr[3]=4, sqrt(4)-floor(4)=0 4 is ... Read More

674 Views
We are given with an array of N elements. The goal is to find the count of all pairs (Arr[i], Arr[j]) which have a sum which is a perfect square such that i!=j. That is Arr[i]+Arr[j] is a perfect square.We will do this by calculating the sum of pairs and check if the square root of that sum is equal to the floor value of the square root. sqrt(Arr[i]+Arr[j])-floor( sqrt(Arr[i]+Arr[j] )==0.Let’s understand with examples.Input − Arr[]= { 4, 3, 2, 1, 2, 4 } N=6Output − Count of pairs with sum as perfect square − 2Explanation −Arr[1]+Arr[3]=4, sqrt(4)-floor(4)=0 4 is ... Read More

253 Views
We are given with N no. of participants in a coding competition. The goal is to find the no. of pairs that are possible when a person can pair with at most one other person. So a pair has at most 2 participants. The participants are allowed to take part alone also.We can solve this using recurrence where pairs=count=1 when n=0 or 1 ( only one person left )if person remains single n reduced to n-1now for remaining pairing people left = n-2count=makePairs(p-1) + (p-1)*makePairs(p-2);Let’s understand with examples.Input − persons=3Output − Count of ways to make pair − 4Explanation −If ... Read More

504 Views
We are given with an array of N elements. The goal is to find the index pairs (i, j) which have the same element value such that i!=j. i.e, Arr[i]=Arr[j] and i!=j. This is used to make pairs of gloves of equal size. Out of N gloves only paired gloves are useful to sell.We will do this by running two loops with 0 -1. Total pairs=2Approach used in the below program is as followsWe take an integer array Arr[] initialized with random numbers for size of gloves > 0.Take a variable n which stores the length of Arr[].Function countPairs(int arr[], ... Read More

491 Views
We are given with an array of numbers Arr[]. The goal is to count the number of triplets whose product is equal to the given number p. There can be more than one triplet with the same values but different elements. For example, (1, 2, 3) and (3, 1, 2) in array [1, 2, 3, 1, 2] will be counted as different if elements are different but values are the same.Let’s understand with examples.Input − arr[]= { 1, 2, 3, 2, 4, 1, 5 }, p=4Output − Number of triplets: 3Explanation −Triplet 1[ 1, 2, 3, 2, 4, 1, 5 ... Read More

293 Views
We are given an array of integers, Arr[] and two variables a and b to define a range [a,b]. The goal is to find the number of triplets whose sum lies in between this range [a,b].We will do this by using three for loops. Increment count if arr[i]+arr[j]+arr[k]>=a and arr[i]+arr[j]+arr[k]

383 Views
We are given a number N. The goal is to count the number of steps required to reduce the number to 1 by following rules −If the number is power of 2, reduce it to its half.Else reduce it to the N-(nearest power of 2 which is less than N).For step 1, we will check if N is power of 2, by checking if ceil(log2(N)), floor(log2(N)) return the same result. If yes then N=N/3, increment count of operation.If the result of step 1 is false then we will perform step 2 and subtract the nearest power of 2 less than ... Read More