Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1018 Bytes

_1282. Group the People Given the Group Size They Belong To.md

File metadata and controls

38 lines (26 loc) · 1018 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 28, 2024

Last updated : June 28, 2024


Related Topics : Array, Hash Table, Greedy

Acceptance Rate : 87.43 %


Solutions

Python

class Solution:
    def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
        people = sorted([(groupSizes[i], i) for i in range(len(groupSizes))], reverse=True)
        outputs = []

        while people :
            currSize = people[-1][0]
            outputs.append([people.pop()[1] for _ in range(currSize)])

        return outputs