UBER | Senior Software Engineer | Phone Screen

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-04-15Added By Anonymous
Source: Link

Company: Uber

Role: Senior Software Engineer

Interview Stage: Phone Screen


Original Post Content:


Build a reservation system for a predefined set of conference rooms given as a list of room Ids [‘roomA’, roomB’...].


It should have a method like scheduleMeeting(startTime, endTime) should return a reservation identifier (including roomId) and reserve it or an error if no rooms are available.

•Assume there are 100 rooms, later can talk about scaling to N
•Assume any number of meetings can be scheduled on any conference room


YOE: 12 yrs


My approach:

1class RoomManger 2{ 3 using TimeSlot = std::pair<int, int>; // start, end 4 using Container = std::unordered_map<std::string, std::set<TimeSlot>>; // room-id to timeslots 5 6 size_t occupied_rooms; 7 std::vector<std::string> ROOM_LIST; // Some constants 8 Container rooms_holder; 9 10 RoomManger(size_t N) : ROOM_LIST(N), occupied_rooms(0), rooms_holder{} 11 { 12 // Fill room list, may be from configuration file ? 13 for (int i = 0; i < N; ++i) 14 { 15 ROOM_LIST[i] = "room" + std::to_string(i + 1); 16 } 17 } 18 19 std::string getNextRoom() 20 { 21 if (occupied_rooms != ROOM_LIST.size()) 22 { 23 return ROOM_LIST[occupied_rooms++]; 24 } 25 return {}; 26 } 27 28public: 29 std::string scheduleMeeting(int startTime, int endTime) 30 { 31 TimeSlot time_slot = {startTime, endTime}; 32 std::string room_id = getNextRoom(); 33 34 if (!room_id.empty()) 35 { 36 // room_id is available 37 rooms_holder[room_id].insert(time_slot); 38 return room_id; 39 } 40 41 for (auto &[room_id, time_slots] : rooms_holder) 42 { 43 if (time_slots.empty()) 44 { 45 time_slots.insert(time_slot); 46 return room_id; 47 } 48 49 auto it = time_slots.lower_bound(time_slot); 50 51 if (it == time_slots.end()) 52 { 53 time_slots.insert(time_slot); 54 return room_id; 55 } 56 57 if (it->first >= time_slot.second) 58 { 59 time_slots.insert(time_slot); 60 return room_id; 61 } 62 } 63 64 throw std::runtime_error("No rooms available"); 65 } 66};


The expectation was to do a simulation of the code.

I totally messed it up.

I couldn't complete it on time, and probably not the best data structures I have choosen.

The interviewer was pretty chill out, though.

Nothing interesting was hitting to me at that moment, I wasted lot of time explaining the my idea of figuring which rooms to pick and how to avoid overlaps.

At end when I thought I am done, I realized I missed to write code of overlapping timeslots, I tried to add some, qickly, but felt I could not, given the time constraints, so just ended explaining again.

At end we discussed about Time and Space complexity.

Probably it would have been a piece of cake if I'd have touch with DSA and codings.

Comments