Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Solve Task Completion with Engineers

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Solve Task Completion with Engineers. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

PhonePe needs to complete n independent tasks using m engineers. Engineer i has power powers[i]. If that engineer completes k tasks, the total time spent is powers[i] * (1 + 2 + ... + k) days. Tasks assigned to the same engineer are completed sequentially, while all engineers work in parallel.

Return the minimum number of days required to complete at least n tasks.

Formal Specification

Implement min_days(n, powers):

  • Input: integer n, the number of tasks, and an integer array powers, where powers[i] is the time multiplier for engineer i.
  • Output: an integer representing the minimum calendar days needed to complete all tasks.

For a candidate duration d, engineer i can complete the largest k satisfying powers[i] * k * (k + 1) / 2 <= d. Use this relationship to test feasibility efficiently.

Constraints

  • 1 <= n <= 10^9
  • 1 <= len(powers) <= 10^5
  • 1 <= powers[i] <= 10^6
  • Engineers may receive zero tasks

Function Signature

def min_days(n, powers):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output