Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Race in Fooland
Easy Accuracy: 0.0% Submissions: 3 Points: 2

Fooland city has a special multi-lane running track. Lanes are numbered from 1 to Tracks. The lanes have N horizontal barriers lying on it (due to some digging and construction work). The ith barrier cover lanes from Li1 to Li2 (both inclusive). Also, the barriers may overlap. The athletes can’t run on the lanes on which barriers are present because they aren’t allowed to switch lanes anytime in the race. (Once a particular lane is allotted to an athlete he/she can’t switch his/her lane anytime during the race and there can be only one athlete on each lane.)

Now the race has to be organised tomorrow itself and the digging work could not be finished on time. The race would have to be organised on the same track only because Fooland city doesn’t have any other track. Help organizers in finding out how many athletes can run in a single race so that none of them would have to switch lanes.

Example 1:

Input:
N = 5, Track = 20
Li = {(1 3), (5 8), (8 13),
(14 15), (9 12)}

Output:
6

Explanation:
The barriers cover lanes from
1 to 3, 5 to 8, 8 to 13,
14 to 15 and 9 to 12. Hence,
barriers are present on the
lanes: {1, 2, 3, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15}.

Hence, the lanes which doesn't
come under any barriers are
{4, 16, 17, 18, 19, 20}.
So, there are 6 lanes on which
athletes can run – {4, 16, 17,
18, 19, 20}


You don't need to read input or print anything. Your task is to complete the function emptyLanes() which takes the pair array A[], its size N and an integer Tracks as inputs and returns the number of athletes that can run in a single track.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 106
1 ≤ Tracks ≤ 106
1 ≤ Li1 ≤ Li2 ≤ Tracks
The Barriers may overlap.