PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement accurate time-based payroll calculations, covering interval arithmetic, proportional pay for partial hours, handling edge cases in start/end times, and designing caching or preprocessing to support repeated cutoff queries.

  • medium
  • Rippling
  • Coding & Algorithms
  • Software Engineer

Compute total wages and partial-hour payments

Company: Rippling

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a list of workers. Each worker has: - `id` (string) - `hourly_rate` (non-negative number) - one work shift for a given day: `start_time`, `end_time` (times such as `"12:00"`, `"22:00"` in 24-hour format) Assume times are within the same day and `end_time > start_time` (no overnight shifts). Pay is proportional to time worked. ### Part 1 — Total payroll for full shifts Write a function that computes the **total amount of money** paid to all workers for their full shifts. **Input:** list of workers **Output:** total pay (number) ### Part 2 — Payroll up to a cutoff time (partial shifts) Write a second function to compute how much to pay workers **up to a given cutoff time** `cutoff_time`. Rules: - If a worker’s shift ends **at or before** `cutoff_time`, pay their full shift. - If a worker’s shift starts **at or after** `cutoff_time`, pay **0**. - If a worker’s shift overlaps the cutoff (e.g., works `12:00–22:00` and cutoff is `17:00`), include only the portion worked **from `start_time` up to `cutoff_time`**. **Input:** list of workers, `cutoff_time` **Output:** total pay up to cutoff (number) ### Follow-up — Caching / avoiding recomputation If this function is called repeatedly for many different cutoff times, describe (at a high level, in code structure or data structures) how you would **cache or preprocess** information to avoid recomputing from scratch each time. (You do not need to use any specific library; just clearly define the approach and expected time/space tradeoffs.)

Quick Answer: This question evaluates a candidate's ability to implement accurate time-based payroll calculations, covering interval arithmetic, proportional pay for partial hours, handling edge cases in start/end times, and designing caching or preprocessing to support repeated cutoff queries.

Part 1: Total Payroll for Full Shifts

You are given a list of workers for a single day. Each worker is represented by a dictionary with these keys: 'id', 'hourly_rate', 'start_time', and 'end_time'. Times are strings in 24-hour "HH:MM" format, all shifts stay within the same day, and end_time is always later than start_time. Pay is proportional to time worked, including partial hours. Write a function that returns the total amount paid to all workers for their full shifts.

Constraints

  • 0 <= len(workers) <= 200000
  • Each time is a valid 24-hour string in "HH:MM" format
  • All shifts are within the same day and satisfy start_time < end_time
  • 0 <= hourly_rate <= 1000000
  • Times are precise to the minute

Examples

Input: ([{'id': 'A', 'hourly_rate': 10, 'start_time': '09:00', 'end_time': '17:00'}, {'id': 'B', 'hourly_rate': 15, 'start_time': '12:00', 'end_time': '16:00'}],)

Expected Output: 140.0

Explanation: Worker A earns 10 * 8 = 80. Worker B earns 15 * 4 = 60. Total = 140.

Input: ([{'id': 'W1', 'hourly_rate': 20, 'start_time': '09:30', 'end_time': '11:00'}],)

Expected Output: 30.0

Explanation: The shift is 90 minutes, or 1.5 hours. Pay = 20 * 1.5 = 30.

Input: ([],)

Expected Output: 0.0

Explanation: No workers means no payroll.

Input: ([{'id': 'M', 'hourly_rate': 60, 'start_time': '00:00', 'end_time': '00:01'}],)

Expected Output: 1.0

Explanation: One minute at 60 per hour costs 1 dollar.

Hints

  1. Convert each time string into minutes since midnight so duration becomes easy to compute.
  2. For one worker, pay = hourly_rate * worked_minutes / 60.

Part 2: Payroll Up to a Cutoff Time

You are given a list of workers for a single day and a cutoff time. Each worker has 'id', 'hourly_rate', 'start_time', and 'end_time'. Compute how much money should be paid up to the cutoff time. Rules: - If a worker's shift ends at or before the cutoff, pay the full shift. - If a worker's shift starts at or after the cutoff, pay 0. - If a worker's shift overlaps the cutoff, pay only for the time from start_time up to cutoff_time. All times are in 24-hour "HH:MM" format, shifts do not cross midnight, and end_time is always later than start_time.

Constraints

  • 0 <= len(workers) <= 200000
  • Each time is a valid 24-hour string in "HH:MM" format
  • All worker shifts are within one day and satisfy start_time < end_time
  • 0 <= hourly_rate <= 1000000
  • Times are precise to the minute

Examples

Input: ([{'id': 'A', 'hourly_rate': 10, 'start_time': '09:00', 'end_time': '17:00'}, {'id': 'B', 'hourly_rate': 20, 'start_time': '12:00', 'end_time': '15:00'}, {'id': 'C', 'hourly_rate': 30, 'start_time': '14:00', 'end_time': '18:00'}], '13:00')

Expected Output: 60.0

Explanation: A is paid for 4 hours = 40. B is paid for 1 hour = 20. C has not started yet. Total = 60.

Input: ([{'id': 'A', 'hourly_rate': 25, 'start_time': '08:00', 'end_time': '10:00'}, {'id': 'B', 'hourly_rate': 40, 'start_time': '10:15', 'end_time': '11:15'}], '12:00')

Expected Output: 90.0

Explanation: The cutoff is after both shifts end, so both workers receive full pay: 50 + 40 = 90.

Input: ([{'id': 'A', 'hourly_rate': 30, 'start_time': '09:00', 'end_time': '11:00'}, {'id': 'B', 'hourly_rate': 20, 'start_time': '10:00', 'end_time': '12:00'}], '09:00')

Expected Output: 0.0

Explanation: A starts exactly at the cutoff, so gets 0. B starts after the cutoff, so also gets 0.

Input: ([{'id': 'A', 'hourly_rate': 24, 'start_time': '09:15', 'end_time': '10:45'}], '10:00')

Expected Output: 18.0

Explanation: Only 45 minutes are paid. 24 * 45 / 60 = 18.

Input: ([], '17:00')

Expected Output: 0.0

Explanation: No workers means the partial payroll is 0.

Hints

  1. For each worker, the paid duration is the overlap between [start_time, end_time) and all time before cutoff_time.
  2. A compact formula is: max(0, min(end, cutoff) - start).

Part 3: Efficient Payroll Queries for Many Cutoff Times

You are given a list of workers for a single day and many cutoff time queries. For each cutoff time, compute the total payroll paid up to that time using the same rules as the partial-shift problem: - pay the full shift if it ends at or before the cutoff, - pay 0 if it starts at or after the cutoff, - otherwise pay only the portion from start_time up to the cutoff. A naive solution that scans every worker for every query may be too slow. Implement an efficient solution that preprocesses the day's data and returns the payroll for all cutoff times in the original query order. All times are in 24-hour "HH:MM" format, shifts stay within the same day, and time precision is one minute.

Constraints

  • 0 <= len(workers) <= 200000
  • 0 <= len(cutoff_times) <= 200000
  • Each time is a valid 24-hour string in "HH:MM" format
  • All worker shifts are within one day and satisfy start_time < end_time
  • 0 <= hourly_rate <= 1000000
  • Times are precise to the minute

Examples

Input: ([{'id': 'A', 'hourly_rate': 10, 'start_time': '09:00', 'end_time': '12:00'}, {'id': 'B', 'hourly_rate': 20, 'start_time': '10:00', 'end_time': '11:00'}], ['08:00', '10:00', '10:30', '12:00'])

Expected Output: [0.0, 10.0, 25.0, 50.0]

Explanation: At 08:00 nobody has worked. At 10:00 only A has worked 1 hour. At 10:30 A has worked 1.5 hours and B has worked 0.5 hours. At 12:00 both full amounts are included.

Input: ([{'id': 'A', 'hourly_rate': 24, 'start_time': '09:15', 'end_time': '10:45'}, {'id': 'B', 'hourly_rate': 60, 'start_time': '10:00', 'end_time': '10:30'}], ['09:15', '10:00', '10:15', '11:00'])

Expected Output: [0.0, 18.0, 39.0, 66.0]

Explanation: The answers reflect cumulative pay at each cutoff, including partial overlap for both workers.

Input: ([], ['00:00', '23:59'])

Expected Output: [0.0, 0.0]

Explanation: With no workers, every query returns 0.

Input: ([{'id': 'A', 'hourly_rate': 60, 'start_time': '00:00', 'end_time': '00:01'}, {'id': 'B', 'hourly_rate': 120, 'start_time': '23:58', 'end_time': '23:59'}], ['00:00', '00:01', '23:58', '23:59'])

Expected Output: [0.0, 1.0, 1.0, 3.0]

Explanation: The first worker contributes 1 dollar by 00:01. The second contributes 2 more dollars by 23:59, for a total of 3.

Hints

  1. Think of each worker as adding a constant dollar-per-minute contribution on every minute from start_time up to, but not including, end_time.
  2. Use a difference array over the 1440 minutes of the day, then prefix sums to answer each query in O(1).
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Searchable Logger Pipeline - Rippling (hard)
  • Implement an In-Memory File System - Rippling
  • Compare Complete and Partial Poker Hands - Rippling (medium)
  • Implement Courier Delivery Cost Tracking - Rippling (medium)
  • Implement Article Vote Tracking - Rippling (medium)