Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1115 |
@bt8816103042 | 739 |
@thealchemist627 | 456 |
@akashkale117 | 453 |
@shivanandp12345678910 | 453 |
@dalwainazism125 | 453 |
@codeantik | 448 |
@SherlockHolmes3 | 447 |
@SHOAIBVIJAPURE | 430 |
@shalinibhataniya1097 | 408 |
@neverevergiveup | 393 |
Complete Leaderboard |
Given an array of integers arr[0..n-1], count all pairs (arr[i], arr[j]) in it such that i*arr[i] > j*arr[j],
and 0 ≤ i < j < n.
Example 1:
Input :
arr[] = {5, 0, 10, 2, 4, 1, 6}
Output :
5
Explanation :
Pairs which hold condition i*arr[i] > j*arr[j] are
(10, 2) (10, 4) (10, 1) (2, 1) (4, 1)
Example 2:
Input :
arr[] = {8, 4, 2, 1}
Output :
2
Your Task:
You don't need to read input or print anything. Your task is to complete the function countPairs() which takes the array A[] and its size N as inputs and returns the required result.
Expected Time Complexity: O(N. log(N))
Expected Auxiliary Space: O(N. log(N))
Constraints:
1 ≤ N ≤ 105
1 ≤ A[ ] ≤ 103
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes