Max Sum of a Pair With Equal Sum of Digits
A medium-tier problem at 66% community acceptance, tagged with Array, Hash Table, Sorting. Reported in interviews at Nvidia and 0 others.
You're working through an Nvidia assessment and hit a problem that looks straightforward until you realize the brute force scan will TLE. Max Sum of a Pair With Equal Sum of Digits asks you to find two distinct indices with matching digit sums and return their maximum sum. The trick isn't the pair search itself. It's grouping numbers by digit sum, then efficiently finding the two largest in each group. Most candidates waste cycles recomputing digit sums or missing that a hash table collapses the search space. If you blank on the pattern during the live OA, StealthCoder surfaces a working solution in seconds.
Companies that ask "Max Sum of a Pair With Equal Sum of Digits"
Max Sum of a Pair With Equal Sum of Digits 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 an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe problem splits into two moves: calculate digit sum for every number, then group by that sum. Once grouped, the answer is the max pair from whichever group has at least two members. The failure mode is looping through all pairs to find a match; that's O(n^2) and won't pass. Instead, bucket numbers by digit sum in one pass, then iterate buckets and track the two largest values. You'll use Hash Table and Array fundamentals here, and depending on your preference, a Heap (Priority Queue) can speed up tracking the top two per bucket. Digit sum itself is a micro-loop over the number's string or repeated modulo. This is a medium because the concept is simple but the implementation carelessness is real: forgetting to validate two distinct indices, or not caching digit sums. StealthCoder is your hedge if you blank on whether to use a max heap or manual tracking.
Pattern tags
You know the problem.
Make sure you actually pass it.
Max Sum of a Pair With Equal Sum of Digits 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 an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Sum of a Pair With Equal Sum of Digits interview FAQ
Is this problem still asked at major companies?+
Nvidia has reported it. It's a medium-difficulty problem with a 66% acceptance rate, so it filters candidates who can't optimize past brute force but isn't a rare curveball. Expect it in assessments where pattern recognition and hash table efficiency matter.
What's the actual trick I'm missing?+
Stop thinking pair-by-pair. Group numbers by digit sum first using a hash table, then find the max sum within each group. Once you've bucketed, the answer is the sum of the two largest numbers in any single bucket. That shifts complexity from O(n^2) to O(n) plus sorting per bucket.
Do I need a heap for this problem?+
No, but it helps if you want O(1) top-2 lookups per bucket. A simpler approach: iterate once per bucket tracking the largest and second-largest. For most assessments, the manual max tracking is fast enough and clearer to code live.
How do I calculate digit sum without mistakes?+
Convert the number to a string and sum each character's numeric value, or use repeated modulo and division. Both work. String approach is less error-prone: sum(int(d) for d in str(num)). Cache results in your hash table to avoid recalculating.
What edge case kills most submissions?+
Forgetting the constraint: indices must be distinct. You can't pair a number with itself even if it's the only candidate in its digit-sum bucket. Also, if no bucket has two or more members, return -1. These aren't tricks; they're reading the problem twice before coding.
Want the actual problem statement? View "Max Sum of a Pair With Equal Sum of Digits" on LeetCode →