Skip to content

Commit 5ffcb26

Browse files
authored
Finish the write-up for LeetCode problem 2724. Sort By (#407)
1 parent 86b76df commit 5ffcb26

File tree

3 files changed

+236
-3
lines changed

3 files changed

+236
-3
lines changed

workspaces/javascript-leetcode-month/problems/2724-sort-by/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22

33
[View Problem on LeetCode](https://leetcode.com/problems/sort-by/)
44

5+
This problem is testing if we know how to sort using a custom "sort key". Note that the problem statement didn't say anything about not using built-in functions such as [`Array.prototype.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). On the contrary, I believe the problem _wants_ us to use the built-ins, and the intent is to have us practice specifying a custom comparison function.
6+
7+
The part of the problem statement stating "You may assume that `fn` will never duplicate numbers for a given array" ensures that we don't have to worry about our sorting algorithm's [stability](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), although if we use a built-in sort, the specification states that it will be stable.
8+
9+
For an added challenge, consider the case in which `fn` might be very expensive, and try to minimize how many times we invoke it.
10+
511
Once you've worked on the problem, check out [the full write-up and solution](solution.md)!

0 commit comments

Comments
 (0)