Skip to content

Fail mirrored runs copied from the reversed read - #852

Open
hankliuliu wants to merge 6 commits into
sysprog21:mainfrom
hankliuliu:fail-reversed-copy-mirrored-run
Open

hankliuliu wants to merge 6 commits into
sysprog21:mainfrom
hankliuliu:fail-reversed-copy-mirrored-run

Conversation

@hankliuliu

@hankliuliu hankliuliu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

In Mirrored Tag Segment (longest-palindromic-substring, LeetCode 5), several wrong scans passed all five judge cases, because every read happened to give each of them a longest mirrored stretch. The one the issue reports returns the longest common substring of the read and its reversed copy without checking that the result is itself mirrored, the approach the LeetCode editorial for problem 5 warns about. The others expand odd centres but keep an adjacent equal pair as it stands, skip the centres at the ends of the read or stop the even centres one short of the last pair, compare characters case-folded or drop everything but letters, or everything but lowercase letters and digits, although the contract promises exact matching of digits and letters, keep the first or the last stretch that grows past one character, or settle one kind of centre, odd or even, before trying the other. The judge is what the interviewer and the report trust, so a full green run credited solutions a human interviewer would reject. Each of these now fails a case named for its read, and a correct solution passes all fifteen.

Wrong scan Case that rejects it It returns
longest common substring with the reversed copy, either tie pick mirrored ends: s="abacdfgdcaba" abacd or dcaba
adjacent equal pair never expanded whole string even: s="abba" bb
centres that skip the ends matching prefix: s="aab" a
even centres that stop before the last pair matching suffix: s="baa" b
case-folded comparison mixed case: s="aA" aA
everything but letters dropped digit at the centre: s="ab1ba" abba
everything but lowercase letters and digits dropped capital at the centre: s="abBba" abba
first or last stretch past one character middle mirror: s="abacdedcfgf" aba or fgf
odd centres settled before even ones even mirror beats odd mirror: s="abacca" aba
even centres settled before odd ones odd mirror beats even mirror: s="aabcb" aa

Approach

Each added read gives one family a wrong answer, so each case is needed, and none depends on which tied stretch an implementation keeps. The browser regression in tests/browser/compiler-explorer.test.js writes centre expansion once and states each scan built on it as the one thing it changes (the centres it visits, how two characters compare, which stretch it keeps, which kind of centre it tries first), so the copies cannot drift apart; the reversed-copy shortcut and the unexpanded pair stay loops of their own, since neither is centre expansion with one option changed. Every scan runs by name against the case pinned for it, with the exact string it returns and the palindrome checker's refusal asserted, and centre expansion runs through the checker on every case. The palindrome checker reads only the length of a case's expected, so a wrong recorded answer could pass every run and be shown as the answer; tests/browser/judge-case-counts.test.js, beside the other bank-wide judge invariant, now runs every judge case's expected through its own checker, which proves membership while the shortcut test pins the length. Labels describe the read, not the shortcut, and pass rules.check_labels; tests/web/contract.rs pins all ten; web/judges/mirrored-tag-segment.json and the digest in tests/golden/task-posed.json are regenerated, not hand-edited. The page example names case 4, so it still shows the same read. The cases arrive in five commits and the bank-wide check in a sixth, each under the interactive-review threshold.

Validation

The branch sits on current main (9817ef6). ./scripts/test.sh ran to the end twice on this head. The second run passed every gate; its browser lane passed 3809 of 3843 with 34 skipped for javac and java, and it ended:

not checked by this run:
  desktop clippy and tests: libwebkit2gtk-4.1-dev builds desktop/
  python tests, test_the_tool_finds_an_interpreter_that_can_build (test_task_authoring.TaskAuthoringTests.test_the_tool_finds_an_interpreter_that_can_build): the tests run outside a venv
  browser tests, 14 skipped: javac is not available
  browser tests, 20 skipped: javac/java are not available

The first run failed one browser test, explicit Start mixes tab audio and the existing mic into a downloadable WebM in tests/browser/local-recorder.test.js, where the 440 Hz level of the recording came out at 0.0065 against a floor of 0.01. It passed 6 runs of 6 on its own and 12 of 12 run four at a time, both on this head and on 2612c5f, and this change touches no recording code, so I left it out of this pull request. Not checked here: desktop clippy and tests, and the Java harness runs.

Beyond the scans the test names, 29 single-change wrong variants of centre expansion, the DP table and brute force (centre ranges and loop bounds, slice ends, character filters, comparisons, which stretch is kept, centre order) were run against the fifteen cases, and each fails at least one; the variants that still pass are equivalent to a correct scan, such as skipping the odd centres at the ends, which only ever yield one character. Dropping either new case, or making its read lowercase, fails the suite by the case's name, and the centre-visiting predicate gives the same answer as the scan it replaced on every read over abA1 up to six characters and on 30,000 random reads over abAB1 up to nine.

Close #850


Summary by cubic

Adds ten longest-palindromic-substring judge cases so wrong scans that previously passed every existing case now fail. The judge gave a full green run to solutions an interviewer would reject: returning the longest common substring of a read and its reversed copy without checking the result is mirrored, keeping an adjacent equal pair instead of expanding it, skipping the centres at the read's ends, comparing characters case-folded, dropping everything but letters or dropping capitals too, stopping even centres one short of the last pair, keeping the first or last stretch that grows past one character, and settling odd or even centres before trying the other. Each scan now fails a case named for its read, and a correct centre-expansion solution passes all fifteen cases.

Regression coverage

  • Runs each wrong scan by name against its pinned case, asserting the exact string it returns and that the checker refuses it, plus a centre-expansion reference against every case.
  • Runs every judge case's expected value through its own checker, so a wrong recorded answer can no longer slip into any judge.
  • Pins the ten new labels in tests/web/contract.rs; the regenerated judge file and golden digest follow automatically. Closes Mirrored Tag Segment accepts reversed-copy common-substring solutions #850.

Written for commit 8706f02. Summary will update on new commits.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@hankliuliu
hankliuliu force-pushed the fail-reversed-copy-mirrored-run branch from e69ec3c to 0bdce44 Compare November 25, 2026 10:42

@haruuu1214 haruuu1214 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.

Thanks, the new case clearly blocks the reversed-copy common-substring shortcut, and running both tie-break variants makes the regression convincing. Using checkAnswer instead of assertRejects is also the right choice here, because a palindrome answer can have several valid strings.

Two small comments:

  1. Line 1056: assert.equal(answer, copied) needs a failure message like the other assertions.
  2. Lines 1038-1041: the check that expected passes the checker could move into a general test over all palindrome judges.

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

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as outdated.

jserv

This comment was marked as outdated.

@hankliuliu
hankliuliu force-pushed the fail-reversed-copy-mirrored-run branch from 0bdce44 to f67b2d6 Compare November 25, 2026 13:11
@jserv
jserv dismissed their stale review November 25, 2026 13:13

No merge conflicts at the current head.

jserv

This comment was marked as resolved.

@hankliuliu
hankliuliu force-pushed the fail-reversed-copy-mirrored-run branch from f67b2d6 to 4a5c445 Compare November 25, 2026 13:57
illdoCc

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@github-actions github-actions Bot added the ready for maintainer review The pull request ready for maintainer review. label Nov 25, 2026
jserv

This comment was marked as resolved.

@github-actions github-actions Bot removed the ready for maintainer review The pull request ready for maintainer review. label Nov 26, 2026
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@jserv

jserv commented Nov 26, 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 9c2d717.

jserv

This comment was marked as outdated.

All five Mirrored Tag Segment cases happen to share a palindromic
longest common substring with their reversed copy, so the shortcut the
LeetCode 5 editorial warns about, returning that substring with no
mirror check, passed 5/5. The added read ends with the reverse of its
non-palindromic prefix and its longest mirrored stretch is only three
characters, so every common substring of length four or more now fails
on length and palindromicity alike. The browser regression runs the
shortcut and a centre-expansion reference against the cases, so a
later edit cannot quietly let the shortcut back in.

Close sysprog21#850

Change-Id: I11a38840cd414fb4b10fc8c971d1a9a41f5d7ae3
No case's longest mirrored stretch had an even length above two, so a
solution that expands odd centres but keeps an adjacent equal pair as
it stands passed all six cases: the pair is the full answer for
"cbbd" and too short to win anywhere else. The whole of "abba"
mirrors, so the bare pair "bb" now fails on length, and the
regression pins the case by label beside the reversed-copy one.

Change-Id: I3492b4a06baf344efd058389ac32018f8886f1ba
The palindrome checker reads only the length of its case's expected
value, so a judge could carry a wrong expected answer, pass every
run, and show that value as the answer in the results panel. Running
each case's expected through its own checker catches that for every
judge at once, including the checkers that accept more than one
answer. The check proves membership, not optimality: the shortcut
regression beside it is what pins how long a longest mirrored
stretch has to be.

Change-Id: I0aaa7eed76187aa1d48d864c8d49d9ba6306db7c
Four more scans agreed with a longest mirrored stretch on every read
so far. An expansion whose centres skip the ends never sees the pair
at the very start, so "aab", whose only stretch past one character is
that pair, rejects it. Every read was lowercase letters, so a scan
comparing case-folded characters passed although the contract
promises exact comparison, and so did one that drops everything but
letters; "aA" rejects the first, and "ab1ba", mirrored through its
digit, rejects the second. The first stretch that grows past one
character, like the last, is a longest one in every current read, so
"abacdedcfgf" puts its only five-character stretch between a shorter
one on each side and rejects both picks. The regression writes centre
expansion once and states each scan as the one thing it changes, so
the copies cannot drift apart, and runs each by name against its
pinned case.

Change-Id: Ib026eca612139649d943073b69be66fc2c97d4f1
Odd and even centres never competed in any read: wherever the longest
stretch was even, no odd one grew past one character, and the
reverse. A scan that settles odd centres first and tries even ones
only when nothing grew passed every case, and so did its mirror
image. "abacca" holds the even "acca" beside the odd "aba", and
"aabcb" the odd "bcb" beside the even "aa", so each read rejects one
order. Both scans are run by name beside the others.

Change-Id: I7ad86960b89ed7352a38bc0187c8526683a01f2e
@hankliuliu
hankliuliu force-pushed the fail-reversed-copy-mirrored-run branch from 9c2d717 to 2612c5f Compare November 26, 2026 13:23
Comment thread problem-bank/judges.json Resolved
Comment thread problem-bank/judges.json Resolved
Every longest stretch so far was lowercase letters and digits, and no
read ended in its only even pair, so two more scans passed all thirteen
cases. One drops everything but lowercase letters and digits before
expanding, the counterpart of the letters-only scan, although the
contract compares upper and lower case exactly: "abBba" mirrors through
its capital, and that scan returns "abba". The other stops its even
centres one short and never tries the pair at the very end of a read, so
"baa", whose only stretch past one character is that pair, rejects it as
"aab" rejects a scan missing the pair at the start. Centre expansion now
takes the centres it visits as a predicate, so the scan skipping the
ends and the one skipping the last pair are each one call, and both new
scans run by name beside the others.

Change-Id: Ie66656d7e98c51c8c459aad030b36929ccd775f1
Comment thread problem-bank/judges.json
"expected": "acca"
},
{
"label": "odd mirror beats even mirror: s=\"aabcb\"",

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.

No read here has three equal characters in a row, so a scan that tries only one kind of centre at each position, the even one when the next character matches and the odd one otherwise, passes every case. On baaab it expands the pair at the first aa, then the pair at the second, and returns aa, never trying the odd centre on the middle a that gives baaab. A read such as s="baaab" expecting baaab rejects it; its label would join the ones tests/web/contract.rs pins, and the scan would run by name in the mirrored tag test like the others.

@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 rework the series into functionally minimal commits, folding similar ones and enforcing the project's commit message 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.

Mirrored Tag Segment accepts reversed-copy common-substring solutions

5 participants