Minimum Segments
Learn this problemProblem statement
Given is an array consisting of n intervals. The ith interval is of type
(a[i], b[i]). Also given is an integer k. Add exactly one segment
(a, b) to the array such that b - a ≤ k and the modified array can
be separated into the minimum number of connected sets.
A set of segments (a[1], b[1]), (a[2], b[2]), ...,
(a[n], b[n]) is connected if every point in the segment
(min(a[1], a[2], ..., a[n]), max(b[1], b[2], ..., b[n])) is covered by some segment
(a[i], b[i]) in the set.
Function
minimumDivision(a: int[], b: int[], k: int) → int
Complete the function minimumDivision in the editor.
minimumDivision has the following parameters:
- 1.
int a[n]: an integer array of first parameters of intervals - 2.
int b[n]: an integer array of second parameters of intervals - 3.
k: an integer denoting the maximum range of the segment that can be added
Returns
int: an integer denoting the minimum number of sets needed to separate the array after adding one segment.
Examples
Example 1
a = [1, 2, 5, 10]b = [2, 4, 8, 11]k = 2return = 2Constraints
- 1 ≤ n ≤ 2 * 105
- 1 ≤ a[i] ≤ b[i] ≤ 109
- 1 ≤ k ≤ 109
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026