Skip to content

Commit ba8381c

Browse files
committed
added problem 2244
1 parent ecb9ccc commit ba8381c

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package problem2244
2+
3+
/*
4+
You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task.
5+
In each round, you can complete either 2 or 3 tasks of the same difficulty level.
6+
Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.
7+
*/
8+
9+
func minimumRounds(tasks []int) int {
10+
var res int
11+
var tmap = map[int]int{}
12+
for _, i := range tasks {
13+
tmap[i]++
14+
}
15+
for _, v := range tmap {
16+
if v == 1 {
17+
return -1
18+
}
19+
if v%3 == 0 {
20+
res += v / 3
21+
} else {
22+
res += (v / 3) + 1
23+
}
24+
}
25+
return res
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package problem2244
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
type Result struct {
11+
Input []int
12+
Expected int
13+
}
14+
15+
var Results = []Result{
16+
{[]int{2, 2, 3, 3, 2, 4, 4, 4, 4, 4}, 4},
17+
{[]int{2, 3, 3}, -1},
18+
}
19+
20+
func TestMinRoundsForTasks(t *testing.T) {
21+
assert := assert.New(t)
22+
23+
for _, res := range Results {
24+
want := res.Expected
25+
got := minimumRounds(res.Input)
26+
assert.Equal(want, got, fmt.Sprintf("%+v", res))
27+
}
28+
}

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ Each problem is in it's own directory, with test files. There are helper package
337337
| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [My Solution](./problems/problem2148) ||
338338
| 2165 | [Smallest Value of the Rearranged Number](https://leetcode.com/problems/smallest-value-of-the-rearranged-number/) | [My Solution](./problems/problem2165) ||
339339
| 2225 | [Find Players With Zero or One Losses](https://leetcode.com/problems/find-players-with-zero-or-one-losses/) | [My Solution](./problems/problem2225) ||
340+
| 2244 | [Minimum Rounds to Complete All Tasks](https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks) | [My Solution](./problems/problem2244) ||
340341
| 2256 | [Minimum Average Difference](https://leetcode.com/problems/minimum-average-difference/) | [My Solution](./problems/problem2256) ||
341342
| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [My Solution](./problems/problem2259) ||
342343
| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [My Solution](./problems/problem2278) ||

0 commit comments

Comments
 (0)