Vectors in Rust are a collection type that can store multiple values of the same type. They are similar to arrays in JavaScript and lists in Python but with some additional features, they are stored on the heap and they can grow or shrink in size.

In this challenge you're asked to implement two functions that calculate the median and mode of a list of integers.

Read the definitions of each Median and Mode below to understand what you need to implement.

The median is the middle value of a list when it is ordered by size. If the list has an even number of elements, the median is the average of the two middle numbers.

Here's an example:

Or if the number of elements is even:

You can implement the function in the following steps:

Sort the list of numbers.

If the number of elements is odd, return the middle element.

If the number of elements is even, return the average of the two middle elements.

The mode is the number that appears most frequently in a list, if there are multiple numbers that appear the same number of times, return all of them in a vector.

Here's an example:

The number 1 appears four times, which is more than any other number in the list.

Important: You must sort the list of numbers before returning the modes list.

You can use the entry method to insert a value into a hash map if it doesn't exist or update it if it does.

When looping through a vector, you can dereference the value using & to get the value instead of a reference to it. For example:

Store the maximum frequency and the number that appears most frequently in a HashMap<i32, i32> and update it as you iterate through the list of numbers, and finally return the list of numbers that appears most frequently.

Editor not available on Mobile!

In order to solve the challenge, please visit this page on a desktop computer.

Vectors in Rust are a collection type that can store multiple values of the same type. They are similar to arrays in JavaScript and lists in Python but with some additional features, they are stored on the heap and they can grow or shrink in size.

In this challenge you're asked to implement two functions that calculate the median and mode of a list of integers.

Read the definitions of each Median and Mode below to understand what you need to implement.

The median is the middle value of a list when it is ordered by size. If the list has an even number of elements, the median is the average of the two middle numbers.

Here's an example:

Or if the number of elements is even:

You can implement the function in the following steps:

Sort the list of numbers.

If the number of elements is odd, return the middle element.

If the number of elements is even, return the average of the two middle elements.

The mode is the number that appears most frequently in a list, if there are multiple numbers that appear the same number of times, return all of them in a vector.

Here's an example:

The number 1 appears four times, which is more than any other number in the list.

Important: You must sort the list of numbers before returning the modes list.

You can use the entry method to insert a value into a hash map if it doesn't exist or update it if it does.

When looping through a vector, you can dereference the value using & to get the value instead of a reference to it. For example:

Store the maximum frequency and the number that appears most frequently in a HashMap<i32, i32> and update it as you iterate through the list of numbers, and finally return the list of numbers that appears most frequently.