Repository navigation
Add consolidation cases to merge-intervals - #854
ye144440154 wants to merge 1 commit into
Conversation
f78861c to
aec794f
Compare
yansawu
left a comment
There was a problem hiding this comment.
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.
|
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
aec794f to
f0394c0
Compare
| ] | ||
| }, | ||
| { | ||
| "label": "overlapping windows apart in the input: [[1,3],[5,6],[2,4]]", |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Problem and behavior
In Maintenance Window Consolidation (
merge-intervals), five wrong solutions passed all five cases:[[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 windowandoverlapping windows apart in the input. All inputs are inside the stated constraints (1 <= intervals.length,0 <= start_i <= end_i <= 10^4). The labels passcheck_labelsinscripts/problem_bank/rules.pyand join the tricky-case list intests/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.pyregeneratedweb/judges/maintenance-window-consolidation.json, and themerge-intervalsdigest intests/golden/task-posed.jsonis recomputed the waytests/test_task_package.pycomputes it.A test in
tests/browser/compiler-explorer.test.js, next to theremove-elementone, 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, throughcheckAnswer, sinceassertRejectscompares withassert.notEqualand 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.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.shatf0394c0e, on07f1d007, on Ubuntu 22.04 under WSL2, rustc 1.100.0, Node 26.13.1, Clang 23 fromscripts/fetch-clang.sh: every gate passes. Not checked by that run: desktop clippy and tests (nolibwebkit2gtk-4.1-dev).Close #844