This question evaluates algorithmic problem-solving skills focused on frequency analysis and selection, measuring competency in designing algorithms and reasoning about time and space complexity.

Given an integer array nums of length n and an integer k (1 ≤ k ≤ number of distinct values in nums), return any ordering of the k values with the highest frequencies. Describe a baseline approach and analyze its time and space complexity. Follow-up: Can you achieve expected O(n) time and O(n) extra space? Explain the data structures you would use and implement that approach.