Build a Weekly Calendar
Company: Robinhood
Role: Frontend Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates frontend UI engineering skills, focusing on interactive interface construction, event handling, and state modeling to maintain a single source of truth for events in a weekly calendar grid, and it belongs to the web frontend development and UI/state-management domain.
Constraints
- 0 <= len(actions) <= 100000
- Valid day values are 0 through 6
- Valid hour values are 0 through 23
- Event names are strings and may be empty; an empty name clears the selected cell
- At most 168 cells can contain events at any time
Examples
Input: []
Expected Output: []
Explanation: No actions means no events are stored.
Input: [("click", 0, 9), ("submit", "Standup"), ("click", 2, 14), ("submit", "Review")]
Expected Output: [(0, 9, 'Standup'), (2, 14, 'Review')]
Explanation: Two valid click-submit pairs create two events in different cells.
Input: [("submit", "Oops"), ("click", 6, 23), ("submit", "Deploy"), ("click", 6, 23), ("submit", "Hotfix")]
Expected Output: [(6, 23, 'Hotfix')]
Explanation: The first submit is ignored because nothing is selected. The later submit to the same cell overwrites the previous event.
Input: [("click", 1, 10), ("click", 7, 5), ("submit", "Sync")]
Expected Output: [(1, 10, 'Sync')]
Explanation: The second click is invalid, so the previous valid selection remains active and the submit applies to day 1, hour 10.
Input: [("click", 3, 8), ("submit", "Gym"), ("click", 3, 8), ("submit", ""), ("click", 3, 9), ("submit", "Read")]
Expected Output: [(3, 9, 'Read')]
Explanation: Submitting an empty string clears the event at day 3, hour 8. A new event is then added at day 3, hour 9.
Hints
- Use a hash map keyed by (day, hour) so each calendar cell has a single canonical event entry.
- Track the currently selected cell separately, and only build the sorted output after all actions are processed.