fix(go): replace emirpasic/gods with Go stdlib in article solutions - #6039
Open
neetcode-gh wants to merge 1 commit into
Open
fix(go): replace emirpasic/gods with Go stdlib in article solutions#6039neetcode-gh wants to merge 1 commit into
neetcode-gh wants to merge 1 commit 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>
Owner
Author
|
@coderabbitai review |
Owner
Author
|
@greptileai review |
Owner
Author
|
bugbot run |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Article Go solutions that used
github.com/emirpasic/godscannot run on the judge.On the platform, an article's Go snippet is spliced into a per-problem driver that already declares
package mainand owns the entire import block:A snippet therefore cannot add an import, and a third-party module could not be resolved even if it could. Every
gods-based Go tab failed to compile.An earlier approach — teaching the drivers to import
gods— was abandoned. Rewriting to the standard library is the maintainer-confirmed fix.Change
All 28 affected Go tabs rewritten to stdlib only:
priorityqueue.NewWith(...)container/heap+ a localsort.Interfacetypelinkedliststackarrayqueue/linkedlistqueueredblacktree/treemapsort.Search/sort.SearchIntsBecause the driver already provides
container/heap,sort,mathand the rest ambiently, none of the new snippets declare imports. Published structure and naming are kept as close to the originals as possible, and behaviour is preserved throughout.Also removes a stray
import "container/heap"from the design-a-leaderboard Heap for top-K tab — not agodstab, but broken on the judge for exactly the same reason (heap redeclared in this block/"container/heap" imported and not used).Two latent bugs disappear as a side effect:
nilpeek of an empty queue).Resetno longer decrements the count for score0when the player is absent.Where Go lacks an ordered-map equivalent (design-a-leaderboard, longest-continuous-subarray-…), a short comment explains the count-map + sorted-slice modelling so the article still reads as a teaching text.
Verification
Every rewritten tab was executed against the production judge via
test-problem-article-solutions.ts --lang go, sequentially with a 250 ms delay. 29/29 pass.The sweep ran every Go tab of each affected problem, not just the rewritten ones. The only failures anywhere were pre-existing
Brute Forcetime-limit-exceeded results on minimum-interval-including-query, sliding-window-maximum, swim-in-rising-water and trapping-rain-water — all untouched by this PR and already failing onmain.Judge config the runs were made against
Run against a
neetcode.ioworking tree carrying in-progress per-language time-limit calibration. Per-problem comparison againstneetcode.iomain:go: 0.4) and meeting-schedule-ii (go: 0.5) — limits identical tomain.golimit on either branch, so both ran on the default 2.5 s CPU allowance, same asmain.go: 0.45exists only on the unmerged calibration branch;mainhas nogoentry and would use the 2.5 s default. This tab was therefore verified under a stricter limit thanmainenforces.timeLimitsentry at all and ran on the default, identical tomain.So every result above holds under
main's configuration.Out of scope
Three articles still use
gods—data-stream-as-disjoint-intervals,design-a-food-rating-system,seat-reservation-manager. None has a Go judge directory, so their rewrites could not be verified and are deliberately left alone.Separately, ~44 Go blocks across ~30 other articles still carry
importlines and will fail on the judge for the same reason as the design-a-leaderboard tab fixed here. That is a broader cleanup, tracked separately rather than bundled into this PR.