How to solve this question. Asked in Infosys

48
Apr 10, 2024
Apr 10, 2024

You are given the arrival and leaving times of N trains in Arr. This means that the ith train arrives at the moment Li and leaves at R

It is given that there are an infinite number of stations on which the train. can stop. Every train will stop at the first empty station.

The stations are designed such that if a train is leaving the station at a given moment, another train can immediately arrive at the station at the same moment without any issues. It is given that a train will stop at the first empty station it encounters.

Let N= 3 and the trains stop at stations A, B, and C respectively. Then, the value K=A+B+C.

Find the value K for the N trains in Arr. Since, the answer can be large return it modulo 10^9+7.

tations are 0-indexed and numbered

Input Format
The first line contains an integer, N. denoting the number of rows in An

Each line i of the N subsequent lines where Os i < N) contains 2 space separated integers each describing the row Arri

The 2 space separated integers in row Arril denote Li] and [Ril respectively

Constraints

1 Nx 10^5

Sample
2 5
1 4

Output
4

Explanation
N=3
Αrr= [[2, 5], [1, 4], [4, 6]]

The first train will arrive on the first second, and it will stop on the first railway.

The second train will arrive on the second, it will stop on the second railway.

On the fourth second, the first arrival train will leave then the last train arrive and it will stop on the first railway.

The sun of railways is: 2+1+1 = 4.

Comments (1)