Flipkart Machine Coding | SDE 3 | Bangalore | August 2021 [Reject]
Anonymous User
1731

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:

  1. Rental service has multiple branches throughout the city.
  2. Each branch has a limited number of different kinds of vehicles.
  3. Each vehicle can be booked with a predefined price per unit time slot.
    For simplicity, the current pricing model does not support dynamic pricing
    or update on prices based on seasonality.
  4. Each vehicle can be booked in multiples of 1 hour time slot.
  5. All bookings should be made before the start time of particular booking.

Requirements:

  1. Onboard a new branch with available vehicles.
  2. Onboard new vehicle(s) of existing type to a particular branch.
  3. Rent vehicle for a time slot and a vehicle type
    (lowest price as the default choice of selection of vehicle, this should be extendable to any other strategy).
    While booking a vehicle if availability is not there, then it should fallback to another available branch,
    which is derived based on the vehicle selection strategy.
  4. A system view should be made available, such as currently blocked vehicles,
    available vehicles of all the branches.

Bonus:

  1. While booking a vehicle, if 2 branches are providing vehicle at the same price,
    give priority to the nearest branch.

Other Notes:

  1. Do not use any database or NoSQL store, use in-memory data-structure for now.
  2. Do not create any UI for the application.
  3. Write a driver class for demo purpose. Which will execute all the commands at one place in the code and have test cases.
  4. Please prioritize code compilation, execution and completion.
  5. Work on the expected output first and then add good-to-have features of your own.

Expectations:

  1. Make sure that you have working and demonstrable code.
  2. Make sure that code is functionally correct.
  3. Make sure concurrent requests are handled appropriately.
  4. Code should be modular and readable.
  5. Separation of concern should be addressed.
  6. Code should easily accommodate new requirements with minimal changes.
  7. Code should be easily testable. Demo with Unit Tests

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.10

My 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.

Comments (2)