Skip to content

feat(coding-challenges): heap - kth largest element with a min-heap of size k - #99

Merged
Irish-Joseph merged 1 commit into
mainfrom
feat/2026-09-25-18-coding-kth-largest
Sep 25, 2026
Merged

Irish-Joseph merged 1 commit into
mainfrom
feat/2026-09-25-18-coding-kth-largest

Conversation

@Irish-Joseph

Copy link
Copy Markdown
Owner

Adds coding-challenges/heap/kth_largest_element.py (Medium) — the min-heap-of-size-k window (O(n log k) time, O(k) space), with the "why a min-heap for largest" rationale from the pattern README worked out in code. Tests cover k=1, k=n, all-equal, and duplicates-counting, plus 300 randomised cross-checks against a full sort with heavy duplication.

Validation: python coding-challenges/heap/kth_largest_element.py passed; full suite python scripts/run_challenges.py → 54/54. Bug caught while writing it: the widely-copied example claiming the 3rd largest of [3,2,3,1,2,3,5,7,2,7,4,7] is 4 is wrong under duplicates-counted semantics (three 7s occupy the top three places; the answer is 7) — the example was corrected and both k=3 and k=4 literals verified directly.

…f size k

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Irish-Joseph
Irish-Joseph merged commit d26823b into main Sep 25, 2026
1 check passed
@Irish-Joseph
Irish-Joseph deleted the feat/2026-09-25-18-coding-kth-largest branch September 25, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant