PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

Find minimal time to serve customers evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • Medium
  • Pinterest
  • Coding & Algorithms
  • Software Engineer

Find minimal time to serve customers

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You manage a bank with k tellers; teller i takes serviceTimes[i] minutes to serve one customer and works continuously. Given an integer array serviceTimes and an integer m (customers to serve), return the minimum integer time T such that sum over i of floor(T / serviceTimes[i]) >= m. Describe your algorithm, prove correctness, analyze time/space complexity, and implement it. Discuss edge cases (very large m, slow tellers, identical rates).

Quick Answer: Find minimal time to serve customers evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

You manage a bank with `k` tellers. Teller `i` takes `serviceTimes[i]` minutes to serve one customer and works continuously without breaks. Given the integer array `serviceTimes` and an integer `m` (the number of customers that must be served), return the minimum integer time `T` such that the total number of customers served by all tellers within `T` minutes is at least `m`. Formally, return the smallest integer `T` with `sum over i of floor(T / serviceTimes[i]) >= m`. Within `T` minutes, teller `i` can serve `floor(T / serviceTimes[i])` customers. As `T` increases the total served is non-decreasing, so the predicate `served(T) >= m` is monotone and the answer can be found with binary search on `T`. A safe upper bound is `min(serviceTimes) * m`, because the single fastest teller alone serves `m` customers by that time. Example: `serviceTimes = [1, 2, 3]`, `m = 5`. At `T = 3` the tellers serve `3 + 1 + 1 = 5 >= 5`, while at `T = 2` they serve `2 + 1 + 0 = 3 < 5`, so the answer is `3`.

Constraints

  • 1 <= k = serviceTimes.length
  • 1 <= serviceTimes[i] (each teller's per-customer time is a positive integer)
  • 1 <= m (at least one customer must be served)
  • The answer T can be large; use 64-bit integers in Java/C++ (min(serviceTimes) * m may exceed 32-bit range for very large m).

Examples

Input: ([1, 2, 3], 5)

Expected Output: 3

Explanation: At T=3: 3//1 + 3//2 + 3//3 = 3+1+1 = 5 >= 5. At T=2 it is only 3, so 3 is minimal.

Input: ([2], 1)

Expected Output: 2

Explanation: Single teller needs 2 minutes to serve the one required customer.

Input: ([5, 10, 10], 9)

Expected Output: 25

Explanation: At T=25: 25//5 + 25//10 + 25//10 = 5+2+2 = 9 >= 9. At T=24 it is 4+2+2 = 8 < 9.

Input: ([1, 1, 1], 6)

Expected Output: 2

Explanation: Identical rates: at T=2 each serves 2, total 6 >= 6; at T=1 total is 3 < 6.

Input: ([7], 1000000)

Expected Output: 7000000

Explanation: Large-m stress: one teller at 7 min/customer needs 7*1000000 minutes for 1,000,000 customers.

Input: ([3, 3, 3], 1)

Expected Output: 3

Explanation: Boundary m=1: any teller serves its first customer at T=3, so the minimum is 3.

Hints

  1. The number of customers served by time T, sum(floor(T / serviceTimes[i])), only grows as T grows. This monotonicity is exactly what binary search needs.
  2. Binary search on the answer T rather than on an index. The predicate is `served(T) >= m`; find the smallest T where it becomes true.
  3. A correct upper bound is min(serviceTimes) * m: by that time the single fastest teller alone has already served m customers, so the predicate is guaranteed true.
  4. Watch the integer range: with large m, min(serviceTimes) * m can overflow 32-bit integers. Use long in Java and long long in C++.
Last updated: Jun 26, 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

  • First Word Matching Each Prefix Query - Pinterest (medium)
  • Hierarchical Access Control for an Advertising Platform - Pinterest (medium)
  • Maximize Boxes Stored Through One Entrance - Pinterest (medium)
  • Solve Multiple Coding Interview Problems - Pinterest (medium)
  • Implement a Sparse Matrix Class - Pinterest (medium)