Skip to content

Add consolidation cases to merge-intervals - #854

Open
ye144440154 wants to merge 1 commit into
sysprog21:mainfrom
ye144440154:merge-intervals-chained-case
Open

ye144440154 wants to merge 1 commit into
sysprog21:mainfrom
ye144440154:merge-intervals-chained-case

Conversation

@ye144440154

@ye144440154 ye144440154 commented Nov 25, 2026 •

Copy link
Copy Markdown

Problem and behavior

In Maintenance Window Consolidation (merge-intervals), five wrong solutions passed all five cases:

  • merging a window with only the next one, then skipping past both;
  • absorbing at most two following windows;
  • comparing each sorted window with the previous input window instead of the merged one;
  • comparing each sorted window with the first merged window instead of the last;
  • merging neighbours in input order and sorting only the result.
Input Expected Wrong answer
[[1,3],[2,5],[4,8]] [[1,8]] [[1,5],[4,8]] (one pair)
[[1,3],[2,5],[4,8],[7,10]] [[1,10]] [[1,8],[7,10]] (two windows)
[[1,10],[2,3],[4,5]] [[1,10]] [[1,10],[4,5]] (previous input window)
[[1,2],[4,6],[5,7]] [[1,2],[4,7]] [[1,2],[4,6],[5,7]] (first merged window)
[[1,3],[5,6],[2,4]] [[1,4],[5,6]] [[1,3],[2,4],[5,6]] (input order)

They passed because no case needs a merged window to absorb more than two others, every merge in the cases lands in the first output window, and the only unsorted case has its overlapping windows next to each other in the input. With this change all five fail, and a correct solution passes all ten cases.

Approach

Each input in the table becomes a case, labelled like the rest of this judge with what the case shows and its input: chained overlaps, four windows in one chain, later window inside the first, overlap after a separate first window and overlapping windows apart in the input. All inputs are inside the stated constraints (1 <= intervals.length, 0 <= start_i <= end_i <= 10^4). The labels pass check_labels in scripts/problem_bank/rules.py and join the tricky-case list in tests/web/contract.rs; none of the new ones contains an existing entry there (unsorted, chained overlaps), so each entry still matches only its own case. python3 scripts/gen-problems.py regenerated web/judges/maintenance-window-consolidation.json, and the merge-intervals digest in tests/golden/task-posed.json is recomputed the way tests/test_task_package.py computes it.

A test in tests/browser/compiler-explorer.test.js, next to the remove-element one, checks every expected value against a sort-and-extend solution and looks each new case up by label to require that it rejects its solution, through checkAnswer, since assertRejects compares with assert.notEqual and two distinct arrays never match.

Validation

  • node --test --test-name-pattern=merge-intervals tests/browser/compiler-explorer.test.js: passes at this head. It fails on a missing pinned label when any of the three newest cases is removed, and it fails, naming the solution, when each of their inputs is replaced with one that solution passes.
  • Each of the five solutions fails its own case. Five nearby mistakes also fail at least one case: no sort, sorting by end, sorting by start descending, merging only on a strict overlap, and taking the next window's end without max. A correct solution passes all ten.
  • python3 scripts/gen-problems.py --check: clean.
  • cargo test --test web: 230 passed, 0 failed, 2 ignored.
  • ./scripts/test.sh at f0394c0e, on 07f1d007, on Ubuntu 22.04 under WSL2, rustc 1.100.0, Node 26.13.1, Clang 23 from scripts/fetch-clang.sh: every gate passes. Not checked by that run: desktop clippy and tests (no libwebkit2gtk-4.1-dev).
  • Not run locally: the C, C++ and Java harnesses on the new cases through Compiler Explorer.

Close #844

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@ye144440154
ye144440154 force-pushed the merge-intervals-chained-case branch from f78861c to aec794f Compare November 25, 2026 14:26
@ye144440154 ye144440154 changed the title Add a chained overlap case to merge-intervals Add chained overlap cases to merge-intervals Nov 25, 2026

@yansawu yansawu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new cases improve regression coverage for chained and nested intervals. However, I identified two remaining gaps in the judge coverage and provided reproducible counterexamples and concrete suggestions in the inline comments.

The proposed additions would help reject incorrect implementations that still pass the current seven built-in cases.

Comment thread tests/browser/compiler-explorer.test.js Resolved
jserv

This comment was marked as resolved.

@jserv

jserv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Some review comments on this pull request are not settled yet. Please refine the change per the review comments listed below, reply on each thread with what you changed or why you did not, and mark each thread resolved yourself once it is settled (Resolve conversation, at the bottom of the thread). The pull request stays blocked while review threads are open.

Not addressed at the current head:

Checked at aec794f.

Five wrong solutions passed all five Maintenance Window Consolidation
cases. One merges a window with only the next one and then skips past
both: on [[1,3],[2,5],[4,8]] it returns [[1,5],[4,8]] instead of
[[1,8]]. Widening that to the next two windows still passes every chain
of three, and returns [[1,8],[7,10]] for [[1,3],[2,5],[4,8],[7,10]]. One
compares each window with the previous input window instead of the
merged one, and returns [[1,10],[4,5]] for [[1,10],[2,3],[4,5]]. Every
merge in the cases lands in the first output window, so comparing with
the first merged window instead of the last passed, and returns
[[1,2],[4,6],[5,7]] for [[1,2],[4,6],[5,7]]. The only unsorted case has
its overlapping windows next to each other, so merging in input order
and sorting only the result passed, and returns [[1,3],[2,4],[5,6]] for
[[1,3],[5,6],[2,4]]. Those five inputs become new cases. A test in
tests/browser/compiler-explorer.test.js runs each solution against the
case that rejects it, looked up by label, and fails against the cases on
main; the labels join the tricky-case list in tests/web/contract.rs so
the cases stay, and the task preview golden takes the judge's new hash.

Close sysprog21#844

Change-Id: I761b4027f69f1bc7f99e698fcf8d693999424308
@ye144440154
ye144440154 force-pushed the merge-intervals-chained-case branch from aec794f to f0394c0 Compare November 26, 2026 10:18
@ye144440154 ye144440154 changed the title Add chained overlap cases to merge-intervals Add consolidation cases to merge-intervals Nov 26, 2026
Comment thread problem-bank/judges.json
]
},
{
"label": "overlapping windows apart in the input: [[1,3],[5,6],[2,4]]",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unsorted variant that folds each window into the first kept window it overlaps, then sorts the result, still passes every case here, since [2,4] touches only [1,3]:

const merged = [];
for (const [s, e] of intervals) {
  const w = merged.find(([a, b]) => s <= b && e >= a);
  if (w) { w[0] = Math.min(w[0], s); w[1] = Math.max(w[1], e); }
  else merged.push([s, e]);
}
return merged.sort(([a], [b]) => a - b);

It never merges two kept windows with each other, so on [[1,2],[5,6],[2,5]], where the last window bridges the first two, it returns [[1,5],[5,6]] instead of [[1,6]] (I ran it through checkAnswer against this head's web/judges/maintenance-window-consolidation.json). A case such as window joining two earlier ones: [[1,2],[5,6],[2,5]] expecting [[1,6]], inside the stated constraints, rejects it while sort-and-extend passes, and would join the labels pinned in tests/web/contract.rs with this variant as its own shortcut in the browser test.

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the current branch onto the upstream default branch and resolve any conflicts. Run /codetrial-review in AI agents (use $codetrial-review in Codex) and resolve all identified issues. Rework the series into minimal, logically coherent commits, squash closely related commits, and ensure all commit messages follow the project’s rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem "Maintenance Window Consolidation" accepts a solution that merges only one neighbouring pair

3 participants