Sort the People

You are given an array of strings names and an array heights of distinct positive integers, both of length n. names[i] and heights[i] describe the i-th person. Return names ordered by height from tallest to shortest.

30:00

Sort the People
easy
Free written solution
Topics
Companies

You are given an array of strings names and an array heights of distinct positive integers, both of length n. names[i] and heights[i] describe the i-th person. Return names ordered by height from tallest to shortest.

Example 1:
Input: {"names":["Mary","John","Emma"],"heights":[180,165,170]}
Output: ["Mary","Emma","John"]
Constraints:
  • n=names.length=heights.lengthn = \text{names.length} = \text{heights.length}

  • 1≤n≤1031 \leq n \leq 10^3

  • 1≤names[i].length≤201 \leq \text{names}[i].\text{length} \leq 20

  • 1≤heights[i]≤1051 \leq \text{heights}[i] \leq 10^5

  • names[i] consists of lower and upper case English letters.

  • All the values of heights are distinct.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"names":["Mary","John","Emma"],"heights":[180,165,170]}

Heights are all different, so sorting by height alone fixes the order. Sort the indices, not the names, so each name stays tied to its height.

the crowd, in input order

180

Mary

165

John

170

Emma

the line, tallest first (0 of 3)

Variables
VariableValue
n3
DepthFunction Call
Stack empty
0/5