Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Copy-pasted from https://gist.github.com/sharath-c-s/7f3cfb34de5507a319e2430a5a62e722
- Calendar Application — Machine Coding Round
- Question
- Develop a calendar application that allows users to schedule events, handle overlapping meetings, register users with roles, and prioritize events based on role hierarchy when conflicts arise.
- No CLI / input parser is required. Drive all operations through hardcoded test cases inside main() (or a test class). Focus time on modelling, correctness, and clean separation of concerns.
- Operations
- Register user with role — role is one of VP, Director, Manager, Dev.
- Login (set current user) — subsequent schedule calls treat the logged-in user as the organizer.
- Schedule event — provide an event name, a start time, an end time, and a list of attendee user IDs.
- List events — for the currently logged-in user, list the events visible in their calendar after applying the conflict-resolution rules below.
- Role Hierarchy
- VP > Director > Manager > Dev
- Used only to break ties when two overlapping events compete for a slot in a user's calendar.
- Constraints
- Single-day window. All events live inside one 24-hour day, in the range [0000, 2400). An event must satisfy 0000 <= startTime < endTime <= 2400. No event overflows into the next day.
- At most two events may overlap at any point inside a single user's calendar (raw, before conflict resolution). A schedule call that would cause a third concurrent event for any attendee (including the organizer) must be rejected with an exception. This is enforced at schedule time, not at list time.
- Conflict resolution is exhaustive. When two events overlap in a user's calendar, exactly one of the following two rules picks the winner — no other tiebreak is required, and the test data is designed so that no other tiebreak is ever needed:
- A self-scheduled event (where the user is the organizer) beats an event the user was invited to.
- Otherwise, the event whose organizer has the higher role wins. The losing event is hidden from that user's list output (it still exists on the organizer's calendar and on other attendees' calendars where it may win or lose independently).
- Times are integers in HHMM 24-hour form — e.g. 1400, 1530, 1730. End time is exclusive: an event 1400–1500 does not overlap an event 1500–1600.
- No CLI parsing. Wire the test cases directly in main() or a JUnit test. Don't spend time on tokenization or stdin handling.
- Overlap Definition
- Two events [s1, e1) and [s2, e2) overlap iff s1 < e2 && s2 < e1. Touching boundaries (e1 == s2) do not overlap.
- Expectations
- Working, demo-able code (mandatory).
- Functionally correct against the supplied test cases (mandatory).
- Proper abstraction, entity modelling, and separation of concerns.
- Modular, readable, unit-testable code.
- Easy to extend for new requirements with minimal churn.
- Proper exception handling for: unknown user, invalid time range, day-overflow, more-than-two overlap, scheduling without a logged-in user.
- Bonus
- Edit / delete event.
- Meeting rooms attached to events; accept or decline if the room is unavailable.
- Concurrency safety (e.g., two schedulers racing on the same attendee's calendar).
- Test Cases
- Note: events with attendees listed include the organizer's own calendar implicitly — the organizer always sees their own event as a self-scheduled entry, no matter what is passed in attendees.
- 1. Register users
- register u1, Dev
- register u2, Dev
- register u3, Manager
- register u4, VP
- register u5, Director
- 2. Schedule events (in order)
- login u2
- schedule e1, 1400 1500, attendees=[u1, u3, u4]
- login u5
- schedule e2, 1300 1430, attendees=[u3]
- login u4
- schedule e3, 1500 1700, attendees=[u2, u3]
- login u3
- schedule e4, 1600 1730, attendees=[u1]
- 3. Rejected schedule — exceeds two-event overlap
- login u1
- schedule e5, 1410 1420, attendees=[u3]
- u3's raw calendar already holds e1 (1400–1500) and e2 (1300–1430) during 1410–1420. Adding e5 would push the overlap count to 3, which violates constraint 2.
- Expected: schedule call throws OverlapLimitExceededException (or equivalent). e5 is not added to anyone's calendar.
- 4. List events per user
- login u3
- list
- Expected output: e2, e4
- Pair Window Resolution
- e1 (u2/Dev) vs e2 (u5/Director) 1400–1430 u3 not self → higher role wins → e2 keeps slot, e1 dropped from u3
- e3 (u4/VP) vs e4 (u3/self) 1600–1700 self wins → e4 keeps slot, e3 dropped from u3
- login u2
- list
- Expected output: e1, e3 — e1 is self, e3 is an invite from u4 (VP). They touch at 1500 but do not overlap.
- login u4
- list
- Expected output: e1, e3 — e1 is an invite from u2 (Dev), e3 is self. No overlap.
- login u1
- list
- Expected output: e1, e4 — both invites, no overlap (e1 ends 1500, e4 starts 1600).
- login u5
- list
- Expected output: e2 — only self.
Advertisement
Add Comment
Please, Sign In to add comment