How to Solve '1331 Rank Transform of an Array' on LeetCode? - Javascript

preview_player
Показать описание
Do you need more help with coding?
════════════════════════════

Problem: #1331 Rank Transform of an Array
Language: #Javascript
Difficulty: Easy

Strategy: Order array and use map
Time Complexity: O(nlog(n))
Space Complexity: O(n)

Pseudo Code:
1. Create new "ordered" array that is sorted.
2. Create map object.
3. Create rank variable starting at 1.
4. Loop through ordered.
a. If the value is not in the map.
i. Set the value to rank ++.
5. Create output array.
6. Loop through arr.
a. Push to output the map value.
7. Return output.

GitHub Repo:

Let's Connect 💯:
════════════════════════════
Рекомендации по теме
Комментарии
Автор

Where did you get this sort method from? Do you have any documentation for this type of sort method? [...array].sort()

theresatrev
Автор

is this the best solution? I mean is there any solution with less time or space complexity than this?

deep_jupiter_ocean
visit shbcf.ru