Amazon Interview Question
Software Engineer / DevelopersTeam: RCX
Country: United States
Interview Type: In-Person
I try to make the design as simple as possible. I assumed:
1. we don't care about who has which seat, we just care about the available seats.
2. There is no need to write the part that handles user chooses a seat or user pays for the seat.
class Seat{
int row;
int col;
//setters,getters
}
/*General info about theatre*/
class Theatre{
HashSet<Seat> availableSeats;
String theatreName;
String theatreAddress;
//other theatre info + setters,getters
}
/*general info about the movie
class MovieInfo{
String name;
String description;
List<String> actors;
//other info + setters,getters
}
/*a class that handles ticket management for a specific movie in a specific theatre for a show time*/
class MovieTicket{
Theatre theatre;
Date showTime;
MovieInfo movieInfo;
HashSet<Seat> getAvailableSeats(){
return theatre.getAvailableSeats();
}
boolean synchronized commitToBuy(Seat seat){
if(theatre.getAvailableSeats().contains(seat)){
theatre.getAvailableSeats().remove(seat)
return true;
}
return false;
}
}
To make it faster, one possible way is to put MovieTicket object in an LRU cache to make sure that hot movies (like a newly released movie at the weekend) can be retrieved very fast. If the MovieTicket object doesn't exist in the cache, we have to create one from our DB.
I try to make the design as simple as possible. I assumed:
1. we don't care about who has which seat, we just care about the available seats.
2. There is no need to write the part that handles user chooses a seat or user pays for the seat.
To make it faster, one possible way is to put MovieTicket object in an LRU cache to make sure that hot movies (like a newly released movie at the weekend) can be retrieved very fast. If the MovieTicket object doesn't exist in the cache, we have to create one from our DB.
- Pooyo May 25, 2014