Skip to content

Practice Count the Number of Fair Pairs

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2563
LeetCode Problem

Count the Number of Fair Pairs

Problem Statement

Count pairs of different indices i < j whose nums values satisfy lower <= nums[i] + nums[j] <= upper. Return the count; different index pairs count separately even when their values match.

Source: Count the Number of Fair Pairs on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [0,1,7,4,4,5], lower = 3, upper = 6
Output
6

# Example 2

Input
nums = [1,7,9,2,5], lower = 11, upper = 11
Output
1

Constraints

1 <= nums.length <= 10^5
nums.length == n
-10^9 <= nums[i] <= 10^9
-10^9 <= lower <= upper <= 10^9

Related LeetCode Problems

Practice more problems similar to Count the Number of Fair Pairs.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.