Problem
Given an array numbers consisting of natural numbers, write a function solution that returns the most frequent element in numbers and its count as an array.
Constraints
- Each element in
numbersis an integer between 0 and 500. numbersis not empty, and its length does not exceed 100.- The result should be returned as a list in the form
[element, count]. - There are no cases where multiple elements have the same maximum count.
Test Case
| Test Case Number | numbers | return |
|---|---|---|
| 1 | [2, 2, 4, 5] | [2, 2] |
| 2 | [10, 5, 100, 5, 3, 5, 0] | [5, 3] |
| 3 | [1] | [1, 1] |
Explanation for Test Case 1
- The most frequent element in
numbersis2, appearing 2 times.
Explanation for Test Case 2
- The most frequent element in
numbersis5, appearing 3 times.
Explanation for Test Case 3
- The most frequent element in
numbersis1, appearing 1 time.