File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,323 LeetCode solutions in JavaScript
1+ # 1,324 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
113311331478|[ Allocate Mailboxes] ( ./solutions/1478-allocate-mailboxes.js ) |Hard|
113411341480|[ Running Sum of 1d Array] ( ./solutions/1480-running-sum-of-1d-array.js ) |Easy|
113511351481|[ Least Number of Unique Integers after K Removals] ( ./solutions/1481-least-number-of-unique-integers-after-k-removals.js ) |Medium|
1136+ 1482|[ Minimum Number of Days to Make m Bouquets] ( ./solutions/1482-minimum-number-of-days-to-make-m-bouquets.js ) |Medium|
113611371486|[ XOR Operation in an Array] ( ./solutions/1486-xor-operation-in-an-array.js ) |Easy|
113711381491|[ Average Salary Excluding the Minimum and Maximum Salary] ( ./solutions/1491-average-salary-excluding-the-minimum-and-maximum-salary.js ) |Easy|
113811391492|[ The kth Factor of n] ( ./solutions/1492-the-kth-factor-of-n.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1482. Minimum Number of Days to Make m Bouquets
3+ * https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
4+ * Difficulty: Medium
5+ *
6+ * You are given an integer array bloomDay, an integer m and an integer k.
7+ *
8+ * You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the
9+ * garden.
10+ *
11+ * The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be
12+ * used in exactly one bouquet.
13+ *
14+ * Return the minimum number of days you need to wait to be able to make m bouquets from the garden.
15+ * If it is impossible to make m bouquets return -1.
16+ */
17+
18+ /**
19+ * @param {number[] } bloomDay
20+ * @param {number } m
21+ * @param {number } k
22+ * @return {number }
23+ */
24+ var minDays = function ( bloomDay , m , k ) {
25+ if ( m * k > bloomDay . length ) return - 1 ;
26+
27+ let left = 1 ;
28+ let right = Math . max ( ...bloomDay ) ;
29+ let result = - 1 ;
30+
31+ while ( left <= right ) {
32+ const mid = Math . floor ( ( left + right ) / 2 ) ;
33+ if ( canMakeBouquets ( mid ) ) {
34+ result = mid ;
35+ right = mid - 1 ;
36+ } else {
37+ left = mid + 1 ;
38+ }
39+ }
40+
41+ return result ;
42+
43+ function canMakeBouquets ( days ) {
44+ let bouquets = 0 ;
45+ let flowers = 0 ;
46+ for ( const bloom of bloomDay ) {
47+ if ( bloom <= days ) {
48+ flowers ++ ;
49+ if ( flowers === k ) {
50+ bouquets ++ ;
51+ flowers = 0 ;
52+ }
53+ } else {
54+ flowers = 0 ;
55+ }
56+ }
57+ return bouquets >= m ;
58+ }
59+ } ;
You can’t perform that action at this time.
0 commit comments