Sunday, March 4, 2012

Pairs have gaps or not

You will be given pairs.. you need to see whether they have any gaps..
 
ex1: max no:20
pairs: 11-15, 0-5, 18-20, 14-19, 6-13

You can think pairs are like intervals..the above has no gaps..
because 0-5,6-13,11-15,18-20 have all numbers from 0 (min) to 20(max)

ex2: 11-15, 0-5, 18-20, 14-16, 6-13

this have gap as the intervals miss a number from 0 to 20 i.e.,17

Suggest some algorithm...which requires less movement of data as each pair 
is stored in a row in a database..

No comments:

Post a Comment