Files
LM-Gambit/.core/suites/math-code/test5.txt
T
Netherwarlord 8f246fabbc feat: add plugin framework with UI contributions and suite selection
- Implemented PluginBlocks component to render various plugin UI elements.
- Created SuitePicker for selecting test suites and questions.
- Introduced usePluginUI hook for managing plugin UI state and manifest.
- Developed DocsPage for comprehensive plugin framework documentation.
- Added PluginPage to render pages declared by plugins based on the current path.
2026-07-28 03:00:55 -04:00

19 lines
1.2 KiB
Plaintext

Write a Python function with exactly this signature:
def top_k_frequent(nums: list[int], k: int) -> list[int]:
It returns the k most frequent elements in nums, ordered from most frequent to least frequent. Ties in frequency are broken by smaller integer value first.
Constraints:
- Average time complexity must be O(n log k) or better. A full O(n log n) sort of the frequency map is not acceptable.
- Standard library only. No third-party packages.
- Must correctly handle: an empty input list, k larger than the number of distinct elements, k <= 0, and negative integers.
- Do not sort the entire frequency map.
Deliver:
1. The implementation, with type hints and a docstring stating the tie-breaking rule.
2. A complexity analysis giving time and space in terms of n and k, and naming the data structure that achieves the bound. State clearly where the log k comes from.
3. Five assert-based tests covering each edge case listed above.
4. Explain what breaks in your heap comparison logic if the tie-breaking rule were changed to "larger value first," and give the one-line change that fixes it.
5. State the one input shape for which your solution is NOT better than a plain sort, and why.