PhonePe | Software Engineer(3-5 years) | Bengaluru | July 2023 | Reject

Anonymous User
1258
Jul 29, 2023
Jul 29, 2023

Round 1 - (Machine Coding)
Interviewer joined the call and gave the problem statement & left.

You have to design and implement a Vehicle Rental Service which allows users to rent a given type of Vehicle for a given time slot.
Requirements:

This Vehicle Rental Service will be operational only in one city (Delhi) which will have multiple branches (eg. Vasant Vihar Branch, CP branch, etc).
Each branch can have three different types of vehicles (VehicleType) : Sedan, Hatchback, SUV. There could be any number of vehicles of each type in a branch.
The rental price per hour should be defined at “per branch per vehicle type” level and NOT at an individual vehicle level. (eg. Sedan in CP branch = 150 rs/hr, Sedan in Vasant Vihar = 100 rs/hr, Hatchback in CP = 80rs/hr and so on)
A user can request to rent a particular vehicle type for a given time slot. You will have to allot the vehicle from one of the branches if available for the given time slot with the “lowest rental price” strategy.
The following APIs have to be implemented:
Note: The given parameters are the mandatory parameters, you are free to add more parameters as part of your apis if you feel the need to do so. The return type of each api is up to you but make sure it provides the relevant information needed.

addBranch(branchName)
This will add a new branch for your Service.

allocatePrice(branchName, vehicleType, price);
This will be used to define price per vehicle type per branch

addVehicle(vehicleId, vehicleType, branchName);
This will add a new vehicle of the given vehicle type in a given existing branch.

bookVehicle(vehicleType, startTime, endTime)
This will be used to rent a vehicle for the given vehicle type for a given time slot defined by Start time and end time. You can expect the start time and endTime to be in hourly slots only.

[Optional]viewVehicleInventory(startTime, endTime): This will give a snapshot of the inventory for the given time slot i.e. all the vehicles that are available and all the vehicles that are not available categorised by vehicleType.

Guidelines:

You should store the data in-memory using a language-specific data-structure.
You can print the output in console.
Design your application in a way that a new rental Strategy can be implemented and used instead of the default one (lowest price).
Implement clear separation between your data layers and service layers.
You can take the startTime and endTime as DateTime or in any other way as you prefer.
The start time and end time will be in hourly granularity only.
Expectations:

  • Your code should cover all the mandatory functionalities explained above.
  • Your code should be executable and clean.
  • Your code should be properly refactored, and exceptions should be gracefully handled.

How will you be evaluated?

  • Code Should be working
  • Code readability and testability
  • Separation Of Concerns
  • Abstraction
  • Object-Oriented concepts.
  • Language proficiency.
  • Scalability
  • Concurrency handling (Bonus Points)
  • Test Coverage (Bonus Points)
    Sample Execution:
addBranch(“Vasanth Vihar”)
addBranch(“Cyber City”)
allocatePrice(“Vasanth Vihar”, VehicleType.Sedan, 100)
allocatePrice(“Vasanth Vihar”, VehicleType.Hatchback, 80)
allocatePrice(“Cyber City”, VehicleType.Sedan, 200)
allocatePrice(“Cyber City”, VehicleType.Hatchback, 50)
addVehicle(“DL 01 MR 9310”, VehicleType.Sedan, “Vasanth Vihar”)
addVehicle(“DL 01 MR 9311”, VehicleType.Sedan, “Cyber City”)
addVehicle(“DL 01 MR 9312”, VehicleType.Hatchback, “Cyber City”)
bookVehicle(VehicleType.Sedan, 29-02-2020 10:00 AM, 29-02-2020 01:00 PM)

“DL 01 MR 9310” from Vasanth Vihar booked.

Note: Since the strategy is lowest price first, the sedan was allocated from Vasanth Vihar as the >>>price is lower as compared to Cyber City Branch.

bookVehicle(VehicleType.Sedan, 29-02-2020 02:00 PM, 29-02-2020 03:00 PM)

“DL 01 MR 9310” from Vasanth Vihar booked.

bookVehicle(VehicleType.Sedan, 29-02-2020 02:00 PM, 29-02-2020 03:00 PM)

“DL 01 MR 9311” from Cyber City booked.

bookVehicle(VehicleType.Sedan, 29-02-2020 02:00 PM, 29-02-2020 03:00 PM)

NO SEDAN AVAILABLE

viewInventory(29-02-2020 02:00 PM, 29-02-2020 03:00 PM)

Branch: Vasanth Vihar
Sedan DL 01 MR 9310 Booked
Hatchback DL 01 MR 9312 Available
Branch: Cyber City
Sedan DL 01 MR 9311 Booked

viewInventory(29-02-2020 04:00 PM, 29-02-2020 05:00 PM)

Branch: Vasanth Vihar
Sedan DL 01 MR 9310 Available
Hatchback DL 01 MR 9312 Available
Branch: Cyber City
Sedan DL 01 MR 9311 Available

Round 2 - (Problem Solving and Data Structures)

Question 1 :

There are n trees in a forest. The heights of the trees is stored in array tree[], where tree[i] denotes the height of the ith tree in the forest. If the ith tree is cut at a height H, then the wood collected is tree[i] - H, provided tree[i] > H. If the total woods that needs to be collected is exactly equal to k, find the height H at which every tree should be cut (all trees have to be cut at the same height). If it is not possible then return -1 else return H.

Example 1:

Input:
n = 5, k = 4
nums[] = {2, 3, 6, 2, 4}
Output: 3
Explanation: Wood collected by cutting trees
at height 3 = 0 + 0 + (6-3) + 0 + (4-3) = 4
hence 3 is to be subtracted from all numbers.
Since 2 is lesser than 3, nothing gets
subtracted from it.

Question 2 :

  • K parking slots => 0 .. K -1

  • N people who will come in, each with a (start_time, duration) that they want to use

  • This is gives an array [(s, d) ... ] sorted by start time

  • We want to assign parking slot to the person in the below way

    • Assign the closest available slot
    • If no slots are available, assign the slot that will get free the earliest
  • Output => slot # that served max parkings

input = [(1, 6), (4, 2), (8, 1)]
K = 2

P0 => Slot 0
P1 => Slot 1
P2 => Slot 0


input = [(1, 20), (4, 10), (8, 1)]
K = 2

P0 => Slot 0
P1 => Slot 1
P2 => Slot 1

Result - No Hire

Comments (5)