Order Names by Their Paired Distinct Heights

Quick Overview

Return names ordered by their paired distinct heights from tallest to shortest, preserving repeated names and their spelling.

Order Names by Their Paired Distinct Heights

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For every index i, names[i] and heights[i] describe the same person. Return the names in decreasing height order. Heights are distinct; names may repeat and retain their original letter case. ```cpp class Solution { public: vector<string> sortPeople(vector<string>& names, vector<int>& heights); }; ``` ### Examples **Example 1:** ```text Input: names = ["Ada","Bo","Cy"], heights = [160,190,175] Output: ["Bo","Cy","Ada"] Explanation: The height order is 190,175,160. ``` **Example 2:** ```text Input: names = ["Lee","Lee"], heights = [155,165] Output: ["Lee","Lee"] Explanation: Both occurrences remain even though their visible names match. ``` ### Constraints - Arrays have the same length n, with `1 <= n <= 1000`. - `1 <= names[i].length <= 20`; names use upper/lowercase English letters. - Heights are distinct integers between 1 and 100000. ### Clarifying Questions - Which height belongs to each name? Entries at the same index describe one person. - Can names repeat? Yes; keep every occurrence. - Can heights tie? No; heights are distinct. - Should names be alphabetized or change case? No; order only by decreasing height and preserve spelling. ```hint Check the boundary Two people can have the same name while having different heights. ```

Overview: Return names ordered by their paired distinct heights from tallest to shortest, preserving repeated names and their spelling.

Microsoft logo
Microsoft
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For every index i, names[i] and heights[i] describe the same person. Return the names in decreasing height order. Heights are distinct; names may repeat and retain their original letter case.

class Solution {
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights);
};

Examples

Example 1:

Input: names = ["Ada","Bo","Cy"], heights = [160,190,175]
Output: ["Bo","Cy","Ada"]
Explanation: The height order is 190,175,160.

Example 2:

Input: names = ["Lee","Lee"], heights = [155,165]
Output: ["Lee","Lee"]
Explanation: Both occurrences remain even though their visible names match.

Constraints

  • Arrays have the same length n, with 1 <= n <= 1000 .
  • 1 <= names[i].length <= 20 ; names use upper/lowercase English letters.
  • Heights are distinct integers between 1 and 100000.

Clarifying Questions Guidance

  • Which height belongs to each name? Entries at the same index describe one person.
  • Can names repeat? Yes; keep every occurrence.
  • Can heights tie? No; heights are distinct.
  • Should names be alphabetized or change case? No; order only by decreasing height and preserve spelling.