File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 285
285
2099|[ Find Subsequence of Length K With the Largest Sum] ( ./2099-find-subsequence-of-length-k-with-the-largest-sum.js ) |Medium|
286
286
2114|[ Maximum Number of Words Found in Sentences] ( ./2114-maximum-number-of-words-found-in-sentences.js ) |Easy|
287
287
2129|[ Capitalize the Title] ( ./2129-capitalize-the-title.js ) |Easy|
288
+ 2244|[ Minimum Rounds to Complete All Tasks] ( ./2244-minimum-rounds-to-complete-all-tasks.js ) |Medium|
288
289
2427|[ Number of Common Factors] ( ./2427-number-of-common-factors.js ) |Easy|
289
290
290
291
## License
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2244. Minimum Rounds to Complete All Tasks
3
+ * https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level
7
+ * of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.
8
+ *
9
+ * Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to
10
+ * complete all the tasks.
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } tasks
15
+ * @return {number }
16
+ */
17
+ var minimumRounds = function ( tasks ) {
18
+ const map = new Map ( ) ;
19
+ let result = 0 ;
20
+
21
+ tasks . forEach ( task => map . set ( task , map . has ( task ) ? map . get ( task ) + 1 : 1 ) ) ;
22
+
23
+ for ( const count of map . values ( ) ) {
24
+ if ( count < 2 ) {
25
+ return - 1 ;
26
+ }
27
+ result += Math . floor ( count / 3 ) + ( count % 3 === 0 ? 0 : 1 ) ;
28
+ }
29
+
30
+ return result ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments