Successful Pairs of Spells and Potions
A medium-tier problem at 45% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at Goldman Sachs and 0 others.
You have two arrays of integers representing spell strengths and potion efficiencies. For each spell, you need to count how many potions create successful pairs where spell * potion >= success threshold. This is a medium-difficulty problem that hits the classic two-pointer and binary search pattern. Goldman Sachs has asked it. The trap is thinking brute force will pass. It won't. The insight is sorting and then either binary search or two pointers to avoid O(n²) TLE. If this problem lands on your live assessment and you freeze on the approach, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Successful Pairs of Spells and Potions"
Successful Pairs of Spells and Potions is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe naive approach is a nested loop: for each spell, check every potion. That's O(n²) and fails on large inputs. The real solution sorts both arrays, then uses two pointers or binary search. If you sort potions, you can binary search for the minimum potion value needed for each spell, or use two pointers starting from opposite ends to count valid pairs efficiently. The trick is recognizing that once you find a potion that works with a spell, all potions to its right (in sorted order) also work. Many candidates write correct logic but don't sort first, or sort but then still loop naively. The two-pointer approach is elegant: start left at the smallest potion and right at the largest spell. If spell * potion works, all potions from left to right work with that spell, so count them and move right. Otherwise move left. Time complexity becomes O(n log n) for sorting plus O(n) for the traversal. That's the hedge you need on the OA.
Pattern tags
You know the problem.
Make sure you actually pass it.
Successful Pairs of Spells and Potions recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Successful Pairs of Spells and Potions interview FAQ
Is this problem really just sorting and two pointers?+
Yes, but the insight doesn't come for free. You must recognize that a sorted array lets you use two pointers or binary search to count valid pairs in one pass instead of nested loops. That's the medium-difficulty hurdle. Without sorting, you're stuck in O(n²).
Why does two pointers work better than binary search here?+
Both work. Two pointers is simpler to code and slightly faster in practice because you process each element once. Binary search requires a log n lookup per spell. For this problem, two pointers feels more natural once you see the sorted array.
What's the most common mistake?+
Writing a brute force nested loop and hoping it passes, or sorting one array but not both, or sorting and then still checking every potion per spell. Candidates also miss that you need to count, not just check existence. Counting requires careful pointer movement.
Goldman Sachs asked this. How often does it come up in interviews?+
Lower frequency in reports, but it's a solid medium-difficulty screening question. It tests whether you can recognize a sorting-based optimization and execute two pointers cleanly. That's something Goldman Sachs cares about.
What topics does this reinforce?+
Array manipulation, Sorting, Two Pointers, and Binary Search. It's a gateway to harder two-pointer problems like merge sorted arrays or reverse pairs. Master the pattern here and you unlock a whole class of optimization tricks.
Want the actual problem statement? View "Successful Pairs of Spells and Potions" on LeetCode →