Repository navigation
Add sliding-window cases to longest-substring - #858
ye144440154 wants to merge 1 commit into
Conversation
ea98694 to
b695822
Compare
sakinu
left a comment
There was a problem hiding this comment.
The new case rejects both shortcuts the description names, and its expected value checks out. Requesting changes because the judge still accepts wrong answers: the open thread on the test file shows one, and the comment on problem-bank/judges.json shows a second that only a case with its longest stretch away from both ends can catch.
|
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 b695822. |
b695822 to
3c06811
Compare
3c06811 to
1605c3e
Compare
1605c3e to
abac7a7
Compare
Eleven wrong solutions passed every Distinct Keystroke Stretch case. Two drop the whole stretch at a repeat: one clears it and starts again at the repeated key, the other moves the left edge to the repeat itself instead of one past its earlier copy. On "dvdf" both lose the v between the two d's and return 2 instead of 3. A third moves the left edge one key per repeat, with if where while belongs, and returns 4 on "abccad", whose longest stretch is 3. A fourth measures only the stretch from the first key and the one ending at the last key; every case has a longest stretch touching an end, so it passed, and it returns 1 on "aabcdaa", whose longest stretch is 4. A fifth starts its edge at 0 instead of -1, so a stretch from the first key comes out one short; it passed because no case has its only longest stretch at the start, and it returns 2 on "abc". A sixth measures a stretch only when a repeat ends it, so the last one is never counted, and returns 0 on "abc". Every input was lowercase letters, so lowercasing s first, or dropping digits, symbols and spaces, passed too, though the contract compares case-sensitively and counts every character; on "aA 1" they return 3 and 2 instead of 4. No input had a space at an end or a repeated key outside a to z, so trimming s, dropping symbols, or a last-seen table of 26 slots that skips every other key passed as well; on " A!1 " they return 3, 3 and 5 instead of 4. The six inputs become new cases. A test in tests/browser/compiler-explorer.test.js runs each solution against its case, 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. The existing left-edge entry there now names its whole label, which the new left-edge label would otherwise satisfy, and the task preview golden takes the judge's new hash. Close sysprog21#857 Change-Id: Ie15579e63be1b975312cea211e0773647322d815
abac7a7 to
7e23871
Compare
| { | ||
| "label": "space before and after the keys", | ||
| "input": [ | ||
| " A!1 " |
There was a problem hiding this comment.
Trimming only one end still passes all eleven cases: " A!1 " has two longest stretches, " A!1" and "A!1 ", each holding one of the two spaces, so s.rstrip() or s.lstrip() in Python (trimEnd() or trimStart() in JavaScript) leaves a stretch of 4 and only trimming both ends returns 3. Since the space repeats, no single input can have its only longest stretch hold both end spaces, so this takes a case for each side: " abca" expecting 4 rejects trimming the start (3), and "abca " expecting 4 rejects trimming the end (3). Each would need a pin in tests/web/contract.rs and a one-sided trim added to the shortcuts in the browser test, the way trimmed is.
Problem and behavior
In Distinct Keystroke Stretch (
longest-substring-without-repeating-characters), eleven wrong solutions passed all five cases:ifwherewhilebelongs);sfirst;atoz.The first two lose the
vbetween the twods of"dvdf"and return 2 instead of 3. The third returns 4 on"abccad", whose longest stretch is"cad", 3. The fourth passed because every case has a longest stretch touching an end of the string; on"aabcdaa"it returns 1 instead of 4 ("abcd"). The fifth passed because no case has its only longest stretch at the start; on"abc"it returns 2 instead of 3, and the sixth returns 0. The last two passed because every input was lowercase letters, while the contract compares case-sensitively and counts every character; on"aA 1"they return 3 and 2 instead of 4. The last three passed because no input had a space at an end or a repeated key outsideatoz; on" A!1 "they return 3, 3 and 5 instead of 4. With this change all eleven fail, and a correct solution passes all eleven cases.Approach
Six cases join the judge:
repeat in the middle of the stretch"dvdf"left edge jumps more than one key"abccad"longest stretch away from both ends"aabcdaa"every key distinct"abc"case and symbols count"aA 1"space before and after the keys" A!1 "The inputs are inside the stated constraints (
0 <= s.length <= 5 * 10^4, letters, digits, symbols and spaces). Like the other labels of this judge, the new ones describe the case without quoting the input, which the results panel shows only when the case fails. The labels passcheck_labelsinscripts/problem_bank/rules.pyand join the tricky-case list intests/web/contract.rs. That list matches each entry against the judge's labels joined together, so the existingleft edgeentry, whichleft edge jumps more than one keywould now satisfy on its own, is spelled out asleft edge must not move backward; removing the"abba"case fails the check again.python3 scripts/gen-problems.pyregeneratedweb/judges/distinct-keystroke-stretch.json, and thelongest-substring-without-repeating-charactersdigest 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 sliding window and runs each solution by name against its case throughassertRejects, which fits here because the answer is a number.Validation
node --test --test-name-pattern=longest-substring tests/browser/compiler-explorer.test.js: passes at this head. It fails on a missing pinned label when any of the five new cases is removed, and it fails, naming the solution, when the"abccad","aabcdaa","abc","aA 1"or" A!1 "input is replaced with one that solution passes ("ab c1"for lowercasing,"aAbc"for dropping non-letters,"abca"," A1 "and"A!1 A!"for the 26-slot table, dropping symbols and trimming).case and symbols count, the sixthrepeat in the middle of the stretchandcase and symbols count). Five nearby mistakes also fail at least one case: moving the left edge without checking it stays ahead, counting the distinct keys of the whole string, resetting the count only at adjacent repeats, uppercasingsfirst, and dropping only spaces. A correct solution passes all eleven.python3 scripts/gen-problems.py --check: clean.cargo test --test web: 230 passed, 0 failed, 2 ignored../scripts/test.shat7e238717, 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 #857