Minimum Weighted Manhattan Travel Cost
Updated
Problem statement
You are given three equal-length arrays x, y, and people. Location i is the integer coordinate (x[i], y[i]) and contains people[i] people.
Choose any integer meeting coordinate (meetingX, meetingY). Its total travel cost is:
sum(people[i] * (abs(meetingX - x[i]) + abs(meetingY - y[i]))).
Return the minimum possible total travel cost. If several coordinates are optimal, only the minimum cost matters.
Function
minWeightedTravelCost(x: int[], y: int[], people: int[]) → longExamples
Example 1
x = [0,4]y = [0,0]people = [1,1]return = 4Any meeting x-coordinate from 0 through 4 with y-coordinate 0 has total cost 4.
Example 2
x = [0,10,20]y = [0,0,10]people = [1,3,1]return = 30The weighted medians are meetingX = 10 and meetingY = 0. The three weighted costs are 10, 0, and 20.
Example 3
x = [-2,3]y = [5,-1]people = [4,1]return = 11The higher-weight first location is an optimal meeting coordinate. The second group travels 5 horizontal and 6 vertical units.
Constraints
1 <= x.length == y.length == people.length <= 100000-1000000 <= x[i], y[i] <= 10000001 <= people[i]sum(people) <= 1000000000- The answer fits in a signed 64-bit integer.
More Concentric AI interview questions
- Kth Greater Element Index to the RightOA · Seen Sep 2026
- Find the Intersection Node of Two Linked ListsOA · Seen Sep 2026
- Count Students Outside Their Sorted PositionsOA · Seen Aug 2026
- Maximum Profit Under a Bitwise OR LimitOA · Seen Aug 2026
- Rearrange a Linked List from Alternating EndsONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Non-Maximum SuppressionWayve · PHONE SCREEN
- Hiking Club Fastest PaceInfosys · OAInfosys interview questions
- Request Routing SystemStripe · OAStripe interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions