Skip to content

feat: add TopKFrequentWords with deterministic tie-breaking (#7298)#7297

Open
oleksii-tumanov wants to merge 2 commits intoTheAlgorithms:masterfrom
oleksii-tumanov:top-k-frequent-words
Open

feat: add TopKFrequentWords with deterministic tie-breaking (#7298)#7297
oleksii-tumanov wants to merge 2 commits intoTheAlgorithms:masterfrom
oleksii-tumanov:top-k-frequent-words

Conversation

@oleksii-tumanov
Copy link

@oleksii-tumanov oleksii-tumanov commented Mar 4, 2026

The implementation returns the k most frequent words from an input array.
https://en.wikipedia.org/wiki/Top-k_problem

Files added:

  • TopKFrequentWords.java
  • TopKFrequentWordsTest.java

Test Case (feature demonstration)
Input:

String[] words = {"the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"};
int k = 4;

Expected output:

["the", "is", "sunny", "day"]

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.42%. Comparing base (4b04ad4) to head (1a0c104).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7297      +/-   ##
============================================
+ Coverage     79.40%   79.42%   +0.02%     
- Complexity     7054     7062       +8     
============================================
  Files           787      788       +1     
  Lines         23114    23129      +15     
  Branches       4544     4548       +4     
============================================
+ Hits          18354    18371      +17     
+ Misses         4025     4024       -1     
+ Partials        735      734       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oleksii-tumanov oleksii-tumanov changed the title feat: add TopKFrequentWords with deterministic tie-breaking feat: add TopKFrequentWords with deterministic tie-breaking (#7298) Mar 4, 2026
@oleksii-tumanov oleksii-tumanov marked this pull request as ready for review March 4, 2026 10:10
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.

2 participants