AmazonOA #235
Get Number of Teams
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersBinary Search
Choose two different employees; different indices mean different people, even when their skills are equal. Count the unordered employee pairs whose skill sum lies in the closed range [minSkill,maxSkill].
Input
The first line contains n minSkill maxSkill; the second line contains the skills. The original constraints were truncated; this site uses 1≤n≤200000, skills and both bounds in −10^9..10^9, and minSkill≤maxSkill.
Output
Output a single integer, the answer.
Example 1
Input:
4 5 7
2 3 4 5
Output:
4
Example 2
Input:
3 2 2
1 1 1
Output:
3
Example 3
Input:
3 -2 0
-2 0 2
Output:
2
Example notes
The answers are 4, 3 and 2. In the second example three employees with the same skill form three pairs.
Editorial
Loading solution…