As reported: Wayfair Software Engineer II loop (2025), machine-coding round on HackerRank, titled "Wayfair Onsite Loop: Event Management". The same problem was given to another SDE 2 candidate as the low-level design round, where working code was expected; it was lengthy and needed speed.
A company manages events and wants reports about them. Implement three classes.
Person — Person(firstName, lastName). (Given.)
EventInfo — EventInfo(eventName, eventDate, capacity, canceled). An event keeps two lists of people: registrations and attendees.
register(person)— add the person to the registrations if the event is not canceled, the number of registrants is belowcapacity, and the person is not already registered.attend(person)— add the person to the attendees if the event is not canceled, the person is registered, and the person is not already an attendee.
EventManager — the constructor starts with an empty list of events.
addEvent(event)— add the event if no event with the same name is already present.register(eventName, person)/attend(eventName, person)— if an event with this name exists, register the person for it / record their attendance (attendance still requires registration).getEventCountByYears()— a list of strings"<year> - <number of events>", ordered by year.getEventRegistrationCountByYears()—"<year> - <total registrations of that year's events>", ordered by year.getEventAttendeesCountByYears()—"<year> - <total attendees of that year's events>", ordered by year.
Example
People Jane Smith, John Doe and Richard Roe; Event1 takes place in 2021 and Event2 in 2020. John registers for Event1 and Event2, Richard for Event1, Jane for Event1 and Event2. John and Richard attend Event1.
Event Count:
2020 - 1
2021 - 1
Registrations:
2020 - 2
2021 - 3
Attendees:
2020 - 0
2021 - 2
Sample 0 (code runner input below)
people: First1 Last1, First2 Last2, First3 Last3
events: Event1 2021.04.22 capacity 91, Event2 2022.01.17 capacity 41, Event3 2024.06.27 capacity 28 (none canceled)
actions: person 1 registers for Event1; person 0 attends Event2; person 0 registers for Event1
output: Event Count: 2021 - 1, 2022 - 1, 2024 - 1
Registrations: 2021 - 2, 2022 - 0, 2024 - 0
Attendees: 2021 - 0, 2022 - 0, 2024 - 0
First1 tries to attend Event2 without registering, so nothing is recorded.
Clarifications
- Every year that has at least one event appears in all three reports, with
0where there is nothing to count. Canceled events still count as events of their year. - "Already registered" means the same person object; two different
Personobjects are two people. - The year is the first four characters of
eventDate.
Constraints: at most 300 people, 200 events and 5000 actions.
Code runner format: three lines, one JSON value each: the people as [firstName, lastName] pairs; the events as [eventName, eventDate ("YYYY.MM.DD"), capacity, canceled]; the actions as [action, personIndex, eventIndex] with 1 = register and 2 = attend (0-based indexes). The harness creates the objects, calls addEvent for every event in order, runs each action through the manager by event name, then prints Event Count:, Registrations: and Attendees: each followed by the lines your three methods return. In C++, register is a keyword, so the register methods are named registerPerson. Open Practice to read the starter classes in the editor, in any of the five languages.