A product page loads thousands of reviews, and each review has a star rating from 1 to 5. The ratings chart needs them sorted from lowest to highest.
Write sortRatings(ratings) that returns a new array with the ratings sorted ascending. Since there are only five possible values, aim for O(n) time.
Input: ratings = [5,3,4,5,1,3] Output: [1,3,3,4,5,5]
One 1, two 3s, one 4, and two 5s.
Input: ratings = [2,2,2] Output: [2,2,2]
All the same rating.
0 <= ratings.length <= 1000001 <= ratings[i] <= 5Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #202 Sort the Star Ratings. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.