-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.kt
More file actions
26 lines (22 loc) · 797 Bytes
/
Solution.kt
File metadata and controls
26 lines (22 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package problems.earliestPossibleDayOfFullBloom
import readmeGeneration.ProblemDifficulty
import readmeGeneration.ProblemSolution
@ProblemSolution(
2136,
"Earliest Possible Day of Full Bloom",
ProblemDifficulty.HARD,
"https://leetcode.com/problems/earliest-possible-day-of-full-bloom/"
)
object Solution {
fun earliestFullBloom(plantTime: IntArray, growTime: IntArray): Int {
val idxDescGrow =
growTime.indices.sortedWith(Comparator<Int> { idx1, idx2 -> growTime[idx2].compareTo(growTime[idx1]) })
var exceededPlanTime = 0
var result = 0
for (i in idxDescGrow) {
result = maxOf(result, exceededPlanTime + plantTime[i] + growTime[i])
exceededPlanTime += plantTime[i]
}
return result
}
}