Need help in set.

Given a set of pairs. Each pair represent a range of numbers.

Example : (5, 8) represents {5, 6, 7, 8}.

I want to find in which pair an element x is present, it is sure that element x exits in at least one pair?

Can this be solved in logarithmic time? Thanks in advance!

There must be some other constraints too else this would be a very easy problem.Just take min and max value of the set.That would be your answer.

β€œCan this be solved in logarithmic time?”
This is the constraint I guess.

is there are overlapping pairs?

Sort, join overlapping pairs, binary search.

Can you please paste the exact link of question? It will help us to sort out weather it is genuine question or it is not taken from any ongoing contest.

1 Like