Project Estimates
Updated
Problem statement
A project has received several bids. Given the distinct integer values in projectCosts and a positive integer target, determine how many distinct value pairs have an absolute difference equal to target.
Two pairs are distinct when they differ in at least one value.
Function
countPairs(projectCosts: int[], target: int) → intExamples
Example 1
projectCosts = [1,3,5]target = 2return = 2The valid pairs are [1,3] and [3,5].
Example 2
projectCosts = [1,5,3,4,2]target = 2return = 3The valid pairs are [1,3], [3,5], and [2,4].
Constraints
2 <= projectCosts.length <= 200000.1 <= projectCosts[i] <= 2 * 10^9.- All values in
projectCostsare distinct. 1 <= target <= 10^9.
More AT&T Online Assessment questions
- Companies with Average Salary Above 40000OA · Seen Oct 2026
- Count Proper Prefix MatchesOA · Seen Oct 2026
- Minimum Binary Swaps to a PalindromeOA · Seen Oct 2026
- 3SumOA · Seen Oct 2025
- Break a PalindromeOA · Seen Oct 2025
- Advertising System Failures ReportOA · Seen Nov 2024
- Counting Triplets Divisible by DOA · Seen Nov 2024
Similar questions at other companies
- Build the Task HierarchyPendo · OA
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Two SumAmazon · OA · PHONE SCREEN
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Customer Signer ScreeningState Farm · OA
- Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
- K Most Recent Unique Request IDsMicrosoft · OAMicrosoft interview questions