1636. Sort Array by Increasing Frequency Easy

@problem@discussion
#Array#Hash Table#Sorting



1/**
2 * [1636] Sort Array by Increasing Frequency
3 *
4 * Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.
5 * Return the sorted array.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,1,2,2,2,3]
10 * Output: [3,1,1,2,2,2]
11 * Explanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [2,3,1,3,2]
16 * Output: [1,3,3,2,2]
17 * Explanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.
18 * 
19 * Example 3:
20 * 
21 * Input: nums = [-1,1,-6,4,5,-6,1,4,1]
22 * Output: [5,-1,4,4,-6,-6,1,1,1]
23 *  
24 * Constraints:
25 * 
26 * 	1 <= nums.length <= 100
27 * 	-100 <= nums[i] <= 100
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/sort-array-by-increasing-frequency/
33// discuss: https://leetcode.com/problems/sort-array-by-increasing-frequency/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn frequency_sort(nums: Vec<i32>) -> Vec<i32> {
39        vec![]
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1636() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.