Sort Custom Records
Problem statement
Each string in records has the form name|score, where name contains lowercase letters and score is a nonnegative integer.
Return the records sorted by score in descending order. Break equal-score ties by name in ascending lexicographic order.
Function
sortRecords(records: String[]) → String[]Examples
Example 1
records = ["ana|7","bob|10","amy|7"]return = ["bob|10","amy|7","ana|7"]The score-10 record comes first; the score-7 tie is ordered by name.
Example 2
records = ["z|0"]return = ["z|0"]A single record is already sorted.
Constraints
1 <= records.length <= 10000.- Every record follows
name|score. - Names are nonempty lowercase strings; scores are between
0and10^9.
Source note: Author-written prompt excerpt retained for source fidelity.