You are tasked with writing a function to sort an array of integers based on the frequency of each element. The criteria for sorting are as follows:
For example, given the array [4, 5, 6, 5, 4, 3]
, the frequencies are:
A possible sorted output would be [3, 6, 4, 4, 5, 5]
.
With Valentine's Day just around the corner, think of this challenge as a way to show some love to your coding skills by carefully arranging numbers just as you would arrange thoughtful gifts. Happy coding!
Function Signature: