Skip to content

Log Line Shape Template accepts a solution that skips the word count check #741

Description

@April-ying

Observed behavior

In Log Line Shape Template (word-pattern, LeetCode 290), the built-in tests accept a solution that never checks whether the message has as many words as the template has letters. It passes 7/7, the same as a correct solution.

class Solution:
    def matchesTokenTemplate(self, pattern: str, s: str) -> bool:
        words = s.split(" ")
        pairs = set(zip(pattern, words))
        return len(pairs) == len(set(pattern)) == len(set(words))

zip stops at the shorter sequence, so template letters past the last word are never compared. On ["abba", "dog cat cat"] it sees only a-dog, b-cat, b-cat, counts two letters, two words and two pairs, and returns true. The answer is false: the template has four letters and the message has three words, and Jim's clarification says a message with more or fewer words than the template has letters does not match. The only built-in case with a count mismatch, ["abba", "dog cat cat dog fish"], has an extra word that is also a new distinct word, so the distinct counts already disagree there and the tests cannot tell the two solutions apart. Since every language runs the same judge cases, the gap is not specific to Python.

Expected behavior

At least one built-in case has fewer words than the template has letters, such as ["abba", "dog cat cat"] expecting false, so this solution fails the tests. A correct solution still passes every case.

Reproduction

  1. Run CodeTrial at the revision below, start a Practice interview on Log Line Shape Template (Coding only, Editor), and keep Python.
  2. Paste the solution above and run the tests. Test results shows 7/7: every built-in case passes.
  3. Under "Add a case", enter ["abba", "dog cat cat"] as the input and false as the expected value, then run again. Under "Your cases" the new case fails with got true.

CodeTrial version

codetrial 0.1.0 (dad7b6e), built from source. The judge for this problem is unchanged between dad7b6e and main at 9f9adee.

Environment

OS: Windows 11 with the server in WSL2
Browser: Chrome 157.0.8103.78
Language: Python
Interview loop: Coding only
Problem: Log Line Shape Template (LeetCode 290)
REACTO or STAR step: Test
Reconnect: None

Sanitized evidence

All 7 built-in cases pass, and the added case fails with got true:

Log Line Shape Template

I would like to fix this by adding that case to problem-bank/judges.json and regenerating the judges. Please assign it to me.

Public data confirmation

  • I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.

Activity

  1. added theissue type on Nov 16, 2026
  2. jserv commented on Nov 16, 2026

    @jserv
    Contributor

    @April-ying Confirmed on main (9f9adee): problem-bank/judges.json gives log-line-shape-template seven cases, and the only word-count mismatch, word count mismatch (["abba", "dog cat cat dog fish"]), has an extra word that is also a new distinct word, so the distinct counts already disagree and a zip-based solution passes it. Accepted as scoped: add a case with fewer words than the template has letters, ["abba", "dog cat cat"] expecting false, to problem-bank/judges.json, regenerate with python3 scripts/gen-problems.py as docs/adding-a-problem.md describes, and check that a correct solution still passes every case. Open the pull request with Close #741.

  3. added 10 commits that reference this issue on Nov 17, 2026
    52992d6
    fd4bc5f
    f493b3c
    4352840
    fb80159
    b644c6c
    ab38ff8
    d872702
    48cb132
    72ac27e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions