Order Integers by Rarity and Descending Ties. Return the entries of nums ordered by increasing occurrence count. When two different values occur equally often, the larger value must come first.
### Problem
Return the entries of `nums` ordered by increasing occurrence count. When two different values occur equally often, the larger value must come first. Preserve every occurrence of each value.
```cpp
class Solution {
public:
vector<int> frequencySort(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
nums = [4,4,2,2,7]
Output: [7,4,4,2,2]
Explanation: 7 occurs once; 4 and 2 each occur twice, with 4 first.
```
**Example 2:**
```text
nums = [-3,0,-3,5,0,5]
Output: [5,5,0,0,-3,-3]
Explanation: All values have frequency two, so values decrease.
```
### Constraints
- `1 <= nums.length <= 100`.
- `-100 <= nums[i] <= 100`.
### Clarifying Questions
Ties are resolved by descending numeric value, so the returned value sequence is fully specified.
```hint Inspect the structure
Which ordering rule applies first, and what resolves a tie between different values?
```
### Reasoning checkpoints
- Produce exactly the required frequency order and descending-value ties.
- Preserve every input occurrence, including negative values and duplicates.
### Optional extensions
How could the bounded value range support an output-building approach without sorting all occurrences?
Overview: Order Integers by Rarity and Descending Ties. Return the entries of nums ordered by increasing occurrence count. When two different values occur equally often, the larger value must come first.
Return the entries of nums ordered by increasing occurrence count. When two different values occur equally often, the larger value must come first. Preserve every occurrence of each value.
class Solution {
public:
vector<int> frequencySort(vector<int>& nums);
};
Examples
Example 1:
nums = [4,4,2,2,7]
Output: [7,4,4,2,2]
Explanation: 7 occurs once; 4 and 2 each occur twice, with 4 first.
Example 2:
nums = [-3,0,-3,5,0,5]
Output: [5,5,0,0,-3,-3]
Explanation: All values have frequency two, so values decrease.
Constraints
1 <= nums.length <= 100
.
-100 <= nums[i] <= 100
.
Clarifying Questions Guidance
Ties are resolved by descending numeric value, so the returned value sequence is fully specified.
Reasoning checkpoints
Produce exactly the required frequency order and descending-value ties.
Preserve every input occurrence, including negative values and duplicates.
Optional extensions
How could the bounded value range support an output-building approach without sorting all occurrences?