fix: repair all article solutions that deterministically fail on the NC judge - #6051
fix: repair all article solutions that deterministically fail on the NC judge#6051neetcode-gh wants to merge 5 commits into
Conversation
Article Go snippets are spliced into a judge driver that already declares
`package main` and its own import block, so a snippet can neither add an
import nor pull in a third-party module. Every Go solution that used
github.com/emirpasic/gods therefore failed to compile on the judge.
Rewrites all 28 affected tabs to the standard library only:
- priorityqueue.Queue -> container/heap with a local sort.Interface type
- linkedliststack -> plain slice used as a stack
- arrayqueue /
linkedlistqueue -> plain slice used as a queue
- redblacktree /
treemap -> count map + sorted slice, binary searched with
sort.Search / sort.SearchInts
The drivers already provide container/heap, sort, math and friends
ambiently, so none of the new snippets declare imports. Published
structure and naming are kept as close to the originals as possible.
Also removes a stray `import "container/heap"` from the
design-a-leaderboard "Heap for top-K" tab, which failed to compile for the
same reason (redeclared / imported and not used against the driver block).
Behaviour is preserved throughout. Two latent bugs disappear as a side
effect: hand-of-straights now bounds-checks the heap before peeking, and
design-a-leaderboard Reset no longer decrements the count for score 0 when
the player is absent.
Every rewritten tab was run against the production judge
(test-problem-article-solutions.ts --lang go); all 29 pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The Binary Exponentiation (Iterative) JavaScript snippet was the only one of the article's nine languages that ran the bit loop on a value that does not fit in a signed 32-bit integer. `Math.abs(-2147483648)` correctly produces `2147483648` (JS numbers are doubles), but `&` and `>>=` apply ToInt32 to their operands first. So `power & 1` evaluates `-2147483648 & 1` -> `0` (the multiply is skipped) and `power >>= 1` evaluates `-2147483648 >> 1` -> `-1073741824`, which fails the `power > 0` guard. The loop exits after a single iteration with `res` still 1. On LeetCode's own published test case `x = 2.00000, n = -2147483648` (expected `0.00000`) the snippet returned `1`. Every other language already widens to 64 bits before the loop -- `Math.abs((long)n)` in Java/C#, `abs((long)n)` in C++, `(n as i64).abs()` in Rust, `n.toLong()` in Kotlin, 64-bit `Int`/`int` in Swift/Go, and arbitrary precision in Python -- so none of them were affected. The article's own "Integer Overflow When Negating n" pitfall section documents exactly this trap. Fixed by using arithmetic instead of bitwise operations, which keeps `power` a full-precision double: `power % 2 === 1` and `Math.floor(power / 2)`. The recursive JavaScript solution already did this and was correct. Also extended the pitfall section with the JavaScript-specific form of the trap. Verified against the NeetCode judge: all 9 languages pass both binary exponentiation approaches, including an `x = 2.00000, n = -2147483648` case that the previous JavaScript code failed with Wrong Answer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…/judge-article-failures
…/judge-article-failures
- time-based-key-value-store Brute Force (all 9 languages): a value set at
timestamp 0 was unreachable — the 'seen' sentinel collided with a legal
timestamp. Use -1 (timestamps are >= 0 on the site). Also make the C# tab
take the max like every other tab instead of relying on insertion order.
- palindrome-partitioning rust Recursion + Backtracking (DP): 'i + l - 2'
underflows usize when l = 1, i = 0, panicking at runtime on every input.
Compute j = i + l - 1 and guard with l <= 2.
- copy-linked-list-with-random-pointer rust (all 5 tabs): replace the
index-based placeholder stubs ('LeetCode does not support Rust') with real
implementations against Option<Rc<RefCell<Node>>>, including both O(1)
extra-space variants.
- kth-smallest-integer-in-bst: kotlin Morris assigned through nullable
receivers and did not compile — rewritten null-safely. The go and kotlin
Brute Force tabs did an inorder collect (no sort), a different algorithm
from the python/java tabs under the same heading — now collect + sort.
- longest-substring-without-duplicates: the swift Brute Force snippet was
fenced as kotlin, so kotlin appeared twice and swift had no coverage.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@coderabbitai review |
|
@greptileai review |
|
bugbot run |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
|
@coderabbitai review |
|
@greptileai review |
|
Review loop tally: CodeRabbit and Greptile were triggered twice (~18:48Z and ~18:36Z cycles) and stayed silent; neither app has ever reviewed a PR in this repo (checked #6039/#6044 history) and Bugbot is disabled here, so bot review is not available on this repo. Verification instead ran against the live judge: 20 problems × 2 runs each via test-problem-article-solutions.ts — every previously-failing deterministic approach×language combo now passes; remaining failures are the pre-existing Brute Force time-limit tier only. Ready for review/merge — merging this PR also marks #6039 and #6044 as merged (their branches are included). |
Summary
A 4-runs-per-combo soak of every article approach × language across 72 problems against the live judge surfaced a set of deterministic (4/4) failures. This PR fixes all of them on the article side. It includes #6039 (Go stdlib heap/stack rewrites) and #6044 (pow-x-n JS INT_MIN fix) as merges — merging this PR marks both as merged — and adds one commit on top:
seensentinel of0collided with a legal timestamp (site contract is0 <= timestamp <= 10^7). Sentinel is now-1. The C# tab also now takes the max qualifying timestamp like every other tab instead of relying on dictionary insertion order.RecursionandBacktracking (DP): the palindrome-table fill computedi + l - 2, which underflowsusizeatl = 1, i = 0and panics at runtime on every input (the judge saw empty output). Now computesj = i + l - 1guarded byl <= 2.Option<Rc<RefCell<Node>>>type, including both O(1) extra-space interleaving variants.Morris Traversal: assigned through nullable receivers and did not compile; rewritten null-safely. Go/KotlinBrute Force: these tabs did an inorder collect with no sort — a different algorithm from the python/java tabs under the same heading; now collect + sort like the rest.```kotlin, so kotlin appeared twice and swift had zero coverage.Verification
Every touched problem was run twice (three times for time-based-key-value-store) through
test-problem-article-solutions.tsagainst the live judge — 20 problems, 41 runs total. All previously-failing deterministic combos now pass. The only remaining failures are the known pre-existing time-limit tier (Brute Force TLEs) and the kth-largest Quick Select python stress-case issue tracked separately on the site side.Companion PR on the site repo enriches four judge drivers (swift
Node: Hashable, kotlin/swift 3-argTreeNode, swift 2-argListNode) that three of these fixes rely on.🤖 Generated with Claude Code