Implement Function to Determine Mode and Prime Numbers
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
##### Scenario
Implementing utility algorithms within a data-processing library.
##### Question
Write a function that returns the mode of an integer list; if all values are unique return None, and support multiple modes when ties exist. Given an integer array containing 1 to n, output all prime numbers in the array.
##### Hints
Emphasize time complexity and edge-case handling.
Quick Answer: This question evaluates algorithmic problem-solving skills, including frequency analysis for mode computation, correct handling of ties and uniqueness edge cases, and basic number-theoretic competency for prime identification.
Given an integer array nums, implement analyze_numbers(nums) that returns a 2-element list: [modes, primes]. modes is either None (if all values in nums appear exactly once) or a sorted list of all values that have the maximum frequency (support ties). primes is a sorted list of unique prime numbers present in nums (values > 1 only). If nums is empty, return [None, []].
Constraints
- 0 <= len(nums) <= 200000
- -10^6 <= nums[i] <= 10^6
- Return modes as None if and only if every value appears once
- Return primes as unique values in ascending order
- 1 and negative numbers are not prime
Hints
- Use a frequency map (e.g., collections.Counter) to find the maximum frequency and all values that match it.
- If the maximum frequency is 1, return modes = None.
- To list primes efficiently, build a sieve up to the maximum positive value in nums and filter the unique values.
- Ignore values <= 1 for prime detection.