← 返回 scale.ai 的题目列表Party Time Blocks
类型:qbank
Given party intervals by neighborhood, compute party-time blocks and no-party gaps. The prompt emphasizes interval sorting, timestamp parsing, output-format precision, and production test design.
Requirements
Input describes party intervals grouped by neighborhood or block.
For each neighborhood, find the party-time block boundaries: the earliest start and latest end for the active party interval group.
Sort intervals by start_time before scanning.
Find time ranges where no party is active.
Time values may arrive as timestamp strings; one implementation detail is extracting the hour component with a helper such as get_hour rather than assuming a pre-parsed integer.
Output format matters. One version expects an integer and dictionary-shaped output rather than a free-form list.
Follow-up: design production unit tests for the implementation.
Notes
Treat this as an interval aggregation problem. The safe skeleton is: normalize timestamps, group by neighborhood, sort intervals by start, merge or scan active windows, then emit the requested gaps / blocks.
The highest-risk part is not the algorithm; it is reading the output contract exactly and normalizing timestamps consistently.
If the interviewer asks for production readiness, cover boundary tests: empty input, single interval, touching intervals, overlapping intervals, malformed timestamps, unsorted input, and multiple neighborhoods.
Preparation
Practice a standard interval-merge implementation and a gap-finding scan from sorted intervals.
Write a small timestamp-normalization helper and test it before integrating it into the interval scan.
Prepare a compact unit-test matrix that covers overlap, adjacency, gaps, and output-shape validation.