Is Subsequence judge accepts frequency-only solutions that ignore character order

Offen
#775 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@ChenYingHan1121 arbeitet bereits daran.

Seit 19.11.2026.

  • #777 von @ChenYingHan1121 — offen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

Problem

The is-subsequence judge does not currently test whether a solution preserves the relative order of characters.

As a result, an incorrect frequency-count implementation passes all five existing judge cases, even though it does not satisfy the problem statement.

Steps to Reproduce

The judge is defined in problem-bank/judges.json under is-subsequence.

I compared two implementations against the existing five cases:

  • Incorrect implementation: Counts character frequencies in t and checks whether all characters of s are available, ignoring order.

  • Correct implementation: Uses two pointers to match the characters of s in their original order within t.

Both implementations passed all five existing cases.

Implementation Existing cases passed
Frequency-count implementation (incorrect) 5/5
Two-pointer implementation (correct) 5/5

Minimal Counterexample

s = "ab"
t = "ba"

Expected result: false

Actual result from the incorrect frequency-count implementation: true

Both characters exist in t, but they appear in the wrong order. Therefore, s is not a subsequence of t.

The correct two-pointer implementation returns false.

Proposed Fix

Add an order-sensitive case to the is-subsequence judge:

{
  "label": "reversed character order",
  "input": ["ab", "ba"],
  "expected": false
}

This test rejects the frequency-count implementation while allowing the correct two-pointer implementation.

Verification

I reproduced the issue locally using the actual five cases loaded from problem-bank/judges.json.

Results:

  • Incorrect frequency-count solution: 5/5 existing cases passed.

  • Correct two-pointer solution: 5/5 existing cases passed.

  • Proposed reversed-order case: incorrect solution failed; correct solution passed.

The local reproduction directly compared outputs against the JSON judge cases. It did not execute the full browser runner.

No production-code changes are needed.

Vorherrschende Sprache
Rust
Sterne
236
Forks
153
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
187

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus sysprog21/codetrial

Alle Issues in sysprog21/codetrial

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.