It was asked by a interviewer.
The target is to Design a train tickets Reservation system. If the train go through 5 stations(e.g. A,B,C,D,E). We could sell tickets from A-E or A-B, if a ticket from A-B is sold, we could go on sell tickets between B-E.
The question is which data structure is suitable to present the seats? It should show which section is available for sale.
Thanks for help!
Best How To :
To be quite honest, "that interviewer's question, at least as it has been presented by you, makes very little sense." (Maybe the interviewer provided more details at-the-time that you have since forgotten.)
But the basic idea should be: "what is the fact that you need to represent?" Well, in this case, the "fact" is that
this_train, has a
ticket to go
to_station B ... where "A" and "B" are enumerations such that you can easily determine when two stations "overlap."
From this, you can then proceed to define the various "bright-line rules" that the reservation system must be able to apply. For instance: "how many existing reservations overlap a certain range-of-stops?" (This will allow you to determine if the seat-capacity of the train would be exceeded.)