Get Min 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's September OA threw 'Get Min Cost' at candidates, and it's a greedy problem wrapped in what looks like optimization. You're trying to minimize cost across some set of choices, and the trap is overthinking it. The greedy move works here, but only if you pick the right attribute to sort by. This is exactly the kind of problem where StealthCoder sits quietly in your corner during the live OA, ready to surface the sorting key if you freeze on what matters.
Pattern and pitfall
Greedy problems ask: what choice do I make right now that leads to the globally optimal answer. For 'Get Min Cost,' that means identifying which property of each option should drive your decision order. Common mistakes: sorting by the wrong metric, or assuming you need dynamic programming when a single greedy pass wins. The pattern is almost always sort then iterate, picking the cheapest, smallest, or earliest available resource that satisfies a constraint. The algorithmic trick is recognizing that greedy works here because the subproblems don't interfere, then coding it clean. When you're live and blanking on the sort order, StealthCoder reads the problem and suggests the right approach without the proctor seeing it.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Get Min 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass JP Morgan's OA.
JP Morgan reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Min Cost FAQ
How hard is 'Get Min Cost' really on JP Morgan OAs?+
Medium. It looks deceptively simple once you nail the greedy insight. Most failures come from wrong sort order or missing a constraint, not from the algorithm itself. If you see it and recognize greedy, you're in good shape.
What's the main trick in this problem?+
Figuring out which property to sort by. Try cost ascending, then work backward if it doesn't make sense. The greedy choice is often 'pick the cheapest available now.' Always validate your sort order against 2-3 test cases before submitting.
Can I solve this without greedy?+
Technically yes, but greedy is the intended path. Dynamic programming or brute force will time out on large inputs. The problem is specifically designed to test whether you recognize a greedy opportunity.
How do I prepare for greedy problems in 48 hours?+
Learn the pattern: sort, then one pass, then done. Know the difference between greedy and DP. Trace through 2-3 examples by hand. Greedy problems reward clarity and correctness of the sort key, not complex data structures.
Is this still being asked in September 2024 OAs?+
Yes. JP Morgan cycles through the same problem families. If you see an optimization problem that feels like it should be greedy, trust that instinct. This problem type appears consistently.