Mirrored Tag Segment accepts reversed-copy common-substring solutions

Open
#850 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@hankliuliu is already working on this.

Since Nov 25, 2026.

  • #852 by @hankliuliu — open

Assessment

This issue has not been assessed yet.

Description

Observed behavior

In Mirrored Tag Segment (longest-palindromic-substring, LeetCode 5), the Python solution below passes all five built-in tests. It takes the longest common substring of the read and its reversed copy and never checks that the result reads the same both ways. The brief says the scanner reads a tag forwards and backwards, so comparing the two directions is the first thing a candidate will try.

class Solution:
    def longestMirroredRun(self, s: str) -> str:
        r = s[::-1]
        n = len(s)
        best_len, best_end = 0, 0
        prev = [0] * (n + 1)
        for i in range(1, n + 1):
            cur = [0] * (n + 1)
            for j in range(1, n + 1):
                if s[i - 1] == r[j - 1]:
                    cur[j] = prev[j - 1] + 1
                    if cur[j] > best_len:
                        best_len, best_end = cur[j], i
            prev = cur
        return s[best_end - best_len:best_end]

All five current cases (babad, cbbd, a, ac, racecar) happen to have a palindromic longest common substring with their reverse, so the palindrome checker in web/lib.js accepts the shortcut 5/5. The LeetCode editorial for problem 5 warns about this approach: it breaks when a reversed copy of a non-palindromic substring appears elsewhere in the string.

Expected behavior

At least one built-in case contains a reversed copy of a non-palindromic substring, so the common-substring shortcut returns a stretch that is not mirrored and fails. A correct solution still passes every case.

Reproduction
  1. Run CodeTrial at the revision below and open Mirrored Tag Segment with Python.
  2. Paste the solution above and run the tests. All five built-in cases pass.
  3. Under "Add a case", enter ["abacdfgdcaba"] as the input and "aba" as the expected value, then run again. The new case fails: the solution returns abacd (its prefix, echoed backwards at the end of the read), which has length 5 and is not mirrored, while the longest mirrored stretch is aba with length 3.

Any common substring of length 4 or more must fail here, because the longest palindrome in abacdfgdcaba has length 3; the checker rejects the wrong answer on both length and palindromicity, so the case holds regardless of which length-5 candidate (abacd or dcaba) an implementation prefers.

CodeTrial version

codetrial 0.1.0 (5c1fdce), built from source at current main.

Environment
  • OS: Windows 11 host with Ubuntu 24.04 under WSL2
  • Browser: Chrome
  • Language: Python
  • Interview loop: Coding
  • Problem: Mirrored Tag Segment (Longest Palindromic Substring, LeetCode 5)
  • REACTO or STAR step: Test
  • Reconnect: Not applicable; this report concerns test-case coverage
Sanitized evidence
Solution Existing 5 cases With abacdfgdcaba added
Common-substring shortcut above 5/5 5/6 (returns abacd)
Centre-expansion reference 5/5 6/6

The table comes from running both solutions against the cases in problem-bank/judges.json under the palindrome checker's rules (string, equal length, substring of the input, mirrored). The screenshots below show the browser reproduction at 5c1fdce: the solution above passes all five built-in cases, and the added case fails with got "abacd" while the interviewer, seeing the green run, asks about complexity as if the solution were correct.

01-shortcut-passes-5-of-5 02-added-case-fails-got-abacd
Public data confirmation
  • I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.
Proposed scope

I read docs/adding-a-problem.md. I would add ["abacdfgdcaba"] with expected "aba" to problem-bank/judges.json under a label that describes the read rather than the shortcut, and regenerate the derived files. As the stock III test in tests/browser/compiler-explorer.test.js does, the regression would run the common-substring shortcut against every case and assert a centre-expansion reference passes all of them while the shortcut fails the added one, so a later edit to a case cannot quietly let it back in. Could you assign this to me?

Dominant language
Rust
Stars
236
Forks
153
Avg merge
1d 9h
Merged PRs (30d)
187

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sysprog21/codetrial

All issues in sysprog21/codetrial

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.