Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Last active April 2, 2026 12:26
Show Gist options
  • Select an option

  • Save UltiRequiem/8d977e002028b0c23a0e45ed1f976b21 to your computer and use it in GitHub Desktop.

Select an option

Save UltiRequiem/8d977e002028b0c23a0e45ed1f976b21 to your computer and use it in GitHub Desktop.
Technical Challenge

Leave Balance Calculation Challenge

Overview

Tilt works by tracking how much time off an employee has taken. In this exercise an employee may take a maximum of 12 weeks of leave per 12-month period.

Your task is to calculate the number of remaining leave hours from the initial 12-week allocation, using the provided as_of_date.

Tracking Methods

The 12-month period is determined by a given tracking_method.

1. "calendar"

The period is January 1 through December 31 of the year containing the as_of_date.

2. "fixed"

The period begins on the date the employee was hired and resets every 12 months.

Rules and Assumptions

  • An employee can take a total of 12-weeks of leave per 12-month period.
  • The employee works 40 hours per week (Monday–Friday).
  • Leave is taken in full weeks only.
  • Each LeaveEvent represents one or more full weeks.
  • Each LeaveEvent is in a single 12-month period and will not cross into the next period.
  • Ignore holidays.
  • All dates are valid and formatted %Y-%m-%d.

Main Task

Implement the calendar tracking method inside:

calculate_remaining_fmla_hours(as_of_date: str) -> float

The function must:

  1. Count leave used within that period up to and including as_of_date
  2. Return remaining hours

Followup Task

Once the calendar method is working, add support for the fixed method inside calculate_remaining_fmla_hours

#!/bin/python3
from datetime import date
class Employee:
def __init__(self, start_date_str):
self.start_date = date.fromisoformat(start_date_str)
class LeaveEvent:
def __init__(self, employee, start_date_str, end_date_str):
self.employee = employee
self.start_date = date.fromisoformat(start_date_str)
self.end_date = date.fromisoformat(end_date_str)
class FMLATracker:
def __init__(self, tracking_method, employee, leave_events):
self.tracking_method = tracking_method
self.employee = employee
self.leave_events = leave_events
@staticmethod
def get_date_difference_days(date_from, date_to):
return (date_to - date_from).days
def calculate_remaining_fmla_hours(self, as_of_date_str):
as_of_date = date.fromisoformat(as_of_date_str)
as_of_date_year = as_of_date.year
employee_start_date = self.employee.start_date
cecs = date(as_of_date_year, employee_start_date.month, employee_start_date.day)
cece = date(
as_of_date_year + 1,
employee_start_date.month,
employee_start_date.day,
)
total_starting_time = 12 * 40
weeks_taked = 0
for leave in self.leave_events:
if leave.start_date >= as_of_date:
continue
if (
self.tracking_method == "calendar"
and as_of_date_year != leave.start_date.year
):
continue
if self.tracking_method == "fixed" and (
leave.start_date <= cecs or leave.end_date >= cece
):
continue
days_taked = FMLATracker.get_date_difference_days(
leave.start_date, leave.end_date
)
weeks_taked += (days_taked + 1) / 7
total_taked_time = weeks_taked * 40
return total_starting_time - total_taked_time
if __name__ == "__main__":
scenarios = [("fixed", 120.0), ("calendar", 40.0)]
as_of_date_str = "2021-12-01"
employee = Employee("2020-03-01")
leave_events = [
LeaveEvent(employee, "2020-07-05", "2020-07-18"),
LeaveEvent(employee, "2021-02-07", "2021-02-20"),
LeaveEvent(employee, "2021-04-04", "2021-04-24"),
LeaveEvent(employee, "2021-08-01", "2021-09-11"),
]
for scenario in scenarios:
tracking_method, expected = scenario
tracker = FMLATracker(
tracking_method,
employee,
leave_events,
)
result = tracker.calculate_remaining_fmla_hours(as_of_date_str)
if result != scenario[1]:
status_message = "FAILED CASE"
else:
status_message = "SUCCESSFUL CASE"
print(
f"{status_message}\n"
f"Tracking Method: {tracking_method}\n"
f"Expected: {expected}\n"
f"Actual: {result}\n"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment