Skip to content

Latest commit

 

History

History
97 lines (76 loc) · 3.9 KB

README.md

File metadata and controls

97 lines (76 loc) · 3.9 KB

Go DSA — pattern-organised, tested reference

The Go counterpart to the TypeScript work in DSA_ProblemSolving_patterns/. Same patterns, same brute-force → optimised method, implemented and verified in Go.

Start here

GO_INTERVIEW_QA.md — the single revision document. Q&A per pattern, arranged as a ladder from linear scans to dynamic programming, with a recognition table, a Blind 75 coverage map, a two-week schedule, and a Go-specific gotcha list. Everything else in this folder is the code it cites.

Layout

One package per pattern. Package doc comments carry the pattern summary (go doc dsa/heaptopk).

Tier Packages
1 — linear scans hashmap prefixsum twopointers slidingwindow
2 — exploit order binarysearch stack linkedlist fastslowpointers intervals cyclicsort
3 — structures heaptopk trees trie design
4 — graphs graphs islandsmatrix toposort unionfind shortestpath
5 — choice under constraint backtracking dp greedy mathbits matrix
6 — arrays & strings arrays strs

Verify

cd Go
go test ./...              # 26 packages
go vet ./... && gofmt -l . # both silent

Current state: 26 packages, 267 solution functions, 337 test functions, all passing; go vet and gofmt clean.

JS ↔ Go parity — ✅ complete

Both trees now implement the same problem set, verified function by function. The division of labour is deliberate:

  • JS carries the teaching — the recipe questions, visualisations, the brute-force → memoise → tabulate → roll ladder, real-world framings.
  • Go carries only what Go does differently, marked GO NOTE in the doc comment.

Read the JS doc block for a problem first, then that problem's Go note.

Package shape

Two packages were split out so the tree matches the JS folders: fastslowpointers (owns ListNode; linkedlist imports it via a type alias) and islandsmatrix (the grid problems, split from graphs). Two were added for the JS-only folders: arrays and strs.

The same problem under two names

Neither tree is wrong; the names just grew separately. A raw name diff will flag these, so they are listed here rather than rediscovered:

Go JavaScript
Serialize / Deserialize Codec class
MaxSlidingWindow maxOfAllSubarrays
MaxSubarray kadaneMaxSubarray
MaxSumSubarrayK maxSumSubarrayOfSizeK
LongestSubstringKDistinct longestSubstringWithKDistinct
LongestSubarrayWithSumAtMostK longestSubarrayWithSumLessThanK
OrangesRotting minTimeToInfectAll
SolveSurroundedRegions solve
DetectCycleStart detectCycle
IsPalindromeList isPalindrome (FastSlowPointers)
Rotate rotateMatrix90
SubarraySumEqualsK subarraySum
RobCircular rob2
SearchRotated search
HasCycleInMatrix hasCycle (exported as hasCycleInGrid)

A handful of problems also live in a different pattern folder on each side (isHappy is under JS HashMap/ but Go mathbits; partitionLabels is under JS MergeIntervals/ but Go greedy). Those are cross-referenced in the doc comments rather than duplicated.

Conventions

  • Every file: pattern header → brute force (where instructive) → optimal solution → the why in comments.
  • Where a brute force exists (TwoSumBrute, TrapBrute, DailyTemperaturesBrute, MaxSumSubarrayKBrute, FindKthLargestSort), the tests assert it agrees with the optimised version on the same inputs. That oracle caught two real bugs while this was written.
  • Tests are table-driven and lead with edge cases: empty, single element, all duplicates, all negatives, k > n.
  • Functions that mutate their input say so in the doc comment; functions that must not are covered by a test asserting the input is unchanged.