Slightly cleaned up solution for lenSort and freqSort.