1478. Allocate Mailboxes

https://leetcode.com/problems/allocate-mailboxes

Description

Given the array houses and an integer k. where houses[i] is the location of the ith house along a street, your task is to allocate k mailboxes in the street.

Return the minimum total distance between each house and its nearest mailbox.

The answer is guaranteed to fit in a 32-bit signed integer.

Example 1:

Example 2:

Example 3:

Example 4:

Constraints:

  • n == houses.length

  • 1 <= n <= 100

  • 1 <= houses[i] <= 10^4

  • 1 <= k <= n

  • Array houses contain unique integers.

ac

Last updated

Was this helpful?