Min Absolute Sum
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's Min Absolute Sum question landed on October 2024 OAs, and it's a dynamic programming play on partition logic. You're given an array and need to split it into two subsets such that the absolute difference between their sums is minimized. The trap is thinking greedy or brute force. You need DP to explore all reachable sums and backtrack to find the closest pair. StealthCoder can shadow you through the state transitions if the recurrence relation blanks you mid-interview.
Pattern and pitfall
The core insight: this is a variant of the partition problem. Use DP where dp[i] is true if sum i is achievable using a subset of the array. Iterate through each number and update the DP table backward to avoid using the same element twice. Once you've built the table, iterate from the total sum down to zero and find the largest achievable sum that is <= total/2. That subset's complement gives you the minimum difference. The twist candidates miss: you need to track which sums are reachable, not which elements. If you blank on the update order or the final iteration, StealthCoder reads the state space and feeds you the pattern in real time.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Min Absolute Sum 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as partition equal subset sum. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Absolute Sum FAQ
Is this really just the partition problem?+
Functionally yes. You're partitioning into two subsets to minimize the absolute difference. Standard DP partition with a twist: you need the actual minimum difference, not just whether a partition exists. The DP table is identical; the final answer extraction is what differs.
What's the time complexity I should target?+
O(n * S) where n is array length and S is the total sum. Space is also O(S) for the DP table. Google expects this. Anything slower than O(n^2) is a red flag on medium arrays. Brute force is instant rejection.
Do I update the DP table forward or backward?+
Backward. Iterate from the current sum down to the element value. This prevents reusing the same element in one pass. Forward iteration will double-count and give you wrong answers. This is the most common mistake.
How do I extract the actual minimum difference?+
After building your reachable sums table, iterate from total_sum / 2 down to 0. Find the largest sum that's reachable. That's one subset sum; the other is total_sum minus that. The difference is total_sum minus 2 times the smaller sum.
Can negative numbers appear in the array?+
The problem doesn't specify, but Google often includes them. If negatives exist, offset all sums by the absolute minimum value to avoid negative indices. Or use a dictionary instead of an array for your DP table. Clarify during the OA if possible.