I was posed this question at an interview and never really came up with a great solution. Does anyone have an "optimum" solution? Where the target is efficiency and being able to deal with large input.
Material Provided:
I am given a long list of shops and their opening/closing times (say 1000).
The Problem:
For a given time of day, return how many of the shops are open
Example Data:
Sainsburys 10:00 23:00
Asda 02:00 18:00
Walmart 17:00 22:00
Example In/Out
Input | Output
12:00 | 2
22:00 | 1 (walmart shut @ 22:00)
17:30 | 3
The two parts of the problem are how to store the data and how to efficiently get the answer, I guess how you're reading the input etc doesn't really matter.
Thanks for your time and insight!