Timer is Running

Pair array product sum
Submissions: 15   Accuracy:


  Difficulty: Basic   Marks: 1

Given a array a[] of non-negative integers. Count the number of pairs (i, j) in the array such that a[i] + a[j] < a[i]*a[j]. (the pair (i, j) and (j, i) are considered same and i should not be equal to j)

Example 1:

arr[] = {3, 4, 5} 
Output: 3
Explanation: Pairs are (3, 4) , (4, 5) and (3,5).  


Example 2:

arr[] = {1, 1, 1 } 
Output: 0

Your Task:
Since, this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function CountPairs() that takes array arr and integer n as parameters and return the total number of pairs possible.


Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).


1 ≤ N ≤ 105


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sudarshan Sharma
Author: Ayush Govil 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.