Minimum Markers to Clear Line Segments
Updated
Problem statement
You are given two integer arrays startX and endX of equal length. Pair i describes one closed line segment on the X-axis.
Normalize each pair before using it:
- The segment's left endpoint is
min(startX[i], endX[i]). - The segment's right endpoint is
max(startX[i], endX[i]).
Placing a marker at an X-axis coordinate clears every remaining segment that contains that coordinate, including segments that meet it at an endpoint.
Return the minimum number of marker placements needed to clear all segments. Return 0 when both arrays are empty.
Function
markerPlaced(startX: int[], endX: int[]) → intExamples
Example 1
startX = [0, 2, 4, -8]endX = [4, 5, 8, -9]return = 2The normalized segments are [0, 4], [2, 5], [4, 8], and [-9, -8].
A marker at 4 clears the first three segments. A second marker at either -9 or -8 clears the remaining segment. No single coordinate belongs to both the negative segment and the three nonnegative segments, so the minimum is 2.
Constraints
0 <= startX.length = endX.length <= 10^4-10^9 <= startX[i], endX[i] <= 10^9- Every endpoint is an integer.
More HSBC Online Assessment questions
- Organization Reputation After Employee DeparturesOA · Seen Nov 2026
- Remove Vowels from a StringOA · Seen Nov 2026
- Minimum Deletion Cost for Distinct Adjacent CharactersOA · Seen Oct 2026
- Distinct Products After Removing One ElementOA · Seen Sep 2026
- Minimum Cleaning Robot RunsOA · Seen Sep 2026
- Minimum Satellite Data Transfer IterationsOA · Seen Aug 2026
- Find ID of SoldierOA · Seen Jun 2026
- Find Most Frequently Purchased ProductsOA · Seen Jun 2026
- Arrange Flower SticksOA · Seen Mar 2025
- Find Largest House AreaOA · Seen Mar 2025
Similar questions at other companies
- Maximum Compatible Time WindowsIBM · OAIBM interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Most Disjoint Intervals From Starts and DurationsDocuSign · OADocuSign interview questions
- University Career FairRoblox · OARoblox interview questions
- Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Appointment Cancellations with a Required BreakMaven Clinic · PHONE SCREENMaven Clinic interview questions
- Minimum Removals for Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions