Find Total Cost
Reported by candidates from JP Morgan's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
JP Morgan sent you a cost calculation problem in December 2024, and you've got 24-72 hours to nail it. This isn't a trick question, but it's designed to catch candidates who overthink or miss an edge case. You need to read the problem carefully, understand what 'total cost' actually means in context, and implement it cleanly. If you blank during the live OA, StealthCoder will read the problem on screen and feed you the pattern in real time.
Pattern and pitfall
Cost problems usually boil down to one of two shapes: either you're summing across a dataset with a fixed formula, or you're applying tiered pricing where the formula changes based on quantity. The trap is that candidates often miss whether discounts apply retroactively, whether there are bulk thresholds, or whether the cost is per unit or cumulative. Start by identifying the input (quantities, prices, maybe a discount table), then build a single-pass loop or a formula. Edge cases: zero quantities, missing prices, rounding rules. StealthCoder helps if you freeze on the exact calculation logic during the live assessment.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Find Total Cost 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass JP Morgan's OA.
JP Morgan 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.
Find Total Cost FAQ
Is this a simple sum or something more complex?+
Without the exact problem text, assume it's straightforward sum first, then check for conditional logic. JP Morgan problems rarely need advanced data structures. If the input is an array of items with prices, start with a single loop and accumulate. Read the problem statement twice before coding.
What's the most common mistake on cost problems?+
Forgetting rounding rules and misreading whether discounts apply to subtotals or individual items. Also, candidates assume 'cost' means revenue, when it might mean expense. Parse the exact wording of what total means.
How do I handle edge cases fast?+
Empty input, negative numbers, zero quantities, and missing prices. Check the constraints section of the problem. If it says prices are positive integers, don't handle negatives. Save time by nailing the main path, then add guards only if the problem hints at edge cases.
Should I optimize for time or just get it working?+
Single pass is always safe for cost problems. Avoid sorting or extra data structures unless the problem explicitly requires ranking or filtering. O(n) is the target. If you're at O(n^2), you've overcomplicized it.
How much time should I spend reading vs. coding?+
Spend 3-5 minutes on the problem statement alone. Reread it once. Spend 1-2 minutes planning the loop or formula on paper. Code for 10-15 minutes. Test with a provided example. Iterate if it fails.