File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } d
3+ * @param {number[] } r
4+ * @return {number }
5+ */
6+ var minimumTime = function ( d , r ) {
7+ let low = d [ 0 ] + d [ 1 ]
8+ let high = 2 * low * 2
9+ let res = high
10+
11+ let lcm = ( r [ 0 ] * r [ 1 ] ) / gcd ( r [ 0 ] , r [ 1 ] )
12+
13+ while ( low < high ) {
14+ let mid = low + Math . floor ( ( high - low ) / 2 )
15+ if ( isOK ( mid ) ) {
16+ high = mid
17+ } else {
18+ low = mid + 1
19+ }
20+ }
21+
22+ return low
23+
24+ function gcd ( a , b ) {
25+ while ( b !== 0 ) {
26+ let temp = b
27+ b = a % b
28+ a = temp
29+ }
30+ return a
31+ }
32+ function isOK ( time ) {
33+ let slots1 = time - Math . floor ( time / r [ 0 ] )
34+ let slots2 = time - Math . floor ( time / r [ 1 ] )
35+ let total_slots = time - Math . floor ( time / lcm )
36+ return slots1 >= d [ 0 ] && slots2 >= d [ 1 ] && total_slots >= d [ 0 ] + d [ 1 ]
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments