← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given n phone batteries, each with a fixed capacity (in minutes of talk-time) and a recharge time (in minutes). Initially all batteries are fully charged. You must power a phone for exactly t minutes of talk-time by rotating batteries: whenever the current battery is drained you must instantly swap in any charged battery (if none exists, the phone dies). While a battery is not in use it recharges at a rate of 1 minute of charge per 1 minute of real time, but it can never exceed its original capacity. Determine whether it is possible to keep the phone alive for the entire t minutes, and if so, return the minimum number of battery swaps required; if impossible, return -1.