Hi Community,
Recently I appeared for the Flipkart Machine Coding Round. Below is the task to be done in 2.5 hours.
YOE: 7+ Years
Description:
Flipkart is starting a new vehicle rental service called FlipKar. In this service, we will rent different kinds of vehicles such as cars and bikes.
Features:
Requirements:
Bonus:
Other Notes:
Expectations:
Test cases:
• add_branch(‘koramangala’, [“1 suv for Rs.12 per hour”, “3 sedan for Rs.10 per hour”, “3 bikes for Rs.20 per hour”]);
• add_branch(‘jayanagar’, [“3 sedan for Rs.11 per hour”, “3 bikes for Rs.30 per hour”, “4 hatchback for Rs.8 per hour”]);
• add_branch(‘malleshwaram’, [“1 suv for Rs.11 per hour”, “10 bikes for Rs.3 per hour” , “3 sedan for Rs.10 per hour”]);
• add_vehicle(‘koramangala’, “1 sedan”); //add 1 sedan to koramangala
• rent_vehicle(‘suv’, 20th Feb 10:00 PM, 20th Feb 12:00 PM); // should book from malleshwaram.
• rent_vehicle(‘suv’, 20th Feb 10:00 PM, 20th Feb 12:00 PM); // should book from koramangala.
• rent_vehicle(‘suv’, 20th Feb 10:00 PM, 20th Feb 12:00 PM); //Should fail saying no vehicle.
• print_system_view_for_time_slot(20th Feb 11:00 PM, 20th Feb 12:00 PM);
o Output:
‘Koramangala’:
All “suv” are booked.
“sedan” is available for Rs.10
“bike” is available for Rs.20
‘Jayanagar’:
“sedan” is available for Rs.11
“bike” is available for Rs.30
“hatchback” is available for Rs.8
‘‘Malleshwaram’’:
All “suv” are booked.
“bike” is available for Rs.3
“sedan” is available for Rs.10My Approch:
I created 4 interfaces IUserService, IDbService, IBookingService and IRentalService.
IRentalService acts as the entry point for the external world.
IBookingService basically has BookVehicle(). For now BookCheapestVehicleService implements it but gives the flexibility to extend to any other strategy at a later point using dependency injection.
IUserService for all user related queries.
IDbService stores all data(models). It is called by the other services.
Verdict:
I demostrated my running code to interviewer. There were a few errors told him how to rectify it and he seemed satisfied. Later got a reject. Not sure what exactly happened. Do they expect a fully functional and optimized code??
Request from community:
If you have some better design in mind for this problem please let us all know your design.