nextBusMinute 🌶️
A bus leaves the stop at minute every, then at 2 every, 3 every, and so on. You get to the stop at minute arrive. If a bus leaves at the very minute you arrive, you just miss it.
Write a method nextBusMinute that takes every (1 or more) and arrive (0 or more) and returns the minute of the first bus that leaves after you arrive. Use a while loop.
For example, nextBusMinute(10, 25) is 30, and nextBusMinute(10, 30) is 40.
The first bus is at minute
every. As long as the bus you are looking at has already left (or is leaving right now), what should happen to it?Loop
while (bus <= arrive) and move to the next bus inside the loop. Which test makes a bus at exactly your arrival minute count as missed?