lc-go/solutions/23/q2300/solution.go

33 lines
618 B
Go

// Package q2300 implements a solution for https://leetcode.com/problems/successful-pairs-of-spells-and-potions/
package q2300
import "slices"
func nGte(arr []int, target int) int {
l, r := 0, len(arr)
for l < r {
m := (l + r) / 2
if arr[m] >= target {
r = m
} else {
l = m + 1
}
}
return len(arr) - l
}
func successfulPairs(spells []int, potions []int, success int64) []int {
slices.Sort(potions)
for i := range spells {
pow := spells[i]
want := int(success) / pow
if pow*want < int(success) {
want++
}
spells[i] = nGte(potions, want)
}
return spells
}
var _ = successfulPairs