Particle Moves to Target
Reported by candidates from Cresta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Most first attempts at this Cresta problem die the same way: the candidate reaches for BFS over the grid, or greedily burns alpha moves until the position looks close. Reported in July 2026, Particle Moves to Target is a math problem wearing a grid costume. Three moves, two equations, one free variable. Coordinates reach 10^6 in magnitude, so searching is out anyway. Once you see the algebra, it's about ten lines. If you blank on the ceiling division with negative numbers, StealthCoder runs invisibly on your screen during the live OA and gives you the solution. Read the next section first and you probably won't need it.
The problem
A particle starts at integer coordinate (startX, startY) and must reach (targetX, targetY) on an unbounded grid. You may use these operations any nonnegative number of times: PROTON: move one cell right, from (x, y) to (x + 1, y). NEUTRON: move one cell down, from (x, y) to (x, y - 1). ALPHA: move two cells up and two cells left, from (x, y) to (x - 2, y + 2). Return a three-element integer array [protons, neutrons, alphas] whose operations reach the target using the minimum possible total number of operations. The result is ordered as PROTON, NEUTRON, ALPHA. Function particleMoves(startX: int, startY: int, targetX: int, targetY: int) → int[] Examples Example 1 startX = 0 startY = 0 targetX = 3 targetY = -2 return = [3,2,0] Three PROTON operations add 3 to x, and two NEUTRON operations subtract 2 from y. No ALPHA operation is needed. Example 2 startX = 4 startY = -3 targetX = -2 targetY = 5 return = [2,0,4] Four ALPHA operations change the position by (-8, 8), and two PROTON operations restore x by 2. The net change is (-6, 8). Example 3 startX = -5 startY = 7 targetX = -8 targetY = 0 return = [1,11,2] Two ALPHA operations contribute (-4, 4). One PROTON and eleven NEUTRON operations then produce the required net change (-3, -7). Constraints -10^6 <= startX, startY, targetX, targetY <= 10^6. Movement occurs on an unbounded integer grid. A minimum-operation solution always exists and every returned count fits a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Let dx = targetX - startX and dy = targetY - startY. With p protons, n neutrons and a alphas, you need p - 2a = dx and 2a - n = dy. So p = dx + 2a and n = 2a - dy. Total operations is dx - dy + 5a, which only grows with a. So pick the smallest a that keeps p, n and a nonnegative: a = max(0, ceil(-dx/2), ceil(dy/2)). Then compute p and n from it. Check example 3: dx = -3, dy = -7, so a = 2, p = 1, n = 11. Matches. The pitfall is ceiling division on negatives. Languages that truncate toward zero will give wrong answers, so use (v + 1) // 2 with floor division or guard the sign. Another trap is trying to fix parity with extra moves. You never need to. If the formula slips under pressure, StealthCoder is the hedge on the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Particle Moves to Target 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Cresta's OA.
Cresta reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Particle Moves to Target FAQ
What's the trick in Particle Moves to Target?+
Write two equations: p - 2a = dx and 2a - n = dy. Everything depends on a, the number of alpha moves. Total cost is dx - dy + 5a, so you want the smallest valid a. No search, no DP, just a closed-form max of three lower bounds.
How do I compute the minimum number of alpha moves?+
a = max(0, ceil(-dx/2), ceil(dy/2)). The first bound keeps protons nonnegative, the second keeps neutrons nonnegative. Then p = dx + 2a and n = 2a - dy. Verify with Example 2: dx = -6, dy = 8 gives a = 4, p = 2, n = 0.
Why does BFS or greedy fail here?+
BFS on a grid with coordinates up to 10^6 explodes in states and time. Greedy alpha spending ignores that each alpha shifts both axes at once, so you can overshoot and pay for extra protons and neutrons. The algebra gives the exact optimum directly.
What edge cases should I test before submitting?+
Test dx and dy both zero, which should return [0,0,0]. Test negative dx with positive dy, where alphas dominate. Test odd values, like dx = -3, where ceiling division matters. Test the all-positive dx and negative dy case, which needs no alphas. Also check negative ceiling behavior in your language.
How do I prepare for this in 48 hours?+
Don't grind grid problems. Practice setting up linear equations for move-count puzzles and solving for one free variable. Rehearse ceiling division on negatives in your chosen language. Then run the three given examples by hand. This problem takes about twenty minutes once the equations click.