Reported January 2024
Goldman Sachshash table

Project Estimates

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

Get StealthCoderRuns invisibly during the live Goldman Sachs OA. Under 2s to a working solution.
Founder's read

Goldman Sachs hit you with a pair-counting problem in January 2024, and it's a trap if you overthink it. You need to count distinct pairs of project costs where the absolute difference equals a target value. The surface reads like a brute-force nested loop, but the catch is handling duplicates correctly. If you blank on the optimal approach during the OA, StealthCoder will feed you the pattern in real time so you don't waste 15 minutes debugging.

The problem

A number of bids are being taken for a project. Determine the number of distinct pairs of project costs where their absolute difference is some target value. Two pairs are distinct if they differ in at least one value. \ Function Description\ Complete the function countPairs in the editor. countPairs has the following parameter(s): \ Returns\ int: the number of distinct pairs in projectCosts with an absolute difference of target
\

Reported by candidates. Source: FastPrep

Pattern and pitfall

This is a hash-table counting problem masquerading as a search problem. The trick: use a frequency map to store how many times each cost appears, then iterate through unique costs and check if cost + target exists in the map. For each valid pair, multiply the frequencies. The pitfall is thinking you need a two-pointer sort or assuming all pairs are equally weighted. The real complexity is that pairs (a, b) and (b, a) are the same, so you only count forward. If target is 0 and a cost appears twice, that's one valid pair from itself, not zero. StealthCoder handles this edge case instantly if you freeze mid-interview.

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 Goldman Sachs's OA.

Goldman Sachs 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

Do I need to sort the array?+

No. A hash map is faster. Sort only if the problem explicitly asks for ordered output. Sorting adds O(n log n) when you don't need it. Goldman Sachs expects you to see the hash-table pattern right away.

What if the same cost appears multiple times?+

That's the crux. Store frequencies in a map. If cost X appears 3 times and cost X + target appears 2 times, that's 3 * 2 = 6 pairs. Special case: if target is 0, one cost appearing N times contributes N choose 2, not N squared.

How do I avoid double-counting pairs?+

Iterate through the map once. For each cost, check if cost + target exists. Only count forward. Since you're checking cost + target, not cost - target, you never revisit a pair. This is why hash-table beats brute force.

What's the time complexity?+

O(n) to build the frequency map, O(n) to iterate and count pairs. Total O(n). Space is O(n) for the map. Brute force is O(n squared). Goldman Sachs wants linear.

Can I code this in 10 minutes?+

Yes, if you see the pattern. Hash map, frequency loop, forward-check for target. If you blank, you'll write nested loops and miss the optimization. That's when StealthCoder becomes your safety net during the real OA.

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

OA at Goldman Sachs?
Invisible during screen share
Get it