Skip to content

Commit a35f167

Browse files
Create README - LeetHub
1 parent 8b941e7 commit a35f167

File tree

1 file changed

+35
-0
lines changed
  • 1282-group-the-people-given-the-group-size-they-belong-to

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h2><a href="https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/">1282. Group the People Given the Group Size They Belong To</a></h2><h3>Medium</h3><hr><div><p>There are <code>n</code> people&nbsp;that are split into some unknown number of groups. Each person is labeled with a&nbsp;<strong>unique ID</strong>&nbsp;from&nbsp;<code>0</code>&nbsp;to&nbsp;<code>n - 1</code>.</p>
2+
3+
<p>You are given an integer array&nbsp;<code>groupSizes</code>, where <code>groupSizes[i]</code>&nbsp;is the size of the group that person&nbsp;<code>i</code>&nbsp;is in. For example, if&nbsp;<code>groupSizes[1] = 3</code>, then&nbsp;person&nbsp;<code>1</code>&nbsp;must be in a&nbsp;group of size&nbsp;<code>3</code>.</p>
4+
5+
<p>Return&nbsp;<em>a list of groups&nbsp;such that&nbsp;each person&nbsp;<code>i</code>&nbsp;is in a group of size&nbsp;<code>groupSizes[i]</code></em>.</p>
6+
7+
<p>Each person should&nbsp;appear in&nbsp;<strong>exactly one group</strong>,&nbsp;and every person must be in a group. If there are&nbsp;multiple answers, <strong>return any of them</strong>. It is <strong>guaranteed</strong> that there will be <strong>at least one</strong> valid solution for the given input.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
12+
<pre><strong>Input:</strong> groupSizes = [3,3,3,3,3,1,3]
13+
<strong>Output:</strong> [[5],[0,1,2],[3,4,6]]
14+
<b>Explanation:</b>
15+
The first group is [5]. The size is 1, and groupSizes[5] = 1.
16+
The second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.
17+
The third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.
18+
Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
19+
</pre>
20+
21+
<p><strong>Example 2:</strong></p>
22+
23+
<pre><strong>Input:</strong> groupSizes = [2,1,3,3,3,2]
24+
<strong>Output:</strong> [[1],[0,5],[2,3,4]]
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>groupSizes.length == n</code></li>
32+
<li><code>1 &lt;= n&nbsp;&lt;= 500</code></li>
33+
<li><code>1 &lt;=&nbsp;groupSizes[i] &lt;= n</code></li>
34+
</ul>
35+
</div>

0 commit comments

Comments
 (0)