Reported July 2025
Metasimulation

Count Fully Used Batteries

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

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

Meta reported this one in July 2025, and it looks friendlier than it is. A phone, a ring of batteries, and a clock that has to keep ticking for t minutes. It's a pure simulation, and the trap sits in how you count. If you're taking this OA in the next couple of days, read the last battery rule twice. A battery that's only partly used doesn't count, and that detail flips answers. StealthCoder is there as a safety net on the live OA if your simulation falls apart under pressure, but the logic here is learnable tonight.

The problem

Your mobile phone is out of power, but you need to keep it working continuously for t minutes. You have several spare batteries, and all of them are fully charged at time 0.
Battery i can power the phone for capacity[i] minutes. Once it is fully depleted, it must recharge for recharge[i] minutes before it can be used again.
Use the batteries in their given cyclic order. When the current battery is fully depleted, move to the next battery. If that battery is still recharging, skip it and continue checking the following batteries in order. If every battery is recharging when the phone needs another battery, the phone cannot remain on continuously.
Return the number of complete battery usages during the required t minutes. A battery counts each time it is fully depleted. If it is impossible to keep the phone working continuously for all t minutes, return -1.
A solution with time complexity no worse than O(t * capacity.length) will fit within the execution time limit.

Function
solution(t: int, capacity: int[], recharge: int[]) → int

Examples
Example 1
t = 16
capacity = [2,5,6]
recharge = [12,1,4]
return = 3
Battery 0 powers the phone from time 0 to time 2. It is then depleted, counts as one complete usage, and will be ready again at time 14.
Battery 1 runs from time 2 to time 7, counts as the second complete usage, and will be ready again at time 8.
Battery 2 runs from time 7 to time 13, counts as the third complete usage, and will be ready again at time 17.
At time 13, battery 0 is still recharging, so it is skipped. Battery 1 is ready and supplies the remaining 3 minutes. Because this final use does not fully deplete battery 1, it is not counted.
The phone remains on for all 16 minutes, and the number of complete battery usages is 3.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is simulation with a ready-time array. Keep a variable for the current time and an array readyAt[i], all starting at 0. Keep a pointer to the next battery in cyclic order. At each step, scan forward from the pointer for a battery with readyAt <= now. If none is ready, return -1. Otherwise run it for capacity[i] minutes. If now plus capacity reaches or passes t, stop and don't count it unless it ends exactly at t. Otherwise count it, set readyAt[i] = end + recharge[i], advance time, and move the pointer past i. The common pitfall is counting the final partial battery, or mishandling the exact-boundary case where depletion lands precisely on t. Another is resetting the scan to index 0 instead of continuing cyclically. The stated O(t * n) bound means a plain step-by-step loop is fine. If you blank on the boundary logic during the live OA, StealthCoder can show a working version.

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 Count Fully Used Batteries 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

⏵ The honest play

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

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

Count Fully Used Batteries FAQ

What's the trick in Count Fully Used Batteries?+

It's straightforward simulation. Track the current time and a readyAt value per battery, scan cyclically for the next ready one, and count only batteries that fully deplete. The hard part isn't the algorithm, it's the edge handling at the end of t.

How do I handle the last battery that only partly runs?+

If the battery's end time would pass t, the phone stays on and you don't count it. If it ends exactly at t, it's fully depleted, so it counts. Decide that boundary before coding and test it with a tiny example.

When do I return -1?+

Return -1 when the current time is below t, the phone needs a new battery, and every battery has readyAt greater than now. That means there's a gap where nothing can power the phone, so continuous operation fails.

Is brute force fast enough for this Meta OA question?+

Yes. The problem states that O(t * capacity.length) fits. Each battery use advances time by at least one minute, so the number of steps is at most t, and each step scans at most n batteries.

How do I prepare for this in 48 hours?+

Hand-trace Example 1 until you can predict every readyAt value. Then write the loop and test cases with t equal to a depletion time, all batteries recharging, and a single battery. Simulation questions reward careful tracing more than new algorithms.

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

OA at Meta?
Invisible during screen share
Get it