Phone Battery Discharge Scheduling
Learn this problemProblem statement
A dead phone needs to run for t minutes of usage time. You have n spare batteries indexed 0 to n - 1, all fully charged at the start. Battery i provides capacity[i] minutes of phone runtime; after it is fully drained it needs recharge[i] minutes of real-time to be ready again.
Batteries must be used in strict cyclic order: 0, 1, 2, ..., n - 1, 0, 1, .... You cannot skip a battery: if the next one in line is still recharging when its turn comes, the phone sits dead (off) until that battery is ready. Phone usage time does not advance while the phone is off; only real-time advances, allowing the other batteries to keep recharging on their own schedules. Once a battery is inserted, the phone runs on it continuously until it is fully drained or the phone hits its t-minute target — you cannot pop a battery out partway through to insert the next one.
Return the indices of the batteries that were fully discharged within the t minutes of usage, in the order they discharged. If the last battery used was only partially drained when the phone hit its t-minute target, it is not included.
Function
batteryDischargeOrder(t: int, capacity: int[], recharge: int[]) → int[]Examples
Example 1
t = 10capacity = [3, 4, 2]recharge = [5, 6, 8]return = [0, 1, 2]Example 2
t = 10capacity = [5]recharge = [5]return = [0, 0]Example 3
t = 4capacity = [5]recharge = [10]return = []Constraints
1 <= t <= 10^41 <= capacity.length == recharge.length <= 10^31 <= capacity[i] <= 10^40 <= recharge[i] <= 10^4
More Roblox problems
- Most Frequent Call Stack Per ThreadPHONE SCREEN · Seen Jul 2026
- Break a PalindromeOA · Seen Jun 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026