Reported November 2024
AT&Thash table

Project Estimates

Reported by candidates from AT&T's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live AT&T OA. Under 2s to a working solution.
Founder's read

The AT&T Project Estimates question, reported in November 2024, looks like a warm-up and mostly is one. It hinges on a hash set. You get a list of distinct bid values and a target, and you count pairs whose absolute difference equals that target. With up to 200000 values, the brute-force double loop is the trap. If you've got an OA coming, this is a five-minute problem when you see the set, and a timeout when you don't. StealthCoder is the safety net if your mind goes blank mid-assessment, but the idea below is short enough to memorize tonight.

The problem

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) → int

Examples
Example 1
projectCosts = [1,3,5]
target = 2
return = 2
The valid pairs are [1,3] and [3,5].
Example 2
projectCosts = [1,5,3,4,2]
target = 2
return = 3
The valid pairs are [1,3], [3,5], and [2,4].

Constraints
2 <= projectCosts.length <= 200000.
1 <= projectCosts[i] <= 2 * 10^9.
All values in projectCosts are distinct.
1 <= target <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Put every value from projectCosts into a hash set. Then for each value x, check whether x + target is in the set. If it is, you've found one pair. Because target is positive and values are distinct, each pair is counted exactly once, since you only look upward. That's O(n) time and O(n) space. The pitfall is the O(n^2) nested loop, which dies at 200000 elements. Another pitfall is checking both x + target and x - target, which double counts every pair. Values reach 2 * 10^9, so watch for integer overflow in 32-bit languages when computing x + target. Use a 64-bit type or compare via subtraction. A sorted array with two pointers also works in O(n log n), but the set is simpler. If you freeze during the live OA, StealthCoder can surface this solution while you keep your head clear.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Project Estimates cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as k diff pairs in an array. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass AT&T's OA.

AT&T reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Project Estimates FAQ

What's the trick in the AT&T Project Estimates problem?+

Store all costs in a hash set, then for each cost x check if x + target exists. That gives O(n) time. Only look in one direction so each pair is counted once. Since target is at least 1 and values are distinct, there's no self-pairing or duplicate edge case.

How hard is this OA question really?+

Easy. It's a pair-difference lookup with a hash set. The only difficulty is recognizing that n can be 200000, which rules out nested loops. If you've solved the classic pairs-with-difference-k problem, you've already seen this one.

Can I use sorting and two pointers instead?+

Yes. Sort the array, then move two pointers and compare the gap to target. It runs in O(n log n) with little extra space. The hash set is faster to write and easier to get right under pressure, so pick it unless memory is a concern.

What edge cases should I test?+

Test the smallest input of two elements, a case where no pair matches, and a case with large values near 2 * 10^9 to check overflow. Also test a chain like [1,3,5] with target 2 to confirm each pair counts once, not twice.

How do I prepare for this in 48 hours?+

Write the hash set solution from scratch twice, then do two or three related problems like two-sum and pairs with difference k. Focus on spotting when a lookup replaces an inner loop. That single move covers this AT&T question and many like it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with AT&T.

OA at AT&T?
Invisible during screen share
Get it