1354. Student Report Order

Easy1.5 points estimatedCustom ComparatorStringSorting

A teacher keeps names[i] and marks[i] for each of n students and must print a report. Students are listed from the highest marks to the lowest. When two students have equal marks, the one whose name comes first in plain character-code order goes first, so every uppercase letter sorts before every lowercase letter. If the names are also identical, the student who appears earlier in the input goes first. Return the names, not the indices, in report order as a list of strings. Compare names character by character using their character codes, with no locale handling and no case folding. Aim for O(n log n) comparisons, each costing at most the length of a name.

Example 1

Input:
names = ["bob","amy","cal"], marks = [80,90,80]
Output:
["amy","bob","cal"]
Explanation:

amy has the top marks; bob and cal tie at 80, and bob sorts before cal.

Example 2

Input:
names = ["bob","Bob","amy"], marks = [70,70,70]
Output:
["Bob","amy","bob"]
Explanation:

All marks are equal, and in character-code order the uppercase Bob comes before amy, which comes before bob.

Example 3

Input:
names = ["x","y"], marks = [0,100]
Output:
["y","x"]
Explanation:

y scored 100 and x scored 0, so y is listed first.

Constraints

1 ≤ n ≤ 500

names.length == marks.length

each name has 1 to 20 English letters

0 ≤ marks[i] ≤ 100

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n log n)
Space
O(n)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…