How I cracked the Machine Coding round of Flipkart

TheCuriousProgrammer
4 min readJun 4, 2021

--

I got an offer from Flipkart for the SDE1 post. Here I am trying to explain the question and my proposed solution for the Machine Coding Round.

The question was explained to all the interviewees together and then we had to code for 2 hours and our screens were monitored.

Watch this video of full explanation of code.

Question:

One of the core problems which people face at every company is the unavailability of conference rooms. So we thought of building one conference room management system. The system should have the following features.

Assumptions:

  1. Conference rooms are scattered across multiple buildings and multiple floors and each floor can have multiple conference rooms, but each conference room should be uniquely identifiable.

2. Booking will be done for slots in hours. Hours will be taken in 24 hours format eg. Book from 1am to 3am {1:3}, from 12pm to 1pm {12:13}

3. Each conference room can be booked given that no one has already booked for that slot.

4. System will be used only by one user only.

5. Booking can be done for 1 day only.

Features:

  1. Users should be able to list down all the conference rooms available in any building. Eg:Alpha building has conference rooms with names: a1, a2, a3, a4 etc.

2. User should be able to find suitable rooms to book for a given slot.

3. User should be able to cancel existing booking and rooms should be free to be booked again for that slot.

4. List down all the bookings made by the current user.

5. Command which will be executed to perform the above actions is listed below.

Note* All the input params given below are for demonstration purposes only, user can create his/her own building name and floor name, and conference rooms.

Commands:

  1. ADD BUILDING <building_name> //Adds building in the system
    Eg: ADD BUILDING flipkart1
    Output: Added building flipkart1 into the system.
  2. ADD FLOOR <buildingName> <floorName>
    Eg. ADD FLOOR FLIPKART1 FirstFloor
  3. ADD CONFROOM <buildingName> <floorName> <conferenceRoomID>
    Eg: ADD CONFROOM flipkart1 firstfloor c1
    The above commands adds c1 conference room in firstfloor of building flipkart1
    Output: Added conference room c1 on firstfloor in flipkart1
  4. BOOK <SLOT> <BUILDING> <FLOOR>
    Books the given Conference room for a given slot, on the given floor of the building.
    Eg: BOOK 1:5 FLIPKART1 SEVENTH C1
  5. CANCEL <SLOT> <BUILDING> <FLOOR> <ROOM ID>
    Cancels the slot booked for the floor in a given building.
  6. LIST BOOKING <BUILDING> <FLOOR>
    Should list down all the bookings made by current user
    Output format: <SLOT> <FLOOR> <BUILDING> <roomName>
    2:6 THIRDFLOOR FLIPKART1 c1
    6:10 THIRDFLOOR FLIPKART1 c2
  7. SEARCH <SlotName> <BuildingName> <FloorName>
    Search should return possible available rooms for given parameters.
    SEARCH 2:3 flipkart3 seventhFloor -> Search conf rooms available for booking from 2->3 in flipkart3 building and seventhFloor floor
    If no room is available for booking for given slot, search will return “No Rooms available”

Bonus Functionality:

Existing search will return empty results if no rooms are available for a given slot. Users want a suggestion functionality using which users can get a list of possible future slots [Size limit to 3] which can be booked.

Eg. Assume no room is available for a slot then the search will return an empty result while SUGGEST command will return the next 3 suggestions.

Command: SUGGEST 3:10

Expectation

  1. Code should be Demo able and functionally complete.
  2. Code should fail gracefully with a proper error message for corner/invalid cases.
  3. Code should be modular, try thinking in terms of Object-Oriented Design.
  4. Input can be taken from the command line or in the main function.
  5. Do not use any database or NoSQL store, use in-memory data structure.
  6. Do not create any UI for the application.
  7. Write a driver class for demo purposes. Which will execute all the commands in one place.
  8. Please prioritize code compilation, execution, and completion.
  9. Work on the expected output first and then only work on bonus features.

How I approached the problem

I was able to create a functioning code for 6 requirements at the end of 2 hours. I managed all the edge cases.

The interviewer asked me to explain the code, she gave me some more test cases to run, they all ran successfully.

After that, we discussed the approach to the 7th and bonus questions, I was able to explain that as well.

Below is the code that I had implemented.

Tips:

Implement functionality 1 by 1. After each implementation check if your code is working.

Have a modular design. The interviewer can ask you to modify the code with some new functionality, your code should be able to incorporate that with minimal changes.

Work on as many edge cases as you think there can be. This is of very high value.

Watch this video of full explanation of code.

--

--