KatInterview

Build a Weekly Schedule Grid

Data Structure DesignModel answer
MediumModel answerData Structure Designfrontendreactstate-management

Last updated

Construct an interactive 7-day schedule grid with hour slots, allowing users to add titled events via a clean, state-driven dialog without duplicate data sources.

Create a weekly calendar component that displays a 7-day schedule breakdown divided into 1-hour time blocks (00:00 to 23:00).

Core Functionality

  1. Grid Layout: Display 7 daily columns across 24 hourly rows.
  2. Cell Selection: Clicking any individual cell (a specific day and hour) triggers a modal input dialog.
  3. Event Creation: The modal allows the user to input an event title. Upon submission, the event must render inside the chosen slot on the grid.
  4. Clean Architecture: The component must maintain a single source of truth for all schedule data. UI views and lookup indexes should be dynamically calculated rather than manually mirrored across multiple state containers.

Expected Deliverable

Provide a component implementation (preferably in React) along with an explanation of your state management decisions, complexity metrics, and handling of UX edge cases.

Hints

Hint 1

Avoid keeping a separate 2D grid matrix in React state alongside your raw events list; calculate cell contents on demand or memoize an index map from the events array.

Hint 2

Represent modal visibility using a nullable selected slot state (e.g., `{ dayIndex, hour } | null`) rather than a disconnected boolean toggle.

Hint 3

Isolate draft input strings inside the modal dialog component to prevent unnecessary parent re-renders while typing.