Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Easy to Medium Coding Practice

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

Your question is Easy to Medium Coding Practice. 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

FedEx Ground loads packages in a fixed order and must ship them over a given number of days. Given the package weights and the number of available days, find the minimum truck capacity that allows all packages to be shipped within the deadline.

Packages cannot be reordered, and each day's shipment must consist of a contiguous portion of the input list. A day may contain multiple packages as long as their total weight does not exceed the truck capacity.

Formal Specification

Implement ship_packages(weights, days), where weights is a list of positive integers representing package weights and days is a positive integer. Return the smallest integer capacity that can ship every package within days days.

Constraints

  • 1 <= len(weights) <= 5 * 10^4
  • 1 <= weights[i] <= 500
  • 1 <= days <= len(weights)
  • Package order must be preserved
  • Every package must be shipped exactly once

Function Signature

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