Design Uber Eats Ads Schedule Dashboard
You are designing an Uber Eats ads dashboard where an advertiser can choose when an ad should run during a week.
The dashboard has 7 days, from Monday to Sunday. Each day is divided into 6 fixed time slots of 4 hours each. A selected slot means the ad will be displayed during that slot for that day.
Clicking a slot toggles it. If the slot was not selected, it becomes selected. If it was already selected, it becomes unselected.
The dashboard stores the full weekly schedule together. Switching between days should not require fetching separate data for that day.
Method Signatures
Constructor
AdsScheduleDashboard(List<String> selectedSlots)
selectedSlots: initially selected slots.
- Each string is in the format
"day,slotIndex".
day is one of MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY.
slotIndex is from 0 to 5.
- Duplicate initial slots should be treated as one selected slot.
Click Slot
List<String> clickSlot(String day, int slotIndex)
- Toggles the given slot for the given day.
- Returns the updated selected slots for that day only.
- The returned slots must be sorted by
slotIndex in increasing order.
Get Day Schedule
List<String> getDaySchedule(String day)
- Returns all selected slots for the given day.
- The returned slots must be sorted by
slotIndex in increasing order.
Get Weekly Schedule
List<String> getWeeklySchedule()
- Returns all selected slots for the full week.
- The returned slots must be sorted by day order from Monday to Sunday.
- For the same day, slots must be sorted by
slotIndex in increasing order.
Output Format
Each selected slot must be returned as a string in this format:
"day,slotIndex,startTime,endTime"
slotIndex = 0 means 00:00 to 04:00.
slotIndex = 1 means 04:00 to 08:00.
slotIndex = 2 means 08:00 to 12:00.
slotIndex = 3 means 12:00 to 16:00.
slotIndex = 4 means 16:00 to 20:00.
slotIndex = 5 means 20:00 to 24:00.
Constraints
- All input values will be valid, including day names, slot indexes,
selectedSlots string format, and any other required format.
0 ≤ selectedSlots.size() ≤ 42
- There are exactly
7 days.
- Each day has exactly
6 slots.
0 ≤ slotIndex < 6
- All method outputs must be deterministic.
- No parameter value will be
null.
Examples
Example 1
Constructor call:
AdsScheduleDashboard(selectedSlots = ["MONDAY,0", "MONDAY,3", "FRIDAY,5"])
Method call:
clickSlot(day = "MONDAY", slotIndex = 1)
Output:
["MONDAY,0,00:00,04:00", "MONDAY,1,04:00,08:00", "MONDAY,3,12:00,16:00"]
Explanation: Monday slot 1 was not selected, so it becomes selected.
Example 2
Constructor call:
AdsScheduleDashboard(selectedSlots = ["TUESDAY,2", "TUESDAY,4", "SUNDAY,0"])
Method call:
clickSlot(day = "TUESDAY", slotIndex = 2)
Output:
["TUESDAY,4,16:00,20:00"]
Explanation: Tuesday slot 2 was already selected, so it becomes unselected.
Example 3
Constructor call:
AdsScheduleDashboard(selectedSlots = ["WEDNESDAY,5", "WEDNESDAY,1", "WEDNESDAY,1"])
Method call:
getDaySchedule(day = "WEDNESDAY")
Output:
["WEDNESDAY,1,04:00,08:00", "WEDNESDAY,5,20:00,24:00"]
Explanation: Duplicate initial slots are ignored, and the result is sorted by slot index.
Example 4
Constructor call:
AdsScheduleDashboard(selectedSlots = ["SUNDAY,2", "MONDAY,5", "FRIDAY,0"])
Method call:
getWeeklySchedule()
Output:
["MONDAY,5,20:00,24:00", "FRIDAY,0,00:00,04:00", "SUNDAY,2,08:00,12:00"]
Explanation: Weekly schedule is returned in fixed day order from Monday to Sunday.