Reported April 2024
Alarm.commath

Arrange Coins

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

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

Alarm.com's April OA included a classic staircase problem where you're given coins and need to figure out how many complete steps you can build. The catch is that step 1 needs 1 coin, step 2 needs 2 coins, step 3 needs 3, and so on. You have a fixed budget of coins and need to return the highest step you can complete. It's math disguised as a simulation problem, and the brute force path will work but waste precious minutes. StealthCoder can surface the closed-form solution if you blank on the pattern.

Pattern and pitfall

This is a classic math problem hiding as a coding interview. You could iterate through steps and subtract coins each time, but the real trick is recognizing that the sum of steps 1 through n equals n*(n+1)/2. Rearrange that formula and use the quadratic formula to jump straight to your answer in constant time. Most candidates code the loop version and pass, but Alarm.com has seen it enough times that they probably appreciate the O(1) solution. The common pitfall is off-by-one errors when converting the formula back. If you freeze on the derivation during the live OA, StealthCoder lets you grab the pattern without raising flags.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Arrange Coins 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as arranging coins. If you have time before the OA, drill that.

⏵ The honest play

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

Alarm.com 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.

Arrange Coins FAQ

Is this actually a hard problem or a warm-up?+

It's a warm-up with a trick. The loop solution passes easily and takes 5 minutes. The math solution impresses. Alarm.com likely uses it to separate candidates who know formulas from those who only know loops. Either way you're fine, but the formula is the hedge.

What's the O(1) approach everyone talks about?+

Recognize that complete steps 1 to n sum to n*(n+1)/2. Set that equal to your coin count, solve for n using the quadratic formula, and floor the result. Derived answer in one line instead of a loop. Binary search also works in O(log n) if you forget the formula.

How do I spot this is a math problem and not a greedy one?+

You're not choosing which coins to use. You're just asked how high you can go with a fixed total. That's a pure counting/math problem. The constraint is the sum, not individual coin picks.

What if I code the loop and run out of time?+

The loop version is correct and will pass. You won't time out on the test. You'll just finish faster than someone who derives the formula. If you blank mid-loop, StealthCoder can fill in the pattern so you don't stall.

Do I need to handle edge cases like zero coins?+

Yes. Zero coins means zero steps completed. Negative coins won't appear. Test with 0, 1, 3, 5, and a large number like 1000000000 to verify your solution handles the boundary cases.

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

OA at Alarm.com?
Invisible during screen share
Get it