We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b1ab98 commit 21fb8aeCopy full SHA for 21fb8ae
Group the People Given the Group Size They Belong To/kata.go
@@ -0,0 +1,21 @@
1
+package kata
2
+
3
+func groupThePeople(groupSizes []int) [][]int {
4
+ buckets := make(map[int][]int, 0)
5
+ dividedGroups := make([][]int, 0)
6
+ for i, groupSize := range groupSizes {
7
+ bucket := buckets[groupSize]
8
+ if bucket == nil {
9
+ bucket = make([]int, 0)
10
+ }
11
12
+ bucket = append(bucket, i)
13
+ if len(bucket) == groupSize {
14
+ dividedGroups = append(dividedGroups, bucket)
15
+ buckets[groupSize] = nil
16
+ } else {
17
+ buckets[groupSize] = bucket
18
19
20
+ return dividedGroups
21
+}
0 commit comments