One of the streets in your city has a total of L street lights.Each light i covers the street from Xi to Yi distance.Find the length of street covered with light.

 One of the streets in your city has a total of L street lights.Each light i covers the street from Xi to Yi distance.Find the length of street covered with light.

Input details:

input1: Denoting the number of street lights.

input2 : An array of L*2 elements.For each row i,(Xi,Yi) denote that the street light i covers the distance from Xi to Yi.

Output Deatils:

Your Function should return the length of the street covered with light.

Example 1:

input1:1

input2:{{5,10}}

Output: 5

Example 2:

input1: 2

input2: {{5,10},{8,12}}

Output : 7

Explanation 1:

Street light 1: 10-5=5 units covered

Explanation 2:

Street light 1: 10-5=5 units covered

Street light 2: 12-8=4 units covered

Common region = 10-8 =2 units

Total = 5+4-2 =7

For the above problem the java code is given below:


0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post