10. Design a Movie ticket booking system like BookMyShow

Observer design pattern can be used to solve this question.


Design a Movie ticket booking system like BookMyShow
1. Simple Solution:    Complete Code

Write code for low level design (object oriented design) of a movie ticket booking system like BookMyShow.
System has cinemas located in different cities. Each cinema will have multiple screens, and users can book one or more seats in given movie show.

System should be able to add new cinemas and movie shows in those cinemas.
Users should be able to list all cinema's in their city which are displaying a particular movie.
For a given cinema, users should also be able to list all shows which are displaying a particular movie.
Each character in the document has its own style.

Implement the below methods in Solution class:

init(Helper10 helper)

addCinema(int cinemaId, int cityId,
int screenCount, int screenRow, int screenColumn)

Add a new cinema inside a city.

addShow(int showId, int movieId, int cinemaId,
int screenIndex, long startTime, long endTime)

Add a show for displaying a movie on a
  cinema screen in a given time slot.

List[String] bookTicket(String ticketId,
int showId, int ticketsCount)

Returns list of seats as "row-column"
e.g. ["0-4", "2-14", "2-0", "11-6"]

boolean cancelTicket(String ticketId)
cancels ticket and makes all seats booked in ticketId
again available for booking.
int getFreeSeatsCount(int showId)

List[Integer] listCinemas(int movieId, int cityId)

List[Integer] listShows(int movieId, int cinemaId)

Input Example
Solution obj=new Solution();
obj.init(helper)
obj.addCinema(cinemaId=0,
cityId=1, screenCount=4,
screenRow=5, screenColumn = 10)
obj.addShow(showId= 1, movieId=4,
cinemaId=0, screenIndex=1,
startTime=1710516108725, endTime=1710523308725)
obj.addShow(showId = 2, movieId=11,
cinemaId = 0, screenIndex = 3,
startTime = 1710516108725, endTime = 1710523308725)

obj.listCinemas(movieId = 0, cityId = 1)
returned cinemaId's list: []
obj.listShows(movieId = 4, cinemaId = 0)
returned showId's list [1]
obj.listShows(movieId = 11, cinemaId = 0)
returned showId's list [2]

obj.getFreeSeatsCount(showId = 1) returned 50
obj.bookTicket(ticketId = 'tkt-1', showId = 1, ticketsCount = 4)
returned seat's list: [0-0, 0-1, 0-2, 0-3]
obj.getFreeSeatsCount(showId = 1) returned 46

obj.cancelTicket(ticketId = 'tkt-1') returned true
obj.getFreeSeatsCount(showId = 1) returned 50