From 8a918a7c58bdf2ef216390ba53d7bc7665ef97de Mon Sep 17 00:00:00 2001 From: sumanth-botlagunta Date: Sun, 2 Apr 2023 13:55:35 +0530 Subject: [PATCH] 2300: Successful Pairs of Spells and Potions --- python/successfull_pairs_of_spells_and_potions.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/successfull_pairs_of_spells_and_potions.py diff --git a/python/successfull_pairs_of_spells_and_potions.py b/python/successfull_pairs_of_spells_and_potions.py new file mode 100644 index 0000000..fd5ad16 --- /dev/null +++ b/python/successfull_pairs_of_spells_and_potions.py @@ -0,0 +1,8 @@ +# https://leetcode.com/problems/successful-pairs-of-spells-and-potions/editorial/ +# T: O((n + m)logm) where n is the number of spells and m is the number of potions +# S: O(m) where m is the number of potions + +class Solution: + def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: + potions.sort() + return [len(potions) - bisect_left(potions, (success + x - 1) // x) for x in spells]