Algorithm
There is a rope on which you will put clothes to dry. And each cloth is of different length and their starting position on the cloth is also different. Once all the clothes are put on the rope. we have to find out how many clothes are visible if i look it from top.
You are given two inputs.
1. length of the rope
2. And a list of Cloth Objects.
List<Cloth>
Cloth class is defined like this
class Cloth{
int initial Position,
int clothLength
}
for example if i am given rope length of 7
and List of cloth objects which has 3 Cloth Objects C1, C2, C3
C1.initialPosition = 0
C1.clothLength = 5(this cloth will cover from 0 to 5)
C2.initialPosition = 2
C2.clothLength = 2 (this cloth will cover from 2 to 4. since length of cloth =2)
C3.initialPosition = 1
C3.clothLength = 5 (this cloth will cover from 1 to 6. since length of cloth =5)
So with this. we can only see Cloth 1 and Cloth 3. So the output should be 2
Imagine the rope like this.
|........|.........|.........|..........|..........|...........|...........|
0 1 2 3 4 5 6 7