Min Operations
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 Min Operations question (Feb 2024) is a classic optimization problem disguised as a state-space search. You're given a number and need to find the minimum count of operations to reach a target, usually doubling, dividing, or adding/subtracting. The trap is brute force. Candidates blank on whether to use BFS or dynamic programming. StealthCoder catches that hesitation and feeds you the pattern in real time so you don't waste 20 minutes on the wrong approach.
Pattern and pitfall
Min Operations lives in the BFS or DP world depending on the constraint set. If the state space is bounded and operations are discrete (multiply by 2, divide by 2, add 1, subtract 1), BFS with a visited set is your guardrail. If you're optimizing over a range and can define subproblems cleanly, DP with memoization scales better. The common pitfall is greedy thinking: 'just always divide or double.' That fails when a detour (like adding 1 before dividing) saves operations overall. BFS explores all paths level by level, so it finds the true minimum. Memoization ensures you never recompute the same state. StealthCoder lets you confirm the approach before you code, so you're not second-guessing mid-implementation.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Min Operations 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum genetic mutation. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass JP Morgan's OA.
JP Morgan reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Operations FAQ
Is this really just BFS with a queue?+
Depends on the exact problem. If you're transforming one number and tracking visited states, yes, BFS works cleanly. If operations have weights or you're optimizing over a large range, memoized recursion is faster. JP Morgan usually goes BFS because it's cleaner to explain and code under pressure.
What's the trick that makes greedy fail?+
Greedy assumes the locally optimal move (divide if even, add 1 if odd) is globally optimal. It's not. Example: 3 to 10. Greedy adds 1 three times then divides. BFS finds 3*2=6, +4=10 in 2 moves. Always explore all neighbors.
How do I avoid timeout on the live OA?+
Track visited states in a set. Without it, you revisit the same number and loop infinitely. For BFS, cap the queue or range sensibly. For DP, memoize aggressively. JP Morgan's test cases are usually small enough that both approaches run under 1 second.
Should I use a list or deque for the queue?+
Deque. Use appendleft and pop, or append and popleft, depending on your language. Python's collections.deque is O(1) for both ends. A list's pop(0) is O(n), which kills performance on large state spaces.
Do I need to reconstruct the path or just return the count?+
Usually just the count. If the problem asks for the sequence of operations, store the parent of each state in a dict during BFS and backtrack. JP Morgan usually asks for the minimum count, not the path.