2418. Sort the People #81
-
You are given an array of strings For each index Return Example 1:
Example 2:
Constraints:
Hint:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To solve this problem, we can follow these steps:
Let's implement this solution in PHP: 2418. Sort the People <?php
// Example usage:
$names = ["Mary","John","Emma"];
$heights = [180,165,170];
$result = sortPeople($names, $heights);
echo implode(",", $result); // Output: Mary,Emma,John
?> Explanation:
This approach ensures that the names are returned in the order of descending heights, as required. The time complexity is (O(n \log n)) due to the sorting step, which is efficient for the input size constraints. |
Beta Was this translation helpful? Give feedback.
To solve this problem, we can follow these steps:
Let's implement this solution in PHP: 2418. Sort the People
Explanation:
Combining Names and Heights:
$combined
where each element is a pair of a name …