question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
successful-pairs-of-spells-and-potions | Python 3 || 7 lines, binary search || T/S: 94% / 81% | python-3-7-lines-binary-search-ts-94-81-cnyzn | \nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n\n n, ans = len(potions), []\n | Spaulding_ | NORMAL | 2023-04-02T15:41:35.890514+00:00 | 2024-06-13T03:48:09.270724+00:00 | 1,161 | false | ```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n\n n, ans = len(potions), []\n potions.sort()\n \n for s in spells:\n num = success//s + bool(success%s)\n idx = bisect_left(potions, num)\n ... | 9 | 0 | ['Python3'] | 0 |
successful-pairs-of-spells-and-potions | Simple C++ Binary Search :) | simple-c-binary-search-by-scaar-7x0u | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- the approach that is used here is binary search.\n- So first we sort th | Scaar | NORMAL | 2023-04-02T12:15:44.029058+00:00 | 2023-04-02T12:15:44.029093+00:00 | 105 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- the approach that is used here is `binary search`.\n- So first we `sort` the potions.\n- then we traverse through `every element in spell` and multiply it to the potions.\n- and because our potions is `sorted` we can apply... | 9 | 0 | ['Binary Search', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Binary Search | binary-search-by-virendra115-0iaz | \npublic int[] successfulPairs(int[] spells, int[] potions, long success) {\n Arrays.sort(potions);\n for(int i=0;i<spells.length;i++){\n | virendra115 | NORMAL | 2022-06-11T16:02:30.930952+00:00 | 2022-06-11T16:02:30.930987+00:00 | 1,224 | false | ```\npublic int[] successfulPairs(int[] spells, int[] potions, long success) {\n Arrays.sort(potions);\n for(int i=0;i<spells.length;i++){\n int l=0,h=potions.length;\n while(l<h){\n int mid = (l+h)/2;\n if(1L*spells[i]*potions[mid]>=success){\n ... | 9 | 0 | ['Java'] | 3 |
successful-pairs-of-spells-and-potions | ✅ EASY || 💯 BEATS-PROOF || 🌟 C++ || 🧑💻 BEGINNER FRIENDLY || 🙂 DETAILED EXPLANATION | easy-beats-proof-c-beginner-friendly-det-izo2 | \n\n# \uD83C\uDF1F PROOF\n---\n\n\n---\n\n\n\n# \uD83C\uDF1F Intuition\n---\n Describe your first thoughts on how to solve this problem. \n#### The problem requ | mukund_rakholiya | NORMAL | 2024-11-20T10:59:50.078361+00:00 | 2024-11-20T11:00:48.549513+00:00 | 692 | false | ```\n```\n# \uD83C\uDF1F PROOF\n---\n\n\n---\n```\n```\n\n# \uD83C\uDF1F Intuition\n---\n<!-- Describe your first thoughts on how to solve this problem. -->\n#### The problem requires counting the number of... | 8 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'C++'] | 9 |
successful-pairs-of-spells-and-potions | ✅C++ || EASY Binary Search | c-easy-binary-search-by-chiikuu-8wex | Code\n\nclass Solution {\n #define ll long long\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long c) {\n sort(p.begi | CHIIKUU | NORMAL | 2023-04-02T09:02:42.597241+00:00 | 2023-04-02T09:02:42.597299+00:00 | 1,420 | false | # Code\n```\nclass Solution {\n #define ll long long\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long c) {\n sort(p.begin(),p.end());\n vector<int>an;\n for(int i=0;i<s.size();i++){\n int d=0;\n ll g=c/s[i];\n if(c%s[i])g++;\n ... | 8 | 1 | ['Binary Search', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | 2300. Successful Pairs of Spells and Potions EASY 96.70% Fast | 2300-successful-pairs-of-spells-and-poti-x0ka | \n\n# Intuition\nThe task is to determine, for each spell, how many potions can be paired with it such that the product of the spell\'s power and the potion\'s | k-arsyn28 | NORMAL | 2024-06-18T18:36:49.404795+00:00 | 2024-06-18T18:36:49.404813+00:00 | 472 | false | \n\n# Intuition\nThe task is to determine, for each spell, how many potions can be paired with it such that the product of the spell\'s power and the potion\'s power meets or exceeds a given success threshol... | 7 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | C++ | EASY EXPLANATION | BEGINNER FRIENDLY | WITHOUT BS🙂 | c-easy-explanation-beginner-friendly-wit-lelj | Intuition\nWE WILL SORT SPELLS IN DESCENDING ORDER AND POTIONS IN ASCENDING ORDER . SO THAT EVERY TIME I CHECK FOR A GIVEN SPELL ,I DON\'T HAVE TO TRAVERSE FROM | codman_1 | NORMAL | 2023-04-02T06:11:06.210609+00:00 | 2023-04-02T06:24:54.567347+00:00 | 784 | false | # Intuition\nWE WILL SORT SPELLS IN DESCENDING ORDER AND POTIONS IN ASCENDING ORDER . SO THAT EVERY TIME I CHECK FOR A GIVEN SPELL ,I DON\'T HAVE TO TRAVERSE FROM BEGINNING . It will start from some index k .\n\nAND ALSO.\nIF ANY GREATER SPELL IS NOT ABLE TO MAKE SUCCESS FROM POTIONS ,THEN \nNO SPELL AFTER THAT WILL GI... | 7 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | [Java] Easy solution using Binary search || O(n*logn) | java-easy-solution-using-binary-search-o-9z8s | O(n*log(n)) / O(1)\n\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n Arrays.sort(potions);\n \n for(int i | 2000shivam659 | NORMAL | 2022-06-13T12:22:03.490762+00:00 | 2022-06-13T14:12:12.205291+00:00 | 762 | false | **O(n*log(n)) / O(1)**\n```\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n Arrays.sort(potions);\n \n for(int i = 0; i < spells.length; i++) {\n int l = 0, r = potions.length;\n \n while(l < r) {\n int m = l + (r - l)... | 7 | 0 | ['Binary Tree', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | Solution By Dare2Solve | Detailed Explanation | Clean Code | solution-by-dare2solve-detailed-explanat-fcnw | Explanation []\nauthorslog.com/blog/ZzthSLHX8W\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& | Dare2Solve | NORMAL | 2024-08-22T18:20:48.135733+00:00 | 2024-08-22T18:20:48.135801+00:00 | 772 | false | ```Explanation []\nauthorslog.com/blog/ZzthSLHX8W\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n vector<long long> arr; // Use long long to handle large numbers\n for (int potion : potions) {\n ... | 6 | 0 | ['Array', 'Two Pointers', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
successful-pairs-of-spells-and-potions | Powerful Binary search Approach | powerful-binary-search-approach-by-ganji-ic5w | \n# Time Complexity----->O(NLogN)\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n | GANJINAVEEN | NORMAL | 2023-04-03T17:44:22.001098+00:00 | 2023-04-03T17:44:22.001139+00:00 | 325 | false | \n# Time Complexity----->O(NLogN)\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n list1=[]\n potions.sort()\n // some test cases are not sorted\n for s in spells:\n // binary search on left most value i.e gr... | 6 | 0 | ['Python3'] | 0 |
successful-pairs-of-spells-and-potions | C# Prefix Sum O(m + n) time O(1) space | c-prefix-sum-om-n-time-o1-space-by-harro-hsju | Intuition\nTo get to success we need to check if we can compensate potion power with our spell power. So we need to calculate neededSpellCost for each potion. A | HarrowinG | NORMAL | 2023-04-02T09:39:52.006241+00:00 | 2023-04-02T09:39:52.006278+00:00 | 1,055 | false | # Intuition\nTo get to ```success``` we need to check if we can compensate potion power with our spell power. So we need to calculate ```neededSpellCost``` for each potion. As it is an integer division we need to add 1 when it can\'t be divided to satisfy the requirement. After that we can see which spell can be used w... | 6 | 0 | ['Prefix Sum', 'C#'] | 1 |
successful-pairs-of-spells-and-potions | Python Solution Explained | python-solution-explained-by-vi_ek-ivls | \'\'\'\n\n def successfulPairs(self, spells: List[int], potions: List[int], s: int) -> List[int]:\n q=[]\n potions.sort() | vi_ek | NORMAL | 2022-06-11T17:49:26.043189+00:00 | 2022-06-11T17:49:26.043231+00:00 | 911 | false | \'\'\'\n\n def successfulPairs(self, spells: List[int], potions: List[int], s: int) -> List[int]:\n q=[]\n potions.sort() #Sort the potion array\n a=len(potions)\n for i in spells:\n count=0\n l=0 ... | 6 | 0 | ['Binary Search', 'Tree', 'C', 'Python'] | 1 |
successful-pairs-of-spells-and-potions | Python 3 | Math, Binary Search | Explanation | python-3-math-binary-search-explanation-t8wy5 | Explanation\n- The order of potions doesn\'t matter, we just need to find out how many potion can form a successful pair with the current spell\n\t- Thus, we ca | idontknoooo | NORMAL | 2022-06-11T17:41:22.360730+00:00 | 2022-06-11T17:45:32.190588+00:00 | 709 | false | ### Explanation\n- The order of `potions` doesn\'t matter, we just need to find out how many potion can form a *successful* pair with the current *spell*\n\t- Thus, we can sort `potions` to make a faster binary search\n- We can\'t use spell to multiply each potion, it takes a long time `O(mn)`; \n\t- Instead, we can us... | 6 | 0 | ['Math', 'Binary Search', 'Python', 'Python3'] | 1 |
successful-pairs-of-spells-and-potions | Python Two Pointers Solution w/ sorting (WITHOUT binary search) | python-two-pointers-solution-w-sorting-w-6tum | Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea is to initially sort both the spells and potions array, and then initialize a | nelsonh15 | NORMAL | 2023-04-02T23:01:36.559855+00:00 | 2023-04-02T23:15:16.867976+00:00 | 447 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea is to initially sort both the ```spells``` and ```potions``` array, and then initialize a variable called ```p``` at the last element of ```potions```. ```p``` will only move from right to left, while another pointer, ```s```, wi... | 5 | 0 | ['Array', 'Two Pointers', 'Sorting', 'Counting', 'Python3'] | 1 |
successful-pairs-of-spells-and-potions | 🚨 [JavaScript][php] - Beats 100% - Binary Search - faster than other solutions | javascriptphp-beats-100-binary-search-fa-qavq | \n# Approach\nHere is my approach to solving the problem using a binary search:\n\n First, we sort the potions array in ascending order. This ensures that the s | hobobobo256 | NORMAL | 2023-04-02T17:37:51.117222+00:00 | 2023-04-02T17:37:51.117256+00:00 | 721 | false | \n# Approach\nHere is my approach to solving the problem using a binary search:\n\n* First, we sort the potions array in ascending order. This ensures that the smallest potions are at the front of the\n array.\n\n* Then, we iterate over the spells array. For each spell, we perform _a binary search_ on the potions arra... | 5 | 0 | ['Binary Search', 'PHP', 'JavaScript'] | 3 |
successful-pairs-of-spells-and-potions | [Kotlin] Binary search | kotlin-binary-search-by-dzmtr-veuj | \nimport kotlin.math.ceil\n\nclass Solution {\n fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {\n val res = IntArray(s | dzmtr | NORMAL | 2023-04-02T12:20:56.732014+00:00 | 2023-04-02T12:20:56.732060+00:00 | 48 | false | ```\nimport kotlin.math.ceil\n\nclass Solution {\n fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {\n val res = IntArray(spells.size)\n potions.sort()\n\n fun findIndex(target: Long): Int {\n var lo = 0\n var hi = potions.lastIndex\n\n while (lo < hi) ... | 5 | 0 | ['Binary Search', 'Kotlin'] | 0 |
successful-pairs-of-spells-and-potions | Binary Search | Intuition explained with example | binary-search-intuition-explained-with-e-i378 | Intuition\n Describe your first thoughts on how to solve this problem. \nIf we sort the potions array and find the minimum index where the product is greater th | nidhiii_ | NORMAL | 2023-04-02T06:14:47.348241+00:00 | 2023-04-02T06:24:49.698869+00:00 | 887 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we sort the potions array and find the minimum index where the product is greater than or equal to success, then we can be sure that the rest of the potions array will give product greater than or equal to success only.\n\nTo solve thi... | 5 | 0 | ['Binary Search', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Clear C# Binary Search beats 95.4% | clear-c-binary-search-beats-954-by-need_-96oo | Intuition\n Describe your first thoughts on how to solve this problem. \nAfter sort potions, this problem becomes to: for each spells[i], find the first index i | need_what | NORMAL | 2023-04-02T03:31:56.960069+00:00 | 2023-04-02T03:31:56.960101+00:00 | 582 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter sort potions, this problem becomes to: for each spells[i], find the first index in potions that spells[i] * potions[index] >= success. Then the pair that spells[i] can form is potions.Length - index\n\nFind the first index match a c... | 5 | 0 | ['C#'] | 0 |
successful-pairs-of-spells-and-potions | JAVA || Easy Solution Using Binary Search || Beginner friendly || Using Map | java-easy-solution-using-binary-search-b-zp1a | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | shivrastogi | NORMAL | 2023-04-02T01:05:09.528664+00:00 | 2023-04-02T01:05:09.528687+00:00 | 2,466 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | ✅C++ | ✅Use Binary Search | ✅Efficient solution | c-use-binary-search-efficient-solution-b-ewuv | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) \n {\n int sn = spells.size | Yash2arma | NORMAL | 2022-06-12T05:52:14.509715+00:00 | 2023-04-02T05:45:19.193588+00:00 | 654 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) \n {\n int sn = spells.size();\n int pn = potions.size();\n vector<int> ans; //stores answer\n \n sort(potions.begin(), potions.end()); //sort potions for b... | 5 | 0 | ['Binary Search', 'C', 'Sorting', 'Binary Tree', 'C++'] | 1 |
successful-pairs-of-spells-and-potions | 🧪🧙♂️ Successful Pairs of Spells and Potions – Binary Search Brew! ⚡️ | successful-pairs-of-spells-and-potions-b-j0se | 💡 IntuitionYou’re given two arrays:spells[i] = power of the i-th spellpotions[j] = strength of the j-th potion
You need to count how many potions can be paired | NAVNEETkharb | NORMAL | 2025-04-05T16:42:03.839958+00:00 | 2025-04-05T16:42:03.839958+00:00 | 144 | false | # 💡 Intuition
You’re given two arrays:
spells[i] = power of the i-th spell
potions[j] = strength of the j-th potion
You need to count how many potions can be paired with each spell such that:
spell[i] * potion[j] ≥ success
---
# 🚀 Approach – Sort & Binary Search Combo! 🧠
To efficiently count how many potions wi... | 4 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'Python', 'C++', 'Java'] | 1 |
successful-pairs-of-spells-and-potions | Go simple solution | go-simple-solution-by-khangtn1-31lg | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | khangtn1 | NORMAL | 2023-09-30T14:20:05.006091+00:00 | 2023-09-30T14:21:23.286064+00:00 | 209 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O((m+n)*logm)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space comple... | 4 | 0 | ['Go'] | 0 |
successful-pairs-of-spells-and-potions | Java. Binary Search. Spells and Potions | java-binary-search-spells-and-potions-by-moyo | \n\nclass Solution {\n public int search(int[] nums, long target, long sel) {\n int start = 0;\n int finish = nums.length - 1;\n int med | red_planet | NORMAL | 2023-04-02T20:43:50.512477+00:00 | 2023-04-02T20:43:50.512523+00:00 | 1,025 | false | \n```\nclass Solution {\n public int search(int[] nums, long target, long sel) {\n int start = 0;\n int finish = nums.length - 1;\n int med;\n if (target < nums[start] * sel) return start;\n if (target > nums[finish] * sel) return nums.length;\n\n while (start < finish && nu... | 4 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | Binary Search for Success. | binary-search-for-success-by-shahscript-2jdf | Intuition\n Describe your first thoughts on how to solve this problem. \nUsing Binary Search for suucess.\n\n# Approach\n Describe your approach to solving the | shahscript | NORMAL | 2023-04-02T19:25:02.112066+00:00 | 2023-04-02T19:25:02.112099+00:00 | 253 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing Binary Search for suucess.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Sort the array.\n- Binary Search to locate the dividing element.\n- Dividing element is where the product is just started to get gr... | 4 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | C++ ✅✅ Easy LOWER BOUND 2023 short sol MUST WATCH. | c-easy-lower-bound-2023-short-sol-must-w-lezs | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long t) {\n sort(p.begin(),p.end());\n vector<in | dynamo_518 | NORMAL | 2023-04-02T17:02:15.695679+00:00 | 2023-04-02T17:02:15.695714+00:00 | 1,000 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long t) {\n sort(p.begin(),p.end());\n vector<int> ans; \n int x; long long y;\n for(auto &it:s) {\n y = t / it;\n x = p.end() - lower_bound(p.begin(),p.end(),y * it >= ... | 4 | 0 | ['C', 'Sorting', 'Binary Tree'] | 1 |
successful-pairs-of-spells-and-potions | Easy and fast C++ Solution with full explanation | easy-and-fast-c-solution-with-full-expla-pmgb | Intuition\nsorting the potions array to reduce the number of operations to search(binary search) for the element whose product with ith spell is greater than or | technoreck | NORMAL | 2023-04-02T06:59:22.570842+00:00 | 2023-04-02T07:03:58.288677+00:00 | 888 | false | # Intuition\nsorting the potions array to reduce the number of operations to search(binary search) for the element whose product with ith spell is greater than or equal to the success.\n\n# Approach\n1. sort `potions` array.\n2. use `binary search` to search for the element whose product with that spell is equal or jus... | 4 | 0 | ['Array', 'Binary Search', 'Sorting', 'C++'] | 1 |
successful-pairs-of-spells-and-potions | python3 Solution | python3-solution-by-motaharozzaman1996-u59f | \n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n potions.sort()\n N=len(pot | Motaharozzaman1996 | NORMAL | 2023-04-02T04:11:56.216778+00:00 | 2023-04-02T04:11:56.216809+00:00 | 1,698 | false | \n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n potions.sort()\n N=len(potions)\n ans=[]\n for s in spells:\n target=(success-1)//s\n index=bisect.bisect_right(potions,target)\n ans.ap... | 4 | 0 | ['Python', 'Python3'] | 2 |
successful-pairs-of-spells-and-potions | 🗓️ Daily LeetCoding Challenge April, Day 2 | daily-leetcoding-challenge-april-day-2-b-pxj4 | This problem is the Daily LeetCoding Challenge for April, Day 2. Feel free to share anything related to this problem here! You can ask questions, discuss what y | leetcode | OFFICIAL | 2023-04-02T00:00:23.491056+00:00 | 2023-04-02T00:00:23.491124+00:00 | 6,742 | false | This problem is the Daily LeetCoding Challenge for April, Day 2.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please crea... | 4 | 0 | [] | 18 |
successful-pairs-of-spells-and-potions | ✅C++ || Binary Search || Explanation with Comments | c-binary-search-explanation-with-comment-vx4a | Please Upvote If It Helps\n\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) \n {\ | mayanksamadhiya12345 | NORMAL | 2022-06-11T19:56:14.635500+00:00 | 2022-06-11T19:56:14.635530+00:00 | 461 | false | **Please Upvote If It Helps**\n\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) \n {\n // declare a vector of size spell that will store our ans\n int n = spells.size();\n int m = potions.size();\n vector<int> ... | 4 | 0 | ['C'] | 0 |
successful-pairs-of-spells-and-potions | [C++] | Binary search | short and simple logic | c-binary-search-short-and-simple-logic-b-ap4n | For each spell,\nneed = success * 1.0 / spell\nBinary search the index of first potion >= need in the sorted potions.\nThe number of potions that are successful | synapse50 | NORMAL | 2022-06-11T17:39:01.493478+00:00 | 2022-06-11T17:45:15.548535+00:00 | 605 | false | For each spell,\n**need = success * 1.0 / spell**\nBinary search the index of **first potion >= need** in the sorted potions.\nThe number of potions that are successful are **potions.length - index**\n```\nvector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.... | 4 | 0 | ['C', 'Binary Tree'] | 0 |
successful-pairs-of-spells-and-potions | Python||Binary Search||Explanation | pythonbinary-searchexplanation-by-nandha-xbcx | I Was Also One Of The Person Who Got TLE At The First Attempt\n\nThe Straight Forward Approach was to multiply each and every value of potion with the every val | nandhan11 | NORMAL | 2022-06-11T16:38:05.105249+00:00 | 2022-06-11T16:40:27.362015+00:00 | 470 | false | I Was Also One Of The Person Who Got TLE At The First Attempt\n\nThe Straight Forward Approach was to multiply each and every value of potion with the every value of spell and count the values which are greater than success and append to the answer array. This was one of the common solution which every one thinks of..\... | 4 | 1 | ['Sorting', 'Binary Tree', 'Python'] | 1 |
successful-pairs-of-spells-and-potions | c++ solution using binary search | c-solution-using-binary-search-by-dilips-44lx | \nclass Solution {\npublic:\n int find(vector<int>&nums,long long val,long long max_val)\n {\n int l=0;\n int r=nums.size()-1;\n int | dilipsuthar17 | NORMAL | 2022-06-11T16:31:40.841845+00:00 | 2022-06-11T16:31:40.841876+00:00 | 232 | false | ```\nclass Solution {\npublic:\n int find(vector<int>&nums,long long val,long long max_val)\n {\n int l=0;\n int r=nums.size()-1;\n int ans=0;\n int n=nums.size();\n while(l<=r)\n {\n int mid=(l+r)/2;\n if((1ll)*nums[mid]*val>=max_val)\n {... | 4 | 2 | ['C', 'Binary Tree', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Beats 93.22% in C++ | Binary Search Algorithm | beats-9322-in-c-binary-search-algorithm-gmimr | Code\ncpp []\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n \n int | SPA111 | NORMAL | 2024-08-22T14:36:25.614584+00:00 | 2024-08-22T14:36:25.614618+00:00 | 684 | false | # Code\n```cpp []\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n \n int n = spells.size();\n int m = potions.size();\n vector<int> pairs;\n\n sort(potions.begin(), potions.end());\n\n for(int i = 0; ... | 3 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | [ Python ] | Simple & Clean Solution using Binary Search | python-simple-clean-solution-using-binar-9ixa | Code\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n ans = []\n potions.sor | yash_visavadia | NORMAL | 2023-04-29T18:42:22.079116+00:00 | 2023-04-29T18:42:22.079140+00:00 | 419 | false | # Code\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n ans = []\n potions.sort()\n\n n = len(potions)\n for s in spells:\n ind = bisect_left(potions, success / s)\n ans.append(n - ind)\n re... | 3 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'Python3'] | 0 |
successful-pairs-of-spells-and-potions | C++ Solution | c-solution-by-pranto1209-z5cw | Approach\n Describe your approach to solving the problem. \n Binary Search\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n | pranto1209 | NORMAL | 2023-04-02T20:29:46.078566+00:00 | 2023-08-03T12:43:30.162138+00:00 | 428 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n Binary Search\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(N * log M)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(N)\n\n# Code\n```\nclass Solution {\np... | 3 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | Java | Binary Search | Clean code | Beats > 87% | java-binary-search-clean-code-beats-87-b-7bp2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | judgementdey | NORMAL | 2023-04-02T19:47:26.597339+00:00 | 2023-04-02T19:52:43.140819+00:00 | 43 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O((m+n) * log(m))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(log(m))$$ used by the sort a... | 3 | 0 | ['Array', 'Binary Search', 'Sorting', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | Master the Art of Spell and Potion Pairing: A TypeScript Binary Search Approach (100% / 87.50%) | master-the-art-of-spell-and-potion-pairi-wpvo | Intuition\nGiven two arrays representing the strengths of spells and potions, our task is to find the number of successful pairs for each spell. A pair is consi | polyym | NORMAL | 2023-04-02T14:50:51.483934+00:00 | 2023-04-02T14:50:51.483964+00:00 | 172 | false | # Intuition\nGiven two arrays representing the strengths of spells and potions, our task is to find the number of successful pairs for each spell. A pair is considered successful if the product of the strengths of the spell and the potion is at least equal to a given `success` value. To solve this problem efficiently, ... | 3 | 0 | ['Array', 'Binary Search', 'Sorting', 'TypeScript'] | 0 |
successful-pairs-of-spells-and-potions | Day92||Binary Search very Easy Solution | day92binary-search-very-easy-solution-by-whuz | Intuition and Approach\nWe have implemented Binary Search to Solve the problem\n\nSo, Condition to use binary tree is that array must be sorted\n\nSo, we used t | Rarma | NORMAL | 2023-04-02T14:13:02.383186+00:00 | 2023-04-02T14:13:02.383230+00:00 | 719 | false | # Intuition and Approach\nWe have implemented Binary Search to Solve the problem\n\nSo, Condition to use binary tree is that array must be sorted\n\nSo, we used the inbuilt sort function.\n\nNow to solve the problem many of you have already tried to do it in O(n^2) order (Code given below) but it is giving the TLE.\n``... | 3 | 0 | ['Math', 'Binary Search', 'Sorting', 'C++'] | 2 |
successful-pairs-of-spells-and-potions | BINARY SEARCH || C++ || PLEASE UPVOTE | binary-search-c-please-upvote-by-satyam2-e4w0 | Intuition\nCan be done in binary search.\n\n# Approach\nStarting with the sorting of potions , After that getting the element till which (spells[i]*potions[mid | satyam2805singh | NORMAL | 2023-04-02T12:18:42.855109+00:00 | 2023-04-02T12:18:42.855146+00:00 | 85 | false | # Intuition\nCan be done in binary search.\n\n# Approach\nStarting with the sorting of potions , After that getting the element till which (spells[i]*potions[mid]) is greater than success and store those elements in pairs[i].\nThe submission shall be taken care of for long long type casting.\n\n# Complexity\n- Time co... | 3 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | Simple 14 lines of code in O(n logn)✔ | simple-14-lines-of-code-in-on-logn-by-ha-3l46 | NOTE:\nPlease go through the Intution and Approach before jumping to the code. You will definitely get it!\nSuggested to write things on notebook while reading. | harsh6176 | NORMAL | 2023-04-02T10:35:22.967781+00:00 | 2023-04-02T10:35:22.967827+00:00 | 152 | false | # NOTE:\n**Please go through the Intution and Approach before jumping to the code. You will definitely get it!**\nSuggested to write things on notebook while reading.\n\n# Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn the question, we can see a basic pattern that we have ... | 3 | 0 | ['Array', 'Math', 'Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Easy Java || Binary Search || Beats 85% | easy-java-binary-search-beats-85-by-hars-ui7b | Intuition\nSolution using basic Binary Search\n\n# Approach\n1. sort the potion array\n2. now iterate for the spell array\n3. binary search the index where the | harshverma2702 | NORMAL | 2023-04-02T10:29:32.833329+00:00 | 2023-04-02T10:29:32.833361+00:00 | 79 | false | # Intuition\nSolution using basic Binary Search\n\n# Approach\n1. sort the potion array\n2. now iterate for the spell array\n3. binary search the index where the multiple of spell*potion>=success\n4. now from that index onwards rest potions will be surely >=success because they are arranged in increasing order\n# Compl... | 3 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | Simple Commented C++ | Binary Search | simple-commented-c-binary-search-by-sour-tjs4 | ```\nclass Solution {\npublic:\n vector successfulPairs(vector& spells, vector& potions, long long success) {\n // Sort the potions array as we will u | SourabCodes | NORMAL | 2023-04-02T09:23:58.144955+00:00 | 2023-04-02T09:23:58.145014+00:00 | 167 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n // Sort the potions array as we will use binary search here...\n sort(potions.begin(),potions.end());\n \n // Declaring the answer array...\n vector<int> a... | 3 | 0 | ['C', 'Binary Tree'] | 0 |
successful-pairs-of-spells-and-potions | Easy Python solution using || Bisect | easy-python-solution-using-bisect-by-lal-4rkk | Code\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n lst=[]\n potions.sort( | Lalithkiran | NORMAL | 2023-04-02T09:13:30.723397+00:00 | 2023-04-02T09:13:30.723430+00:00 | 345 | false | # Code\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n lst=[]\n potions.sort()\n ln=len(potions)\n for i in spells:\n t = bisect_left(potions, success/i)\n lst.append(ln-t)\n return lst\n``... | 3 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Python3'] | 0 |
successful-pairs-of-spells-and-potions | ✅✅ Binary Search Approach || Java Solution | binary-search-approach-java-solution-by-k8kcc | \n# Java Code\n\nclass Solution {\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n int pairs[] = new int[spells.length];\ | pratham31 | NORMAL | 2023-04-02T08:04:46.570383+00:00 | 2023-04-02T08:05:13.711389+00:00 | 362 | false | \n# Java Code\n```\nclass Solution {\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n int pairs[] = new int[spells.length];\n\n Arrays.sort(potions);\n\n for(int i = 0; i < spells.length; i++)\n {\n int start = 0, end = potions.length-1;\n ... | 3 | 0 | ['Two Pointers', 'Binary Search', 'Sorting', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | Easy Explanation , Binary search Approach 🔥⬆️ | easy-explanation-binary-search-approach-2f3yc | Approach\n1. Brute Force approach to solve this problem is to use a nested loop, where the outer loop iterates over the "spells" vector and the inner loop itera | ishaanchoudhary | NORMAL | 2023-04-02T07:44:14.415996+00:00 | 2023-04-02T07:44:14.416025+00:00 | 40 | false | # Approach\n1. Brute Force approach to solve this problem is to use a **nested loop**, where the outer loop iterates over the "spells" vector and the inner loop iterates over the "potions" vector. For each pair (s, p), the product s * p is checked against the target. If the product is greater than or equal to the targe... | 3 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 1 |
successful-pairs-of-spells-and-potions | [Python3] One line solution. | python3-one-line-solution-by-geka32-uylb | Code\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n return potions.sort() or [len | geka32 | NORMAL | 2023-04-02T07:35:14.991212+00:00 | 2023-04-02T07:35:14.991252+00:00 | 920 | false | # Code\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n return potions.sort() or [len(potions) - bisect_left(potions, -(-success // spell)) for spell in spells]\n\n``` | 3 | 0 | ['Python3'] | 2 |
successful-pairs-of-spells-and-potions | Java Solution for beginners. With simple explanation and some additional tips | java-solution-for-beginners-with-simple-ygjqw | Intuition\nBinary Search\n\n# Approach\nStep 1 : Sort potions \nStep 2 : get number of pair of successful potions and spells by using binary search. Try finding | shashwat1712 | NORMAL | 2023-04-02T07:25:13.809007+00:00 | 2023-04-02T09:37:45.307825+00:00 | 480 | false | # Intuition\nBinary Search\n\n# Approach\nStep 1 : Sort potions \nStep 2 : get number of pair of successful potions and spells by using binary search. Try finding smallest element in potions which can give you successful pair by subtracting index of samllest element by length of potions.\nStep 3 : store all the value i... | 3 | 0 | ['Array', 'Binary Search', 'Sorting', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | Sorting + Binary Search + Explaination||✅Easy Java solution||Beginner Friendly🔥 | sorting-binary-search-explainationeasy-j-s9aa | Intuition\n Describe your first thoughts on how to solve this problem. \nSort the potions array and then use binary search on potions array to get the that elem | deepVashisth | NORMAL | 2023-04-02T07:03:41.476411+00:00 | 2023-04-02T07:04:09.508803+00:00 | 94 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the potions array and then use binary search on potions array to get the that element whose elements of right part of the array will be greater than or equal to success given because if that particular element excceds success then al... | 3 | 0 | ['Binary Search', 'Sorting', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | C++ solution || with explanation || Let's code it💻 | c-solution-with-explanation-lets-code-it-a0zn | Upvote if you found this solution helpful\uD83D\uDD25\n\n# Approach\nThe first approach which comes to mind after reading the question is to traverse the Potion | piyusharmap | NORMAL | 2023-04-02T05:28:59.346860+00:00 | 2023-04-02T05:28:59.346905+00:00 | 325 | false | # Upvote if you found this solution helpful\uD83D\uDD25\n\n# Approach\nThe first approach which comes to mind after reading the question is to traverse the Potions array for each spell and count the number of pairs which satisfies the given condition, but this method leads to TLE because the time complexity for this wi... | 3 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | JavaScript, Java, C and Python solution with time complexity of O(n log m) | javascript-java-c-and-python-solution-wi-xq7p | \n\n# Approach\nSort the potions array in descending order.\nCreate an empty hash map map to store the results.\nFor each element in the spells array:\na. If th | Aryan_rajput_ | NORMAL | 2023-04-02T05:22:26.709860+00:00 | 2023-04-02T05:22:26.709922+00:00 | 373 | false | \n\n# Approach\nSort the potions array in descending order.\nCreate an empty hash map map to store the results.\nFor each element in the spells array:\na. If the element is not in the map, calculate the value of success / spells[i] and find the position of the first element in the sorted potions array that is greater t... | 3 | 0 | ['C', 'Python', 'Java', 'JavaScript'] | 1 |
successful-pairs-of-spells-and-potions | Python short and clean 2-liner. Functional programming. | python-short-and-clean-2-liner-functiona-e1z2 | Approach\n1. Sort potions into, say s_potions.\n\n2. For each spells, say x, binary-search for insertion index i in s_potions.\n\n3. Return len(potions) - i.\n\ | darshan-as | NORMAL | 2023-04-02T05:03:09.114918+00:00 | 2023-04-02T05:03:09.114955+00:00 | 291 | false | # Approach\n1. Sort `potions` into, say `s_potions`.\n\n2. For each `spells`, say `x`, binary-search for insertion index `i` in `s_potions`.\n\n3. Return `len(potions) - i`.\n\n# Complexity\n- Time complexity: $$O((m + n) * log(n))$$\n\n- Space complexity: $$O(m + n)$$\n\nwhere,\n`m is number of spells`,\n`n is number ... | 3 | 0 | ['Array', 'Binary Search', 'Sorting', 'Python', 'Python3'] | 0 |
successful-pairs-of-spells-and-potions | Sort + Binary Search | C++ | sort-binary-search-c-by-tusharbhart-og4f | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n = potions.size();\n | TusharBhart | NORMAL | 2023-04-02T04:02:38.547545+00:00 | 2023-04-02T04:02:38.547577+00:00 | 1,579 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n = potions.size();\n vector<int> ans;\n sort(potions.begin(), potions.end());\n\n for(int i : spells) {\n int pos = lower_bound(potions.begin(), p... | 3 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Easy Solution Implemented with more one language. | easy-solution-implemented-with-more-one-rvj2u | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Mustafa-Moghazy | NORMAL | 2023-04-02T01:27:04.796646+00:00 | 2023-04-02T01:27:04.796679+00:00 | 895 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['C++', 'Java', 'JavaScript'] | 0 |
successful-pairs-of-spells-and-potions | Swift | Binary Search | swift-binary-search-by-upvotethispls-bwmg | Binary Search (accepted answer)\n\nclass Solution {\n func successfulPairs(_ spells: [Int], _ potions: [Int], _ success: Int) -> [Int] {\n let potions | UpvoteThisPls | NORMAL | 2023-04-02T01:16:25.357001+00:00 | 2023-04-02T20:12:34.087734+00:00 | 138 | false | **Binary Search (accepted answer)**\n```\nclass Solution {\n func successfulPairs(_ spells: [Int], _ potions: [Int], _ success: Int) -> [Int] {\n let potions = potions.sorted()\n \n return spells.map { spell in\n var (left, right) = (0, potions.count)\n while left < right {... | 3 | 0 | ['Swift'] | 1 |
successful-pairs-of-spells-and-potions | JS, binary search with comments | js-binary-search-with-comments-by-bagiry-b3oo | Intuition\nTo achieve we don\'t have to calcualate every spell * potion. If we sort potions then have to find the firs potion which satisfies our conditions. Al | bagiryan | NORMAL | 2023-04-02T00:34:12.980217+00:00 | 2023-04-02T00:38:16.177045+00:00 | 547 | false | # Intuition\nTo achieve we don\'t have to calcualate every spell * potion. If we sort potions then have to find the firs potion which satisfies our conditions. All next potions will satisfy as well.\n\n# Approach\n - Sort potions ascending order\n - for each spell find that minimum number which would be bigger than suc... | 3 | 0 | ['JavaScript'] | 0 |
successful-pairs-of-spells-and-potions | C++ || Sort and Lower Bound | c-sort-and-lower-bound-by-sosuke23-bibl | Code\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long success) {\n int n = s.size(), m = p.size(); | Sosuke23 | NORMAL | 2023-04-02T00:07:08.088381+00:00 | 2023-04-02T00:07:08.088425+00:00 | 747 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long success) {\n int n = s.size(), m = p.size();\n sort(p.begin(), p.end());\n vector<int> res(n);\n for (int i = 0; i < n; i += 1) {\n long long x = (success + s[i] - 1) ... | 3 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | ✅Easiest & Best Solution in C++ || BinarySearch✅ | easiest-best-solution-in-c-binarysearch-ma23p | Complexity\n- Time complexity:\nO(nlogm)\n\n- Space complexity:\nO(1)\n\n# Code\nPlease Upvote if u liked my Solution\uD83D\uDE42\n\nclass Solution {\npublic:\n | aDish_21 | NORMAL | 2022-10-27T20:11:41.787762+00:00 | 2022-10-27T20:11:41.787807+00:00 | 467 | false | # Complexity\n- Time complexity:\nO(nlogm)\n\n- Space complexity:\nO(1)\n\n# Code\n**Please Upvote if u liked my Solution**\uD83D\uDE42\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n=spells.size(),m=potions.size();\n ... | 3 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | JS | Binary search | Runtime: 83.33% | js-binary-search-runtime-8333-by-diff64-dkyn | \nvar successfulPairs = function(spells, potions, success) {\n\tlet res = [];\n\tpotions.sort((a, b) => a - b);\n\tfor (let i = 0; i < spells.length; i++) {\n\t | Diff64 | NORMAL | 2022-08-18T13:53:55.642475+00:00 | 2022-08-18T13:53:55.642529+00:00 | 563 | false | ```\nvar successfulPairs = function(spells, potions, success) {\n\tlet res = [];\n\tpotions.sort((a, b) => a - b);\n\tfor (let i = 0; i < spells.length; i++) {\n\t\tlet h = potions.length-1, l = 0, mid;\n\t\twhile (l <= h) {\n\t\t\tmid = ~~(l + (h-l)/2);\n\t\t\tif (spells[i] * potions[mid] >= success) h = mid-1;\n\t\t\... | 3 | 0 | ['Binary Tree', 'JavaScript'] | 0 |
successful-pairs-of-spells-and-potions | O(N+M) Approach || C++ || Without binary Search and sort || Easy || Faster | onm-approach-c-without-binary-search-and-x24e | \nclass Solution {\npublic:\n \n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int maxi = 0;\n | bit_changes | NORMAL | 2022-06-11T19:27:50.157042+00:00 | 2022-06-11T19:28:16.655642+00:00 | 399 | false | ```\nclass Solution {\npublic:\n \n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int maxi = 0;\n unordered_map<int,int> dp;\n for(int i = 0 ; i<potions.size() ; i++){\n dp[potions[i]]++;\n maxi = max(potions[i],maxi);\n ... | 3 | 0 | ['C', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | [Rust] Native binary search solution | rust-native-binary-search-solution-by-ni-6145 | rust\nuse std::cmp::Ordering;\n\nimpl Solution {\n pub fn successful_pairs(spells: Vec<i32>, mut potions: Vec<i32>, success: i64) -> Vec<i32> {\n let | night-crawler | NORMAL | 2022-06-11T17:01:53.706944+00:00 | 2022-06-12T15:48:24.610004+00:00 | 189 | false | ```rust\nuse std::cmp::Ordering;\n\nimpl Solution {\n pub fn successful_pairs(spells: Vec<i32>, mut potions: Vec<i32>, success: i64) -> Vec<i32> {\n let num_potions = potions.len() as i32;\n potions.sort_unstable();\n\n let mut result = vec![0; spells.len()];\n\n for (i, spell) in spells.... | 3 | 0 | ['Binary Tree', 'Rust'] | 3 |
successful-pairs-of-spells-and-potions | JAVA || Clean Code || Binary Search | java-clean-code-binary-search-by-rachelg-u0xp | \nclass Solution {\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n \n Arrays.sort(potions);\n int[] res=ne | rachelgupta7codenirvana | NORMAL | 2022-06-11T16:57:14.396328+00:00 | 2022-06-11T16:57:14.396357+00:00 | 441 | false | ```\nclass Solution {\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n \n Arrays.sort(potions);\n int[] res=new int[spells.length];\n \n for(int i=0;i<spells.length;i++)\n {\n int count=binarySearch(spells[i],potions,success);\n ... | 3 | 0 | ['Binary Search', 'Java'] | 2 |
successful-pairs-of-spells-and-potions | Successful Pairs of spells and Potions | successful-pairs-of-spells-and-potions-b-by1k | Easy approach Binary search --\nPlease Upvote\n\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long ss) {\n | BibhabenduMukherjee | NORMAL | 2022-06-11T16:50:15.879491+00:00 | 2022-06-11T16:50:55.281152+00:00 | 101 | false | **Easy approach Binary search --**\n**Please Upvote**\n\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long ss) {\n sort(p.begin() , p.end());\n vector<long long> res(s.size());\n for(int i = 0 ; i< s.size() ; ++i){\n res[i]... | 3 | 1 | ['Binary Tree'] | 0 |
successful-pairs-of-spells-and-potions | C++ || EASY TO UNDERSTAND || Ultimate Binary Search Solution | c-easy-to-understand-ultimate-binary-sea-s9nm | \n#define ll long long int\n#define ld long double\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& p, long long su | aarindey | NORMAL | 2022-06-11T16:05:58.865720+00:00 | 2022-06-11T16:05:58.865757+00:00 | 154 | false | ```\n#define ll long long int\n#define ld long double\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& p, long long success) {\n sort(p.begin(),p.end());\n ll n=p.size();\n\n vector<int> ans;\n for(int x:spells)\n {\n ll up=ceil(... | 3 | 1 | [] | 1 |
successful-pairs-of-spells-and-potions | Binary Search | Python | Easy to understand | binary-search-python-easy-to-understand-8vo8o | Idea:\nThe pretty straightforward solution, sort potions and for each spell find an index of minimal potions that will make success and we know that everything | dilshodbek | NORMAL | 2022-06-11T16:05:52.116014+00:00 | 2022-06-11T16:05:52.116076+00:00 | 211 | false | Idea:\nThe pretty straightforward solution, sort potions and for each spell find an index of minimal potions that will make success and we know that everything greater will make a success too. \n\n\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n ... | 3 | 0 | [] | 1 |
successful-pairs-of-spells-and-potions | Priority queue || C++ || Max-heap || Easy-Understanding || Simple | priority-queue-c-max-heap-easy-understan-4pip | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n vector<int> ans;\n | itzyash_01 | NORMAL | 2022-06-11T16:03:59.932279+00:00 | 2022-06-11T16:03:59.932311+00:00 | 218 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n vector<int> ans;\n priority_queue<int> pq;\n unordered_map<int,int> mp;\n for(int i=0;i<potions.size();i++)\n pq.push(potions[i]);\n vector<int>... | 3 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | Sort potions and apply Binary Search || C++ || Sorting 🟩 | sort-potions-and-apply-binary-search-c-s-v3vr | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long k) {\n sort(potions.begin(),potions.end | VIPul1 | NORMAL | 2022-06-11T16:03:14.158059+00:00 | 2022-06-11T16:13:49.284373+00:00 | 254 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long k) {\n sort(potions.begin(),potions.end());\n int n = spells.size(), m = potions.size();\n int i = 0, j = 0;\n vector<int> res;\n for(int i=0;i<n;i++){\n int... | 3 | 0 | ['C', 'Sorting'] | 1 |
successful-pairs-of-spells-and-potions | Ceil + binary search | ceil-binary-search-by-slow_code-oyxz | \ttypedef long long ll;\n\tclass Solution {\n\tpublic:\n\t\tvector successfulPairs(vector& spells, vector& portions, long long success) {\n\t\t\tsort(begin(port | Slow_code | NORMAL | 2022-06-11T16:00:41.184095+00:00 | 2022-06-11T16:02:58.622632+00:00 | 276 | false | \ttypedef long long ll;\n\tclass Solution {\n\tpublic:\n\t\tvector<int> successfulPairs(vector<int>& spells, vector<int>& portions, long long success) {\n\t\t\tsort(begin(portions),end(portions));\n\t\t\tvector<int>res;\n\t\t\tint m = portions.size();\n\t\t\tfor(auto num:spells){\n\t\t\t\tif(success/num>=100001){\n\t\t... | 3 | 0 | [] | 0 |
successful-pairs-of-spells-and-potions | Python Binary Search EASY TO UNDERSTAND SOLUTION | python-binary-search-easy-to-understand-uj207 | \n# Code\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n n = len(spells)\n | chrishardin | NORMAL | 2024-08-18T22:57:00.521826+00:00 | 2024-08-18T22:57:00.521864+00:00 | 98 | false | \n# Code\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n n = len(spells)\n m = len(potions)\n pairs = [0] * n\n\n # Info from question\n # spells[i] = strength of i\n # potion[j] = strength of j\n... | 2 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'Python3'] | 0 |
successful-pairs-of-spells-and-potions | Counting Successful Spell-Potion Pairs Using Binary Search (100% Runtime Efficiency) | counting-successful-spell-potion-pairs-u-5ibk | Intuition\nThe function calculates the number of successful pairs between each spell and a potion. A pair is considered successful if the product of the spell a | authxth | NORMAL | 2024-08-18T13:42:39.947434+00:00 | 2024-08-18T13:42:39.947484+00:00 | 332 | false | # Intuition\nThe function calculates the number of successful pairs between each spell and a potion. A pair is considered successful if the product of the spell and potion values is greater than or equal to a given success threshold. To efficiently find these pairs, binary search is employed after sorting the potions a... | 2 | 0 | ['TypeScript'] | 0 |
successful-pairs-of-spells-and-potions | ✅💯🔥Simple Code📌🚀| 🔥✔️Easy to understand🎯 | 🎓🧠Beginner friendly🔥| O(N logM) Time Comp.💀💯 | simple-code-easy-to-understand-beginner-lxd6g | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | atishayj4in | NORMAL | 2024-07-20T18:01:31.454748+00:00 | 2024-08-01T18:58:45.370545+00:00 | 251 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'C', 'Sorting', 'Python', 'C++', 'Java'] | 0 |
successful-pairs-of-spells-and-potions | Easy Binary Search Approach | easy-binary-search-approach-by-codered23-uf3w | \n\n# Complexity\n- Time complexity:\nO(n logm)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n public int[] successfulPairs(int[] spells, int[] | codeRed23 | NORMAL | 2024-06-29T13:47:28.084124+00:00 | 2024-06-29T13:47:28.084156+00:00 | 147 | false | \n\n# Complexity\n- Time complexity:\nO(n logm)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int[] successfulPairs(int[] spells, int[] potions, long success) {\n int n=spells.length;\n int m=potions.length;\n int[] arr= new int[n];\n Arrays.sort(potions);\n ... | 2 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | Beats 89% || C++ solution using binary search and sorting | beats-89-c-solution-using-binary-search-u5i8y | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yashu761 | NORMAL | 2024-06-25T10:12:55.360334+00:00 | 2024-06-25T10:12:55.360368+00:00 | 492 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO((m+n)logm) sorting potions vector -> mlogm and applying binary search on potions for every spell nlogm\n\n- Space complexity:\nO(... | 2 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | 🔥Simple and easy approach using lower_bound | simple-and-easy-approach-using-lower_bou-ao4i | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Sparsh_7637 | NORMAL | 2024-06-18T20:29:05.320390+00:00 | 2024-06-18T20:29:05.320425+00:00 | 55 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n$$O(nlog(n))$$\n\n- Space complexity:\n$$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<... | 2 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | ✅ Easy C++ Solution | easy-c-solution-by-moheat-ex61 | Code\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n = spells.size( | moheat | NORMAL | 2024-05-31T08:22:24.828211+00:00 | 2024-05-31T08:22:24.828245+00:00 | 125 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n = spells.size();\n int m = potions.size();\n\n vector<int> v;\n\n sort(potions.begin(),potions.end());\n\n for(int i=0;i<n;i++)\n {\n ... | 2 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | ✅Easy C++ Solution(Only 5 lines) || For Beginners 📌🔥🔥📌 | easy-c-solutiononly-5-lines-for-beginner-bxo6 | \n\n\n# Please upvote of you found the solution helpful.\uD83D\uDE4F\uD83C\uDFFB\n\n# Code\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector< | Gaurav_Tomar | NORMAL | 2024-04-27T05:38:36.496493+00:00 | 2024-04-27T05:38:36.496529+00:00 | 280 | false | \n\n\n# ***Please upvote of you found the solution helpful.\uD83D\uDE4F\uD83C\uDFFB***\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& s, vector<int>& p, long long su... | 2 | 0 | ['Binary Search', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | C++ | O((N+M)*LogM TC Solution | Binary Search on solution space | c-onmlogm-tc-solution-binary-search-on-s-tyza | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(), poti | theCuriousCoder | NORMAL | 2024-04-27T05:09:10.077904+00:00 | 2024-04-27T05:09:10.077923+00:00 | 4 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(), potions.end());\n int n = spells.size(), m = potions.size();\n vector<int> output;\n for(int i = 0; i<n; i++) {\n if (spells[i]*1... | 2 | 0 | [] | 0 |
successful-pairs-of-spells-and-potions | [Python] Binary Search | python-binary-search-by-lshigami-adu7 | \n\n# Code\n\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n def BinarySearch(nums,x | lshigami | NORMAL | 2024-03-18T07:56:31.045473+00:00 | 2024-03-18T07:56:31.045505+00:00 | 645 | false | \n\n# Code\n```\nclass Solution:\n def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n def BinarySearch(nums,x):\n l=0\n r=len(nums)-1\n while l<=r:\n m=(l+r)//2\n if nums[m]>=x:\n r=m-... | 2 | 0 | ['Python3'] | 0 |
successful-pairs-of-spells-and-potions | Simple pythonic solution | simple-pythonic-solution-by-burkh4rt-ks5t | Code\npython\nclass Solution:\n def successfulPairs(\n self, spells: List[int], potions: List[int], success: int\n ) -> List[int]:\n n, _ = | burkh4rt | NORMAL | 2024-01-20T04:15:29.372627+00:00 | 2024-01-20T04:15:29.372658+00:00 | 400 | false | # Code\n```python\nclass Solution:\n def successfulPairs(\n self, spells: List[int], potions: List[int], success: int\n ) -> List[int]:\n n, _ = len(potions), potions.sort()\n return [n - bisect_left(potions, success / s) for s in spells]\n``` | 2 | 0 | ['Python3'] | 0 |
successful-pairs-of-spells-and-potions | hashmap + stack approach Beats 99.87% + Explaination 🔥✅ | hashmap-stack-approach-beats-9987-explai-vat1 | \n# Approach\n So we need to sort the potion array , why ? Because when we loop through the potion array we want to store the number of integers are infront of | LovinsonDieujuste | NORMAL | 2024-01-13T22:52:38.810855+00:00 | 2024-01-13T22:52:38.810876+00:00 | 469 | false | \n# Approach\n So we need to sort the ```potion``` array , why ? Because when we loop through the ``` potion``` array we want to store the number of integers are infront of `potion[i]` \n\nFor Example: ```potions = [5,2,4,3,1]``` \nWhen we sort it we get this ```[1,2,3,4,5]```\nNow we know that 5 numbers are greater o... | 2 | 0 | ['Hash Table', 'Stack', 'Python3'] | 1 |
successful-pairs-of-spells-and-potions | [Binary Search] Easy Solution in Python | binary-search-easy-solution-in-python-by-jrrr | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | hongyingyue | NORMAL | 2024-01-05T07:24:30.449811+00:00 | 2024-01-05T07:24:30.449846+00:00 | 199 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Python3'] | 0 |
successful-pairs-of-spells-and-potions | 🔥🔥Easy Solutions in Java || Beats 75.85% | easy-solutions-in-java-beats-7585-by-ans-c39t | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | AnsH29 | NORMAL | 2023-10-20T02:26:53.621588+00:00 | 2023-10-20T02:26:53.621608+00:00 | 649 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Java'] | 0 |
successful-pairs-of-spells-and-potions | Successful Pairs of Spells and Potions C++ solution | successful-pairs-of-spells-and-potions-c-q70a | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rissabh361 | NORMAL | 2023-09-07T05:16:05.637716+00:00 | 2023-09-07T05:16:05.637743+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['C++'] | 0 |
successful-pairs-of-spells-and-potions | C++ | | Binary Search | c-binary-search-by-rhythm_jain-9dyy | \nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n=potions.size();\n | rhythm_jain_ | NORMAL | 2023-07-17T10:14:32.226251+00:00 | 2023-07-17T10:14:32.226272+00:00 | 15 | false | ```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n=potions.size();\n sort(potions.begin(), potions.end());\n vector<int> ans;\n for(long it: spells)\n {\n int start=0;\n int end=... | 2 | 0 | ['Binary Search', 'Sorting', 'Binary Tree', 'C++'] | 1 |
successful-pairs-of-spells-and-potions | (sorting-->mlogm) and (traverse+binary serach--> nlogm) solution | sorting-mlogm-and-traversebinary-serach-mvo27 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Leximoberg | NORMAL | 2023-07-09T02:47:46.684202+00:00 | 2023-07-09T02:47:46.684222+00:00 | 61 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.