Reported September 2024
FactSetheap priority queue

Last Stone Weight

Reported by candidates from FactSet's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live FactSet OA. Under 2s to a working solution.
Founder's read

FactSet hit you with Last Stone Weight in September 2024, and it's a heap problem designed to trip up candidates who overthink it. You're given a list of stone weights. In each turn, you pick the two heaviest stones, smash them together, and if they're unequal, the heavier stone minus the lighter one goes back into the pile. The game ends when one stone or zero stones remain. Return the weight of the last stone, or zero if none are left. It's straightforward once you see the pattern, but the live OA can fog your memory. StealthCoder sits invisible on your screen and feeds you the heap structure the moment you blank.

Pattern and pitfall

This is a max-heap problem masquerading as a simulation. Python's heapq is a min-heap by default, so you either negate values when pushing or use a workaround. The trick is recognizing that you're always extracting the two maximum elements, processing them, and reinserting the result. A naive sort-every-iteration approach will time out on large inputs. Build a max-heap, loop until one stone or fewer remain, pop twice, compute the difference, and push it back if nonzero. The pattern is heap-priority-queue. Most candidates miss the negation trick in Python and waste minutes debugging. StealthCoder knows the exact syntax and avoids that rabbit hole during the real OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Last Stone Weight 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as last stone weight. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass FactSet's OA.

FactSet 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.

Last Stone Weight FAQ

Is this really just a max-heap problem?+

Yes. Extract the two heaviest repeatedly, compute the difference, and reinsert. The 'simulation' framing is narrative decoration. A priority queue (max-heap) is the only efficient structure. Sorting the array each time will time out.

How do I do a max-heap in Python?+

heapq is a min-heap. Negate all weights when inserting and negate again when popping. Or use a wrapper class. Most candidates forget the negation and spend 10 minutes debugging. Know this before the OA.

What's the time complexity?+

O(n log n) for heap operations. You extract two stones and reinsert at most n times. Much better than re-sorting each iteration, which is O(n^2 log n) and will fail large test cases.

Do I need to handle edge cases like empty lists?+

Yes. If the input has zero or one stone, return that stone's weight immediately. If two or more stones and the final result is zero, return zero. Test these before submitting.

Is FactSet likely to ask a heap problem again?+

Yes. Heap problems are common in FactSet OAs, especially those disguised as simulations or game logic. If you see 'repeatedly extract max' or 'process pairs,' think heap immediately.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with FactSet.

OA at FactSet?
Invisible during screen share
Get it