Hi Ashish ,
1. I have used a helper column , column E.
In E4 , enter the formula =D4-C4+1
Copy down.
2. I have put in the outputs in columns J and K. The formulae are different for the first row and thereafter.
In J4 , enter the formula =B4
In K4 , enter the formula =C4
3. In the second row , enter the following formulae :
J5
=IFERROR(IF(INDEX($E$4:$E$7,MATCH(J4,$B$4:$B$7,0))>COUNTIF(J$4:J4,J4),J4,INDEX($B$4:$B$7,MATCH(J4,$B$4:$B$7,0)+1)),"")
K5
=IF(J5="","",IF(J5<>J4,INDEX($C$4:$C$7,MATCH(J5,$B$4:$B$7,0)),K4+1))
Copy down as far as required.
Narayan