1478. Allocate Mailboxes
Previous1477. Find Two Non-overlapping Sub-arrays Each With Target SumNext1479. Sales by Day of the Week
Last updated
Last updated
**Input:** houses = [1,4,8,10,20], k = 3
**Output:** 5
**Explanation:** Allocate mailboxes in position 3, 9 and 20.
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
**Input:** houses = [2,3,5,12,18], k = 2
**Output:** 9
**Explanation:** Allocate mailboxes in position 3 and 14.
Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.
**Input:** houses = [7,4,6,1], k = 1
**Output:** 8
**Input:** houses = [3,6,14,10], k = 4
**Output:** 0