Problem Β· Array
Get Pairs Count π₯
Learn this problemProblem statement
Amazon's development team is working on a parallel-processing analysis system designed to measure the computational demand of multiple tasks. There are n tasks, and the resource consumption for completing the i-th task is given by tasks[i].
Two tasks are considered computationally equivalent if the absolute difference in their resource requirements is less than or equal to k.
Given the list tasks and the integer k, compute the total number of unique pairs of tasks that can be classified as computationally equivalent.
Function
getPairsCount(tasks: int[], threshold: int) β longExamples
Example 1
tasks = [100, 200, 300, 400]threshold = 250return = 5The pairs of processes considered computationally equivalent are (100, 200), (100, 300), (200, 300), (200, 400), and (300, 400).
Example 2
tasks = [10, 12, 11]threshold = 0return = 0Every pair of processes has a difference in computational resource needs that is strictly greater than zero.
Example 3
tasks = [7, 10, 13, 11]threshold = 3return = 4
The process pairs are shown in the above image. Hence the answer is 4.
Constraints
1 β€ n β€ 2 * 10^51 β€ tasks[i] β€ 10^60 β€ threshold β€ 10^6
More Amazon problems
- Secure Maximum DeliveriesOA Β· Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW Β· Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN Β· Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN Β· Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW Β· Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW Β· Seen Jul 2026
- Maximum System Memory CapacityOA Β· Seen Jul 2026
- Package Delivery SystemOA Β· Seen Jul 2026