Allocate Mailboxes
Updated
Problem statement
Houses stand at the integer positions in houses along one street. Install exactly k mailboxes at integer positions so that the sum of every house's distance to its nearest mailbox is as small as possible.
Return that minimum total distance.
Function
minMailboxDistance(houses: int[], k: int) → intExamples
Example 1
houses = [5,10,15,20]k = 3return = 5Mailboxes at 5, 10, and any median position between 15 and 20 give total distance 5.
Example 2
houses = [6,7,8,12]k = 2return = 2Positions 7 and 12 serve the houses with total distance 2.
Constraints
1 <= houses.length <= 100.1 <= k <= houses.length.- House positions are distinct integers between 1 and 10000.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Allocate Mailboxes with Squared DistanceLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Minimum Total Waiting Time for One ElevatorExpedia · ONSITE INTERVIEWExpedia interview questions
- Maximum Length Pair ChainAmazon · ONSITE INTERVIEW
- Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
- Minimum Cost to Select People for Skill QuotasVisa · OAVisa interview questions
- Cheapest Order to Cut a RodAdobe · PHONE SCREENAdobe interview questions
- Maximum Order VolumeSnowflake · OASnowflake interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)