PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates algorithmic problem-solving skills related to interval overlap handling and constrained packing, measuring competency in mapping temporal events to minimal column layouts and assigning strings into fixed-width rows under capacity constraints.

  • medium
  • Robinhood
  • Coding & Algorithms
  • Software Engineer

Implement Calendar Layout and String Packing

Company: Robinhood

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

The interview reportedly included two separate coding exercises: 1. **Day-view calendar layout** - You are given a list of events for a single day. Each event has a `start` time and `end` time in minutes since midnight. - Build a function that assigns each event a visual layout for a calendar day view. - If two events overlap in time, they must be placed in different columns. - For each event, return: - its column index, - the total number of columns needed for its overlapping group. - The layout should use the minimum number of columns necessary for each overlapping group. 2. **Place strings into three rows** - You are given a list of strings and exactly 3 rows. - Each row has a fixed maximum width `W`. - The width consumed by a string is its character length. - Process the strings in order. - Part A: place each string into any row that has enough remaining capacity; return any valid placement, or report failure if a string cannot be placed. - Part B: among all rows that can fit the current string, place it into the row with the most remaining space before placement. Break ties by choosing the smallest row index. - Return the placement result and the remaining space in each row.

Quick Answer: This question evaluates algorithmic problem-solving skills related to interval overlap handling and constrained packing, measuring competency in mapping temporal events to minimal column layouts and assigning strings into fixed-width rows under capacity constraints.

Part 1: Day-View Calendar Layout

You are given events for a single day, where each event is a pair (start, end) measured in minutes since midnight. Build a day-view layout that assigns every event a column index. Two events that overlap in time must be placed in different columns. For each event, return a tuple (column_index, total_columns), where total_columns is the minimum number of columns needed by that event's overlapping group. An overlapping group is a maximal set of events connected by direct overlap or by a chain of overlaps. If one event ends exactly when another starts, they do not overlap. Return results in the original input order.

Constraints

  • 0 <= len(events) <= 200000
  • 0 <= start < end <= 1440
  • Events that touch at a boundary, such as (60, 120) and (120, 180), do not overlap.

Examples

Input: ([(60, 120), (90, 150), (150, 180)],)

Expected Output: [(0, 2), (1, 2), (0, 1)]

Explanation: The first two events overlap, so they need 2 columns. The third starts exactly when the second ends, so it forms a new group with 1 column.

Input: ([(0, 30), (10, 40), (20, 50), (60, 70)],)

Expected Output: [(0, 3), (1, 3), (2, 3), (0, 1)]

Explanation: The first three events overlap in one group and reach a peak concurrency of 3. The last event is separate.

Input: ([(30, 60), (0, 15), (10, 40), (45, 50)],)

Expected Output: [(0, 2), (0, 2), (1, 2), (1, 2)]

Explanation: All four events belong to one connected overlap group, and the maximum simultaneous overlap is 2.

Input: ([],)

Expected Output: []

Explanation: No events means no layout.

Hints

  1. Sort events by start time and track currently active events with a min-heap ordered by end time.
  2. Whenever the active set becomes empty, one overlap group has finished, so you can finalize its total column count.

Part 2: Place Strings into Three Rows - Any Valid Placement

You are given a list of strings and exactly 3 rows. Each row starts with width W, and placing a string consumes len(string) units from that row. Process the strings in order. For this deterministic version of the problem, place each string into the first row with enough remaining space, scanning rows from index 0 to 2. If a string cannot be placed in any row, return None. Otherwise return the row chosen for each string and the final remaining space in the 3 rows.

Constraints

  • 0 <= len(strings) <= 200000
  • 0 <= W <= 1000000000
  • There are exactly 3 rows indexed 0, 1, and 2
  • The width of a string is len(string)

Examples

Input: (['ab', 'c', 'def', 'gh'], 4)

Expected Output: ([0, 0, 1, 2], [1, 1, 2])

Explanation: Use first-fit: 'ab' and 'c' go to row 0, 'def' to row 1, and 'gh' to row 2.

Input: (['aaaa', 'bbbb', 'cccc', 'd'], 4)

Expected Output: None

Explanation: The first three strings exactly fill the three rows, so the last string cannot be placed.

Input: ([], 5)

Expected Output: ([], [5, 5, 5])

Explanation: No strings are placed, so all rows keep their full width.

Input: (['', 'ab', '', 'c'], 2)

Expected Output: ([0, 0, 0, 1], [0, 1, 2])

Explanation: Empty strings consume zero width and still follow the first-fit rule.

Hints

  1. Because there are only 3 rows, you can check all rows for every string in constant time.
  2. Keep an array of remaining capacities and update it as you place strings.

Part 3: Place Strings into Three Rows - Most Remaining Space

You are given a list of strings and exactly 3 rows. Each row starts with width W, and placing a string consumes len(string) units from that row. Process the strings in order. For each string, consider all rows that have enough remaining space and place the string into the row with the most remaining space before placement. If multiple rows tie, choose the smallest row index. If no row can fit the current string, return None. Otherwise return the row chosen for each string and the final remaining space in the 3 rows.

Constraints

  • 0 <= len(strings) <= 200000
  • 0 <= W <= 1000000000
  • There are exactly 3 rows indexed 0, 1, and 2
  • The width of a string is len(string)

Examples

Input: (['aa', 'b', 'cc', 'd'], 3)

Expected Output: ([0, 1, 2, 1], [1, 1, 1])

Explanation: Each step chooses the row with the most free space among those that can fit the current string.

Input: (['aaa', 'bbb', 'ccc', 'd'], 3)

Expected Output: None

Explanation: The first three strings fill the three rows completely, so the last string cannot be placed.

Input: ([], 2)

Expected Output: ([], [2, 2, 2])

Explanation: No strings means nothing is placed.

Input: (['a', 'a', 'a', 'a'], 2)

Expected Output: ([0, 1, 2, 0], [0, 1, 1])

Explanation: The first three strings spread across the rows, then the final tie on remaining space is broken by choosing the smallest row index.

Hints

  1. For each string, compare the remaining capacities of all rows that can fit it before you subtract the string length.
  2. You can enforce the tie-break naturally by scanning rows from 0 to 2 and only replacing the current best when you find a strictly larger remaining capacity.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Build a Weekly Calendar - Robinhood (medium)
  • Solve path and inventory problems - Robinhood
  • Aggregate user logs into 30-minute sessions - Robinhood (hard)
  • Count Referral Descendants - Robinhood (medium)
  • Compute dependency load factors in a DAG - Robinhood (medium)