Magicsheet logo

The Number of Full Rounds You Have Played

Medium
56.8%
Updated 6/1/2025

Asked by 2 Companies

The Number of Full Rounds You Have Played

What is this problem about?

Time management logic is crucial for many applications, from gaming to scheduling. "The Number of Full Rounds You Have Played" asks you to calculate how many complete 15-minute rounds of a game occurred between a start time and an end time. A full round starts at :00, :15, :30, or :45 of an hour and lasts exactly 15 minutes. For example, if you start at 12:01 and end at 12:44, you only completed one full round (12:15 to 12:30). If the end time is earlier than the start time, it's assumed you played through midnight into the next day.

Why is this asked in interviews?

This the Number of Full Rounds You have Played interview question is used by companies like Microsoft to test a candidate's ability to handle time-based arithmetic and boundary rounding. It requires converting string-based time formats into a numerical representation (like total minutes from midnight) and carefully adjusting the start and end points to align with the 15-minute boundaries. It also tests logic for handling wrap-around cases (midnight).

Algorithmic pattern used

The problem falls under the Math, String interview pattern.

  1. Convert the startTime and finishTime into total minutes from the start of the day (HH * 60 + MM).
  2. If the finishTime is less than startTime, add 1440 minutes (one full day) to the finishTime.
  3. Round the startTime up to the next 15-minute mark.
  4. Round the finishTime down to the previous 15-minute mark.
  5. The number of rounds is max(0, (roundedFinish - roundedStart) // 15).

Example explanation

Start: 12:05, Finish: 12:50.

  1. Start Minutes: 1260 + 5 = 725. Finish Minutes: 1260 + 50 = 770.
  2. Round start 725 up to 735 (which is 12:15).
  3. Round finish 770 down to 765 (which is 12:45).
  4. Rounds: (765 - 735) / 15 = 30 / 15 = 2. The full rounds were 12:15-12:30 and 12:30-12:45.

Common mistakes candidates make

In "The Number of Full Rounds You have Played coding problem," many candidates fail to handle the midnight wrap-around correctly. Another frequent mistake is rounding the start time down and the end time up, which would count partial rounds. Finally, forgetting to handle the case where the rounded start becomes later than the rounded finish (resulting in 0 rounds) can lead to negative results.

Interview preparation tip

When working with time, converting everything to a single unit (like minutes or seconds) is almost always the best first step. It simplifies the math significantly compared to working with hours and minutes separately. Practice rounding numbers to arbitrary intervals (like 15 or 30) using the modulo operator.

Similar Questions