Sponsored
Use these hints if you're stuck. Try solving on your own first.
Each bag will contain a sub-array.
Only the endpoints of the sub-array matter.
Try to use a priority queue.
Solve with full IDE support and test cases