Skip to content
LC-2418 Easy LeetCode

2418. Sort the People

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 85% Topics: Array, Hash Table, String, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(n)

# sort
class Solution(object):
    def sortPeople(self, names, heights):
        """
        :type names: List[str]
        :type heights: List[int]
        :rtype: List[str]
        """
        order = range(len(names))
        order.sort(key=lambda x: heights[x], reverse=True)
        return [names[i] for i in order]

Solution from kamyu104/LeetCode-Solutions · MIT