diff --git a/README.md b/README.md index 6db9fcb..79fb745 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,215 @@ -# LeetCode-in-Python -LeeteCode-in-Python is a GitHub repo with Python solutions to LeetCode problems. It offers clean, efficient, and well-documented code for interview prep, competitive programming, and mastering algorithms. Solutions are categorized by difficulty and include explanations for clarity. Regularly updated, it emphasizes Pythonic practices. +# LeetCode Python Solutions + + + +This repository contains Python solutions for various LeetCode problems. Each problem is organized in its own directory under the `Solution/` folder, with a `readme.md` file providing the problem description, examples, constraints, and solutions in multiple programming languages. + +## π Why Use This Repository? + +#### **"Success is the sum of small efforts, repeated day in and day out."** β Robert Collier + +This repository is designed to help you: + +- **Master Problem-Solving**: Tackle a wide range of LeetCode problems with clear and concise solutions. +- **Learn Efficiently**: Understand optimized approaches and advanced techniques. +- **Stay Motivated**: Progress step by step, and see your skills grow with every solved problem. +- **Collaborate and Contribute**: Join a community of learners and developers to share knowledge and improve together. + +Whether you're preparing for coding interviews, enhancing your algorithmic skills, or just exploring the joy of problem-solving, this repository is your companion on the journey to success. + +--- + +## π Table of Contents + +- [π Features](#-features) +- [π Repository Structure](#-repository-structure) +- [π οΈ How to Use](#οΈ-how-to-use) +- [π Highlights](#-highlights) +- [π€ Contributing](#-contributing) + - [Steps to Contribute](#steps-to-contribute) + - [Contribution Graph](#contribution-graph) +- [π License](#-license) +- [π Statistics](#-statistics) +- [π Quick Links](#-quick-links) +- [Index of LeetCode Python Solutions](#index-of-leetcode-python-solutions) + +## π Features + +- **Comprehensive Solutions**: Includes Python solutions for a wide range of LeetCode problems. +- **Multi-Language Support**: Problem descriptions and solutions are available in multiple programming languages. +- **Organized Structure**: Each problem is neatly organized in its own directory with a dedicated `readme.md` file. +- **Interactive and Informative**: Easy-to-navigate structure with detailed explanations and examples. + +## π Repository Structure + +```mermaid +graph TD + A[Root Directory] --> B[LICENSE] + A --> C[README.md] + A --> D[.gitattribute] + A --> E[Solution/] + A --> E12[gitignore] + A --> E14[workflow] + E --> F[LeetCode Qutions] + F --> |follow instructions| F1[README.md] + G[Readme.md] + F --> |Edit For Contribute| G1[Solutions.py] +``` + +## π οΈ How to Use + +1. Navigate to the `Solution/` folder. +2. Find the directory corresponding to the problem you are interested in (e.g., `104. Maximum Depth of Binary Tree`). +3. Open the `readme.md` file for the problem description, examples, and solutions. +4. Review the Python solution in the `.py` file. + +## π Highlights + +- **Beginner-Friendly**: Solutions are written in a clear and concise manner, making them easy to understand. +- **Advanced Techniques**: Includes optimized solutions for complex problems. +- **Regular Updates**: The repository is continuously updated with new problems and solutions. + +## π€ Contributing + +Contributions are welcome! If you have a better solution or additional test cases, feel free to submit a pull request. + +### Steps to Contribute + +1. Fork the repository. +2. Create a new branch for your changes. +3. Add your solution or update an existing one. +4. Commit your changes with a descriptive message. +5. Submit a pull request. + +### Contribution Graph + +```mermaid +graph TD + A[Contributors] --> B[Add New Solutions] + A --> C[Fix Bugs in Existing Solutions] + A --> D[Improve Documentation] + A --> E[Add Test Cases] + B --> F[Python Solutions] + B --> G[Multi-Language Support] + C --> H[Code Optimization] + D --> I[Update README.md] + D --> J[Add Problem Descriptions] + E --> K[Edge Cases] + E --> L[Performance Tests] +``` + +### Contribution Graph + +```mermaid +graph TB; + A[Contributors] --> B[Fork] + B --> C[Clone in your system] + C --> D[Create Branch] + D --> E[Add Solution or Update Existing One] + E --> F[Commit Changes] + F --> G[Push Changes] + E --> L[Add Performance] + L --> M[Add Test Cases] + M --> N[Add Edge Cases] + N --> O[ Performance Tests] -->H + G --> H[Create Pull Request] + H --> I[Merge Pull Request] + I --> J[Add Reviewer of owner] + J --> K[Add lebels] + +``` + +## π License + +This repository is licensed under the MIT License. See the `LICENSE` file for more details. + +--- + +## π Statistics + +- **Total Problems Solved**: 100+ (and counting!) +- **Languages Supported**: Python, Java, C++, Go, TypeScript +- **Difficulty Levels**: Easy, Medium, Hard + +--- + +## π Quick Links + +- [LeetCode Website](https://leetcode.com/) +- [Contribute to this Repo](https://github.com/your-repo-link) +- [MIT License](LICENSE) + +--- + + + +## Index of LeetCode Python Solutions + +This index provides a quick overview of all the problems and solutions available in this repository. Each problem is organized under the `Solution/` folder, and older solutions are stored in the `privious/` folder. + +## π Solution Directory + +### Problems by ID + +- [**1004. Max Consecutive Ones III**](Solution/1004.%20Max%20Consecutive%20Ones%20III/readme.md) +- [**104. Maximum Depth of Binary Tree**](Solution/104.%20Maximum%20Depth%20of%20Binary%20Tree/readme.md) +- [**11. Container With Most Water**](Solution/11.%20Container%20With%20Most%20Water/readme.md) +- [**1161. Maximum Level Sum of a Binary Tree**](Solution/1161.%20Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/readme.md) +- [**1207. Unique Number of Occurrences**](Solution/1207.%20Unique%20Number%20of%20Occurrences/readme.md) +- [**1372. Longest ZigZag Path in a Binary Tree**](Solution/1372.%20Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/readme.md) +- [**1448. Count Good Nodes in Binary Tree**](Solution/1448.%20Count%20Good%20Nodes%20in%20Binary%20Tree/readme.md) +- [**1456. Maximum Number of Vowels in a Substring of Given Length**](Solution/1456.%20Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/readme.md) +- [**1466. Reorder Routes to Make All Paths Lead to the City Zero**](Solution/1466.%20Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/readme.md) +- [**1493. Longest Subarray of 1's After Deleting One Element**](Solution/1493.%20Longest%20Subarray%20of%201's%20After%20Deleting%20One%20Element/readme.md) +- [**151. Reverse Words in a String**](Solution/151.%20Reverse%20Words%20in%20a%20String/readme.md) +- [**1657. Determine if Two Strings Are Close**](Solution/1657.%20Determine%20if%20Two%20Strings%20Are%20Close/readme.md) +- [**1679. Max Number of K-Sum Pairs**](Solution/1679.%20Max%20Number%20of%20K-Sum%20Pairs/readme.md) +- [**1732. Find the Highest Altitude**](Solution/1732.%20Find%20the%20Highest%20Altitude/readme.md) +- [**1926. Nearest Exit from Entrance in Maze**](Solution/1926.%20Nearest%20Exit%20from%20Entrance%20in%20Maze/readme.md) +- [**199. Binary Tree Right Side View**](Solution/199.%20Binary%20Tree%20Right%20Side%20View/readme.md) +- [**206. Reverse Linked List**](Solution/206.%20Reverse%20Linked%20List/readme.md) +- [**2095. Delete the Middle Node of a Linked List**](Solution/2095.%20Delete%20the%20Middle%20Node%20of%20a%20Linked%20List/readme.md) +- [**2130. Maximum Twin Sum of a Linked List**](Solution/2130.%20Maximum%20Twin%20Sum%20of%20a%20Linked%20List/readme.md) +- [**215. Kth Largest Element in an Array**](Solution/215.%20Kth%20Largest%20Element%20in%20an%20Array/readme.md) +- [**2215. Find the Difference of Two Arrays**](Solution/2215.%20Find%20the%20Difference%20of%20Two%20Arrays/readme.md) +- [**2336. Smallest Number in Infinite Set**](Solution/2336.%20Smallest%20Number%20in%20Infinite%20Set/readme.md) +- [**2352. Equal Row and Column Pairs**](Solution/2352.%20Equal%20Row%20and%20Column%20Pairs/readme.md) +- [**236. Lowest Common Ancestor of a Binary Tree**](Solution/236.%20Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/readme.md) +- [**238. Product of Array Except Self**](Solution/238.%20Product%20of%20Array%20Except%20Self/readme.md) +- [**2390. Removing Stars From a String**](Solution/2390.%20Removing%20Stars%20From%20a%20String/readme.md) +- [**2462. Total Cost to Hire K Workers**](Solution/2462.%20Total%20Cost%20to%20Hire%20K%20Workers/readme.md) +- [**2542. Maximum Subsequence Score**](Solution/2542.%20Maximum%20Subsequence%20Score/readme.md) +- [**283. Move Zeroes**](Solution/283.%20Move%20Zeroes/readme.md) +- [**328. Odd Even Linked List**](Solution/328.%20Odd%20Even%20Linked%20List/readme.md) +- [**334. Increasing Triplet Subsequence**](Solution/334.%20Increasing%20Triplet%20Subsequence/readme.md) +- [**345. Reverse Vowels of a String**](Solution/345.%20Reverse%20Vowels%20of%20a%20String/readme.md) +- [**374. Guess Number Higher or Lower**](Solution/374.%20Guess%20Number%20Higher%20or%20Lower/readme.md) +- [**392. Is Subsequence**](Solution/392.%20Is%20Subsequence/readme.md) +- [**394. Decode String**](Solution/394.%20Decode%20String/readme.md) +- [**399. Evaluate Division**](Solution/399.%20Evaluate%20Division/readme.md) +- [**437. Path Sum III**](Solution/437.%20Path%20Sum%20III/readme.md) +- [**443. String Compression**](Solution/443.%20String%20Compression/readme.md) +- [**450. Delete Node in a BST**](Solution/450.%20Delete%20Node%20in%20a%20BST/readme.md) +- [**547. Number of Provinces**](Solution/547.%20Number%20of%20Provinces/readme.md) +- [**643. Maximum Average Subarray I**](Solution/643.%20Maximum%20Average%20Subarray%20I/readme.md) +- [**649. Dota2 Senate**](Solution/649.%20Dota2%20Senate/readme.md) +- [**700. Search in a Binary Search Tree**](Solution/700.%20Search%20in%20a%20Binary%20Search%20Tree/readme.md) +- [**724. Find Pivot Index**](Solution/724.%20Find%20Pivot%20Index/readme.md) +- [**735. Asteroid Collision**](Solution/735.%20Asteroid%20Collision/readme.md) +- [**841. Keys and Rooms**](Solution/841.%20Keys%20and%20Rooms/readme.md) + +## π Previous Solutions Directory + +### Problems by ID + +- [**2115. Find All Possible Recipes from Given Supplies**](privious/2115.%20Find%20All%20Possible%20Recipes%20from%20Given%20Supplies.py) +- [**2206. Divide Array Into Equal Pairs**](privious/2206.%20Divide%20Array%20Into%20Equal%20Pairs.py) +- [**2226. Maximum Candies Allocated to K Children**](privious/2226.%20Maximum%20Candies%20Allocated%20to%20K%20Children.py) +- [**2560. House Robber IV**](privious/2560.%20House%20Robber%20IV.py) +- [**2594. Minimum Time to Repair Cars**](privious/2594.%20Minimum%20Time%20to%20Repair%20Cars.py) +- [**3356. Zero Array Transformation II**](privious/3356.%20Zero%20Array%20Transformation%20II.py) + +--- + +For detailed problem descriptions and solutions, navigate to the respective directories. + diff --git a/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/1466. Reorder Routes to Make All Paths Lead to the City Zero.py b/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/1466. Reorder Routes to Make All Paths Lead to the City Zero.py new file mode 100644 index 0000000..a8f58ae --- /dev/null +++ b/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/1466. Reorder Routes to Make All Paths Lead to the City Zero.py @@ -0,0 +1,10 @@ +class Solution: + def minReorder(self, n: int, connections: List[List[int]]) -> int: + def dfs(a: int, fa: int) -> int: + return sum(c + dfs(b, a) for b, c in g[a] if b != fa) + + g = [[] for _ in range(n)] + for a, b in connections: + g[a].append((b, 1)) + g[b].append((a, 0)) + return dfs(0, -1) \ No newline at end of file diff --git a/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/readme.md b/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/readme.md new file mode 100644 index 0000000..bcc9cd3 --- /dev/null +++ b/Solution/1466. Reorder Routes to Make All Paths Lead to the City Zero/readme.md @@ -0,0 +1,331 @@ + + + +# [1466. Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) + +--- +- **comments**: true +- **difficulty**: Medium +- **edit_url**: https://github.com/doocs/leetcode/edit/main/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md +- **rating**: 1633 +- **source**: Weekly Contest 191 Q3 +- **tags**: + - Depth-First Search + - Breadth-First Search + - Graph + +## Description + + + +
There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.
Roads are represented by connections where connections[i] = [ai, bi] represents a road from city ai to city bi.
This year, there will be a big event in the capital (city 0), and many people want to travel to this city.
Your task consists of reorienting some roads such that each city can visit the city 0. Return the minimum number of edges changed.
It's guaranteed that each city can reach city 0 after reorder.
+
Example 1:
+
++Input: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]] +Output: 3 +Explanation: Change the direction of edges show in red such that each node can reach the node 0 (capital). ++ +
Example 2:
+
++Input: n = 5, connections = [[1,0],[1,2],[3,2],[3,4]] +Output: 2 +Explanation: Change the direction of edges show in red such that each node can reach the node 0 (capital). ++ +
Example 3:
+ ++Input: n = 3, connections = [[1,0],[2,0]] +Output: 0 ++ +
+
Constraints:
+ +2 <= n <= 5 * 104connections.length == n - 1connections[i].length == 20 <= ai, bi <= n - 1ai != biYou are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entrance = [entrancerow, entrancecol] denotes the row and column of the cell you are initially standing at.
In one step, you can move one cell up, down, left, or right. You cannot step into a cell with a wall, and you cannot step outside the maze. Your goal is to find the nearest exit from the entrance. An exit is defined as an empty cell that is at the border of the maze. The entrance does not count as an exit.
Return the number of steps in the shortest path from the entrance to the nearest exit, or -1 if no such path exists.
+
Example 1:
+
++Input: maze = [["+","+",".","+"],[".","",".",".","+"],["+","+","+","."]], entrance = [1,2] +Output: 1 +Explanation: +There are 3 exits in this maze at [1,0], [0,2], and [2,3]. +Initially, you are at the entrance cell [1,2]. +- You can reach [1,0] by moving 2 steps left. +- You can reach [0,2] by moving 1 step up. +It is impossible to reach [2,3] from the entrance. +Thus, the nearest exit is [0,2], which is 1 step away. ++ +
Example 2:
+
++Input: maze = [["+","+","+"],[".","",".","."],["+","+","+"]], entrance = [1,0] +Output: 2 +Explanation: +There is 1 exit in this maze at [1,2]. +[1,0] does not count as an exit since it is the entrance cell. +Initially, you are at the entrance cell [1,0]. +- You can reach [1,2] by moving 2 steps right. +Thus, the nearest exit is [1,2], which is 2 steps away. ++ +
Example 3:
+
++Input: maze = [[".","+"]], entrance = [0,0] +Output: -1 +Explanation: +There are no exits in this maze. ++ +
+
Constraints:
+ +maze.length == mmaze[i].length == n1 <= m, n <= 100maze[i][j] is either '. or '+'.entrance.length == 20 <= entrancerow < m0 <= entrancecol < nentrance will always be an empty cell.You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.
You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:
k sessions and hire exactly one worker in each session.candidates workers or the last candidates workers. Break the tie by the smallest index.candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.Return the total cost to hire exactly k workers.
+
Example 1:
+ ++Input: costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4 +Output: 11 +Explanation: We hire 3 workers in total. The total cost is initially 0. +- In the first hiring round we choose the worker from [17,12,10,2,7,2,11,20,8]. The lowest cost is 2, and we break the tie by the smallest index, which is 3. The total cost = 0 + 2 = 2. +- In the second hiring round we choose the worker from [17,12,10,7,2,11,20,8]. The lowest cost is 2 (index 4). The total cost = 2 + 2 = 4. +- In the third hiring round we choose the worker from [17,12,10,7,11,20,8]. The lowest cost is 7 (index 3). The total cost = 4 + 7 = 11. +The total hiring cost is 11. ++ +
Example 2:
+ ++Input: costs = [1,2,4,1], k = 3, candidates = 3 +Output: 4 +Explanation: We hire 3 workers in total. The total cost is initially 0. +- In the first hiring round we choose the worker from [1,2,4,1]. The lowest cost is 1, and we break the tie by the smallest index, which is 0. The total cost = 0 + 1 = 1. +- In the second hiring round we choose the worker from [2,4,1]. The lowest cost is 1 (index 2). The total cost = 1 + 1 = 2. +- In the third hiring round there are less than three candidates. We choose the worker from the remaining workers [2,4]. The lowest cost is 2 (index 0). The total cost = 2 + 2 = 4. +The total hiring cost is 4. ++ +
+
Constraints:
+ +1 <= costs.length <= 105 1 <= costs[i] <= 1051 <= k, candidates <= costs.lengthYou are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.
For chosen indices i0, i1, ..., ik - 1, your score is defined as:
nums1 multiplied with the minimum of the selected elements from nums2.(nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1]).Return the maximum possible score.
+ +A subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.
+
Example 1:
+ ++Input: nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3 +Output: 12 +Explanation: +The four possible subsequence scores are: +- We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7. +- We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6. +- We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12. +- We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8. +Therefore, we return the max score, which is 12. ++ +
Example 2:
+ ++Input: nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1 +Output: 30 +Explanation: +Choosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score. ++ +
+
Constraints:
+ +n == nums1.length == nums2.length1 <= n <= 1050 <= nums1[i], nums2[j] <= 1051 <= k <= nWe are playing the Guess Game. The game is as follows:
+ +I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.
+ +You call a pre-defined API int guess(int num), which returns three possible results:
-1: Your guess is higher than the number I picked (i.e. num > pick).1: Your guess is lower than the number I picked (i.e. num < pick).0: your guess is equal to the number I picked (i.e. num == pick).Return the number that I picked.
+ ++
Example 1:
+ ++Input: n = 10, pick = 6 +Output: 6 ++ +
Example 2:
+ ++Input: n = 1, pick = 1 +Output: 1 ++ +
Example 3:
+ ++Input: n = 2, pick = 1 +Output: 1 ++ +
+
Constraints:
+ +1 <= n <= 231 - 11 <= pick <= nYou are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.
You are also given some queries, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?.
Return the answers to all queries. If a single answer cannot be determined, return -1.0.
Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.
+ +Note: The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them.
+ ++
Example 1:
+ ++Input: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] +Output: [6.00000,0.50000,-1.00000,1.00000,-1.00000] +Explanation: +Given: a / b = 2.0, b / c = 3.0 +queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? +return: [6.0, 0.5, -1.0, 1.0, -1.0 ] +note: x is undefined => -1.0+ +
Example 2:
+ ++Input: equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]] +Output: [3.75000,0.40000,5.00000,0.20000] ++ +
Example 3:
+ ++Input: equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]] +Output: [0.50000,2.00000,-1.00000,-1.00000] ++ +
+
Constraints:
+ +1 <= equations.length <= 20equations[i].length == 21 <= Ai.length, Bi.length <= 5values.length == equations.length0.0 < values[i] <= 20.01 <= queries.length <= 20queries[i].length == 21 <= Cj.length, Dj.length <= 5Ai, Bi, Cj, Dj consist of lower case English letters and digits.You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion.
You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.
Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the ith spell.
+
Example 1:
+ ++Input: spells = [5,1,3], potions = [1,2,3,4,5], success = 7 +Output: [4,0,3] +Explanation: +- 0th spell: 5 * [1,2,3,4,5] = [5,10,15,20,25]. 4 pairs are successful. +- 1st spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful. +- 2nd spell: 3 * [1,2,3,4,5] = [3,6,9,12,15]. 3 pairs are successful. +Thus, [4,0,3] is returned. ++ +
Example 2:
+ ++Input: spells = [3,1,2], potions = [8,5,8], success = 16 +Output: [2,0,2] +Explanation: +- 0th spell: 3 * [8,5,8] = [24,15,24]. 2 pairs are successful. +- 1st spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful. +- 2nd spell: 2 * [8,5,8] = [16,10,16]. 2 pairs are successful. +Thus, [2,0,2] is returned. ++ +
+
Constraints:
+ +n == spells.lengthm == potions.length1 <= n, m <= 1051 <= spells[i], potions[i] <= 1051 <= success <= 1010