Relocate Retailers

Relocate Retailers

There are n merchants, each operating within a designated geographical range. The operating zone of merchant i is defined by the interval spanning from zoneStart[i] to zoneEnd[i].
A set of k merchants is termed cohesive (inclusive) if there exists at least one merchant whose operational territory overlaps with (or touches) all the other (k-1) merchants’ operational zones.
The marketplace plans to relocate some merchants to new areas. Your goal is to determine the minimum number of merchants that need to be moved so that the remaining merchants form a cohesive subset.

Input:
minimumRetailers has the following parameters:
int zoneStart[n]: the left ends of the operating regions
int zoneEnd[n]: the right ends of the operating regions
Output:
Return the smallest number of merchants that need to be relocated

Example1:
Input: zoneStart = [1, 3, 4, 6, 9], zoneEnd = [2, 8, 5, 7, 10]
Output: 2
Explanation:
Retailer 1 ranges from 1 to 2.
Retailer 5 ranges from 9 to 10.
Retailers 2, 3, and 4 already are inclusive.
Move retailers 1 and 5 to intersect with Retailer 2's region.
The minimum number of retailers to relocate is 2.

Example2:
Input: zoneStart = [1, 2, 3, 4], zoneEnd = [2, 3, 5, 5]
Output: 1
Explanation:
Region 1 (1, 2) intersects only region 2. (move regions 3 and 4)
Region 2 (2, 3) intersects regions 1 and 3. (move region 4)
Region 3 (3, 5) intersects regions 2 and 4. (move region 1)
Region 4 (4, 5) intersects region 3. (move regions 1 and 2)
The minimum number of moves is 1, moving region 1 or 4

Constraints
1 ≤ n ≤ 10^5
1 ≤ zoneStart[i] ≤ zoneEnd[i] ≤ 10^9 (1 <= i < n)
All regions have regions with the same start and end points.



Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.