title stringlengths 1 100 | titleSlug stringlengths 3 77 | Java int64 0 1 | Python3 int64 1 1 | content stringlengths 28 44.4k | voteCount int64 0 3.67k | question_content stringlengths 65 5k | question_hints stringclasses 970
values |
|---|---|---|---|---|---|---|---|
Python3: Recursive Dict Approach | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Intuition\nUsing a dictionary to keep track of used substrings\n\n# Approach\n- index: The current index in the string \'s\'. It determines the starting point for creating substrings at each level of recursion.\n- cur: A dictionary to keep track of the current substrings that have been encountered.\n```\ndef recursiv... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Concise solution on python3 | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | \n# Code\n```\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n \n def go(start, used):\n if start == len(s):\n return len(used)\n\n cur = ""\n ans = 0\n for i in range(start, len(s)):\n cur = cur + s[i]\n ... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Python Bit Mask, Easy to Understand | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Intuition\nWhen overcoming questions like this, think about DP. If DP fails, then no choice we need to bruteforce\n\n# Approach\nHow to make array of permutation:\nThink about divider as 1 and no divider as 0\nabba -> a [] b | b [] a, divider = [no, divide, no]\nabba -> a | b [] b | a, divider = [divide, no, divide ]... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Recursion | Used Dictionary | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n self.count = 0\n self.counter = {}\n\n def solve(s, cnt):\n if s == "":\n self.count = max(self.count, cnt)\n return\n\n for i in range(len(s)):\n if s... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Python3 + Backtracking | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Code\n```\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n unique = set()\n curr = []\n max_len = 1\n\n def backtrack(i):\n nonlocal max_len\n if i == len(s):\n if len(curr) > 1:\n max_len = max(max_len,len(curr))\n ... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Easy Python Solution | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Code\n```\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n unique_set=set()\n count=0\n ans=0\n def backtrack(start, count):\n nonlocal ans\n if start==len(s):\n ans= max(ans, count)\n for end in range(start+1, len(s)+1):\n ... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
[Python3] Simple Backtracking | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Code\n```\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n self.hs = set()\n def helper(cur):\n if cur >= len(s):\n return 0\n ret = 0\n for i in range(cur+1, len(s)+1):\n if s[cur: i] not in self.hs:\n sel... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Python (Simple Backtracking) | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # 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)$$ --... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
Typical backtracking problem | clear code | full explanation | split-a-string-into-the-max-number-of-unique-substrings | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Use a set to keep track of which substrings have been used already.\n2. Try each possible substring at every position and backtrack if a complete split is not possible.\n# Approach\n<!-- Describe your approach to solving the problem. -... | 0 | Given a string `s`, return _the maximum number of unique substrings that the given string can be split into_.
You can split string `s` into any list of **non-empty substrings**, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are **uniqu... | null |
[Python3] top-down dp | maximum-non-negative-product-in-a-matrix | 0 | 1 | \n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n \n @lru_cache(None)\n def fn(i, j): \n """Return maximum & minimum products ending at (i, j)."""\n if i == 0 and j == 0: return grid[0][0], grid[0][0]\... | 39 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
[Python3] top-down dp | maximum-non-negative-product-in-a-matrix | 0 | 1 | \n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n \n @lru_cache(None)\n def fn(i, j): \n """Return maximum & minimum products ending at (i, j)."""\n if i == 0 and j == 0: return grid[0][0], grid[0][0]\... | 39 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
[Python3] Bottom-up Dynamic Programming | maximum-non-negative-product-in-a-matrix | 0 | 1 | ### Intuition\nTypical bottom-up solution\n\n### Complexity\n`time`: `O(M * N)`\n`space`: `O(M * N)`\t\t\n### Solution\n```python\ndef maxProductPath(self, A: List[List[int]]) -> int:\n\tm, n = len(A), len(A[0])\n\tMax = [[0] * n for _ in range(m)]\n\tMin = [[0] * n for _ in range(m)]\n\tMax[0][0] = A[0][0]\n\tMin[0][0... | 16 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
[Python3] Bottom-up Dynamic Programming | maximum-non-negative-product-in-a-matrix | 0 | 1 | ### Intuition\nTypical bottom-up solution\n\n### Complexity\n`time`: `O(M * N)`\n`space`: `O(M * N)`\t\t\n### Solution\n```python\ndef maxProductPath(self, A: List[List[int]]) -> int:\n\tm, n = len(A), len(A[0])\n\tMax = [[0] * n for _ in range(m)]\n\tMin = [[0] * n for _ in range(m)]\n\tMax[0][0] = A[0][0]\n\tMin[0][0... | 16 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
DFS || Dynamic Programming || Memoization || Python3 | maximum-non-negative-product-in-a-matrix | 0 | 1 | ```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n def isBound(row,col):\n return 0<=row<len(grid) and 0<=col<len(grid[0])\n \n @lru_cache(None)\n def dfs(row,col,product):\n if not isBound(row, col):\n return -1\n ... | 2 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
DFS || Dynamic Programming || Memoization || Python3 | maximum-non-negative-product-in-a-matrix | 0 | 1 | ```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n def isBound(row,col):\n return 0<=row<len(grid) and 0<=col<len(grid[0])\n \n @lru_cache(None)\n def dfs(row,col,product):\n if not isBound(row, col):\n return -1\n ... | 2 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
Python 3 | DP O(m*n) time, In place | Explanation | maximum-non-negative-product-in-a-matrix | 0 | 1 | ### Explanation\n- At each position `(i, j)`, maintain a tuple for `(small, large)`\n\t- small: smallest product up to this point\n\t- large: largest product up to this point\n- Update each point from top to bottom, from left to right. Current `small` or `large` only depends on values on the left or above.\n### Impleme... | 6 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
Python 3 | DP O(m*n) time, In place | Explanation | maximum-non-negative-product-in-a-matrix | 0 | 1 | ### Explanation\n- At each position `(i, j)`, maintain a tuple for `(small, large)`\n\t- small: smallest product up to this point\n\t- large: largest product up to this point\n- Update each point from top to bottom, from left to right. Current `small` or `large` only depends on values on the left or above.\n### Impleme... | 6 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
Bottom Up Dp Solution | maximum-non-negative-product-in-a-matrix | 0 | 1 | ```\nclass Solution:\n \n # O(n*m) time,\n # O(n*m) space,\n # Approach: bottom up dp, greedy\n def maxProductPath(self, grid: List[List[int]]) -> int:\n \n \'\'\'\n the key take here is to store the smallest negative number and largest positive value at each cell,\n t... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
Bottom Up Dp Solution | maximum-non-negative-product-in-a-matrix | 0 | 1 | ```\nclass Solution:\n \n # O(n*m) time,\n # O(n*m) space,\n # Approach: bottom up dp, greedy\n def maxProductPath(self, grid: List[List[int]]) -> int:\n \n \'\'\'\n the key take here is to store the smallest negative number and largest positive value at each cell,\n t... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
python3 solution for bp | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n m = len(grid)\n n = len(grid[0])\n dp = [[[float(\'inf\'), -float(\'inf\')] for _ in range(n)] for _ in range(m)]\n dp[0][0] = [grid[0][0], grid[0][0]]\n for i in range(m):\n for j i... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
python3 solution for bp | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n m = len(grid)\n n = len(grid[0])\n dp = [[[float(\'inf\'), -float(\'inf\')] for _ in range(n)] for _ in range(m)]\n dp[0][0] = [grid[0][0], grid[0][0]]\n for i in range(m):\n for j i... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
[Python 3] Top Down DP | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\nSimilar to Maximum Product Subarray problem\n\n\n# Complexity\n- Time complexity:\n O(m*n)\n- Space complexity:\n O(m*n) but can be optimized to O(n) by keeping track of only previous row and current row\n\n# Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n ... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
[Python 3] Top Down DP | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\nSimilar to Maximum Product Subarray problem\n\n\n# Complexity\n- Time complexity:\n O(m*n)\n- Space complexity:\n O(m*n) but can be optimized to O(n) by keeping track of only previous row and current row\n\n# Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n ... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
Python - typical bottom up DP | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Complexity\n- Time complexity:\n$$O(n)$$ - n is number of cells in grid\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution:\n def maxProductPath(self, g: List[List[int]]) -> int:\n R, C, mod = len(g), len(g[0]), 1_000_000_007\n dp = [[[inf, -inf] for _ in range(C)] for _ in range(R)]\n ... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
Python - typical bottom up DP | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Complexity\n- Time complexity:\n$$O(n)$$ - n is number of cells in grid\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution:\n def maxProductPath(self, g: List[List[int]]) -> int:\n R, C, mod = len(g), len(g[0]), 1_000_000_007\n dp = [[[inf, -inf] for _ in range(C)] for _ in range(R)]\n ... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
[Python3] Simple Top Down Two Method Approach | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n \n m = len(grid)\n n = len(grid[0])\n\n @cache\n def dpPositive(r,c): # returns the largest positive product path from r,c\n if not (0<=r<m and 0<=c<n):\n return -1\n ... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
[Python3] Simple Top Down Two Method Approach | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Code\n```\nclass Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:\n \n m = len(grid)\n n = len(grid[0])\n\n @cache\n def dpPositive(r,c): # returns the largest positive product path from r,c\n if not (0<=r<m and 0<=c<n):\n return -1\n ... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
Simple Python Solution | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCreate a 2D list which stores the [min, max] for every (row,col). then return the max value of bottom right.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N2)\n<!-- Add your t... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
Simple Python Solution | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCreate a 2D list which stores the [min, max] for every (row,col). then return the max value of bottom right.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N2)\n<!-- Add your t... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
[91.82% Faster] Easy DP solution, clean code and easy to understand | maximum-non-negative-product-in-a-matrix | 0 | 1 | <!-- # Intuition\nDescribe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nEach item in the DP matrix is a tuple that memorize... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
[91.82% Faster] Easy DP solution, clean code and easy to understand | maximum-non-negative-product-in-a-matrix | 0 | 1 | <!-- # Intuition\nDescribe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nEach item in the DP matrix is a tuple that memorize... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
Python3 48ms solution. | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy first thought to solve this problem is to use dynamic programming. By keeping track of the maximum and minimum product of subproblems, we can build up the answer for the entire grid.\n# Approach\n<!-- Describe your approach to solving ... | 0 | You are given a `m x n` matrix `grid`. Initially, you are located at the top-left corner `(0, 0)`, and in each step, you can only **move right or down** in the matrix.
Among all possible paths starting from the top-left corner `(0, 0)` and ending in the bottom-right corner `(m - 1, n - 1)`, find the path with the **ma... | null |
Python3 48ms solution. | maximum-non-negative-product-in-a-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy first thought to solve this problem is to use dynamic programming. By keeping track of the maximum and minimum product of subproblems, we can build up the answer for the entire grid.\n# Approach\n<!-- Describe your approach to solving ... | 0 | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
Given... | Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point. |
LRU Cache for Speed, Memo if Memory | Pick Your Optimization | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA recursive solution can work well if you start to break down what the problem asks in concrete steps \n\nFor any graph of costs, there exists a min cost per column \nIf we know the min cost per column, then we can map out our cheapest co... | 0 | You are given two groups of points where the first group has `size1` points, the second group has `size2` points, and `size1 >= size2`.
The `cost` of the connection between any two points are given in an `size1 x size2` matrix where `cost[i][j]` is the cost of connecting point `i` of the first group and point `j` of t... | null |
LRU Cache for Speed, Memo if Memory | Pick Your Optimization | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA recursive solution can work well if you start to break down what the problem asks in concrete steps \n\nFor any graph of costs, there exists a min cost per column \nIf we know the min cost per column, then we can map out our cheapest co... | 0 | You are given a string `s` and two integers `x` and `y`. You can perform two types of operations any number of times.
* Remove substring `"ab "` and gain `x` points.
* For example, when removing `"ab "` from `"cabxbae "` it becomes `"cxbae "`.
* Remove substring `"ba "` and gain `y` points.
* For examp... | Each point on the left would either be connected to exactly point already connected to some left node, or a subset of the nodes on the right which are not connected to any node Use dynamic programming with bitmasking, where the state will be (number of points assigned in first group, bitmask of points assigned in secon... |
Python (Simple DP + Bitmasking) | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | # 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)$$ --... | 1 | You are given two groups of points where the first group has `size1` points, the second group has `size2` points, and `size1 >= size2`.
The `cost` of the connection between any two points are given in an `size1 x size2` matrix where `cost[i][j]` is the cost of connecting point `i` of the first group and point `j` of t... | null |
Python (Simple DP + Bitmasking) | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | # 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)$$ --... | 1 | You are given a string `s` and two integers `x` and `y`. You can perform two types of operations any number of times.
* Remove substring `"ab "` and gain `x` points.
* For example, when removing `"ab "` from `"cabxbae "` it becomes `"cxbae "`.
* Remove substring `"ba "` and gain `y` points.
* For examp... | Each point on the left would either be connected to exactly point already connected to some left node, or a subset of the nodes on the right which are not connected to any node Use dynamic programming with bitmasking, where the state will be (number of points assigned in first group, bitmask of points assigned in secon... |
[Python3] top-down dp | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | \n```\nclass Solution:\n def connectTwoGroups(self, cost: List[List[int]]) -> int:\n m, n = len(cost), len(cost[0])\n mn = [min(x) for x in zip(*cost)] # min cost of connecting points in 2nd group \n \n @lru_cache(None)\n def fn(i, mask):\n """Return min cost of connecti... | 2 | You are given two groups of points where the first group has `size1` points, the second group has `size2` points, and `size1 >= size2`.
The `cost` of the connection between any two points are given in an `size1 x size2` matrix where `cost[i][j]` is the cost of connecting point `i` of the first group and point `j` of t... | null |
[Python3] top-down dp | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | \n```\nclass Solution:\n def connectTwoGroups(self, cost: List[List[int]]) -> int:\n m, n = len(cost), len(cost[0])\n mn = [min(x) for x in zip(*cost)] # min cost of connecting points in 2nd group \n \n @lru_cache(None)\n def fn(i, mask):\n """Return min cost of connecti... | 2 | You are given a string `s` and two integers `x` and `y`. You can perform two types of operations any number of times.
* Remove substring `"ab "` and gain `x` points.
* For example, when removing `"ab "` from `"cabxbae "` it becomes `"cxbae "`.
* Remove substring `"ba "` and gain `y` points.
* For examp... | Each point on the left would either be connected to exactly point already connected to some left node, or a subset of the nodes on the right which are not connected to any node Use dynamic programming with bitmasking, where the state will be (number of points assigned in first group, bitmask of points assigned in secon... |
[Python] BFS with heapq and bit tricks. 90ms, beats 100% | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | The special size handling at the top makes things a bit faster; taking all the zero-cost edges before BFS gives about 50% speed boost as well, although the code still beats 100% without those.\n\nThere are 3 optimizations over other BFS or DFS solutions that are big:\n1. ```if first_mask != mask_i: ``` splits the case ... | 1 | You are given two groups of points where the first group has `size1` points, the second group has `size2` points, and `size1 >= size2`.
The `cost` of the connection between any two points are given in an `size1 x size2` matrix where `cost[i][j]` is the cost of connecting point `i` of the first group and point `j` of t... | null |
[Python] BFS with heapq and bit tricks. 90ms, beats 100% | minimum-cost-to-connect-two-groups-of-points | 0 | 1 | The special size handling at the top makes things a bit faster; taking all the zero-cost edges before BFS gives about 50% speed boost as well, although the code still beats 100% without those.\n\nThere are 3 optimizations over other BFS or DFS solutions that are big:\n1. ```if first_mask != mask_i: ``` splits the case ... | 1 | You are given a string `s` and two integers `x` and `y`. You can perform two types of operations any number of times.
* Remove substring `"ab "` and gain `x` points.
* For example, when removing `"ab "` from `"cabxbae "` it becomes `"cxbae "`.
* Remove substring `"ba "` and gain `y` points.
* For examp... | Each point on the left would either be connected to exactly point already connected to some left node, or a subset of the nodes on the right which are not connected to any node Use dynamic programming with bitmasking, where the state will be (number of points assigned in first group, bitmask of points assigned in secon... |
Very simple, self-explanatory stack based solution | crawler-log-folder | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O... | 1 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Very simple, self-explanatory stack based solution | crawler-log-folder | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O... | 1 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
Simple implementing with using Stack DS | crawler-log-folder | 0 | 1 | # Intuition\nThe descriptions is leading us to use the **stack**, that follows LIFO-schema.\n\n---\n\nIf you don\'t familiar with **stack**, lets have a look at [wiki page about stack description](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).\n\n# Approach\n1. create `stack` variable, that\'ll be store all... | 1 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Simple implementing with using Stack DS | crawler-log-folder | 0 | 1 | # Intuition\nThe descriptions is leading us to use the **stack**, that follows LIFO-schema.\n\n---\n\nIf you don\'t familiar with **stack**, lets have a look at [wiki page about stack description](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).\n\n# Approach\n1. create `stack` variable, that\'ll be store all... | 1 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
Python solution with one pass | crawler-log-folder | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIterate through the logs, \n- if there are two dots and the steps is greater than zero, then step decreases by 1\n- if there is only one dot, steps doesn\' change\n- if it\'s a folder, steps increase by 1\n\n\n\n# Complexity\n- Time compl... | 2 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Python solution with one pass | crawler-log-folder | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIterate through the logs, \n- if there are two dots and the steps is greater than zero, then step decreases by 1\n- if there is only one dot, steps doesn\' change\n- if it\'s a folder, steps increase by 1\n\n\n\n# Complexity\n- Time compl... | 2 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
Simple Python code | crawler-log-folder | 0 | 1 | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n stack = []\n for log in logs:\n ... | 1 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Simple Python code | crawler-log-folder | 0 | 1 | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n stack = []\n for log in logs:\n ... | 1 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
Easy Python Solution using Stacks | crawler-log-folder | 0 | 1 | # Code\n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n stack=[]\n for i in logs:\n if i=="./":\n continue\n elif stack and i=="../":\n stack.pop()\n elif i!=\'../\':\n stack.append(i)\n retur... | 4 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Easy Python Solution using Stacks | crawler-log-folder | 0 | 1 | # Code\n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n stack=[]\n for i in logs:\n if i=="./":\n continue\n elif stack and i=="../":\n stack.pop()\n elif i!=\'../\':\n stack.append(i)\n retur... | 4 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
[Python3] straightforward | crawler-log-folder | 0 | 1 | \n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n ans = 0\n for log in logs: \n if log == "./": continue\n elif log == "../": ans = max(0, ans-1) # parent directory\n else: ans += 1 # child directory \n return ans \n``` | 11 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
[Python3] straightforward | crawler-log-folder | 0 | 1 | \n```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n ans = 0\n for log in logs: \n if log == "./": continue\n elif log == "../": ans = max(0, ans-1) # parent directory\n else: ans += 1 # child directory \n return ans \n``` | 11 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
Intuitive code and easily understandable in Python | crawler-log-folder | 0 | 1 | ```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n res = 0\n for i in logs:\n if i == \'./\':\n continue\n elif i == \'../\':\n if res > 0:\n res -= 1\n else:\n res += 1\n retu... | 4 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
Intuitive code and easily understandable in Python | crawler-log-folder | 0 | 1 | ```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n res = 0\n for i in logs:\n if i == \'./\':\n continue\n elif i == \'../\':\n if res > 0:\n res -= 1\n else:\n res += 1\n retu... | 4 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
PYTHON | Super Easy python solution | crawler-log-folder | 0 | 1 | ```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n res = 0\n \n for i in logs:\n if i == \'../\' and res > 0:\n res -= 1\n elif i != \'./\' and i != \'../\':\n res += 1\n \n return res\n``` | 6 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
PYTHON | Super Easy python solution | crawler-log-folder | 0 | 1 | ```\nclass Solution:\n def minOperations(self, logs: List[str]) -> int:\n res = 0\n \n for i in logs:\n if i == \'../\' and res > 0:\n res -= 1\n elif i != \'./\' and i != \'../\':\n res += 1\n \n return res\n``` | 6 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
just parse string | crawler-log-folder | 0 | 1 | # 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)$$ --... | 0 | The Leetcode file system keeps a log each time some user performs a _change folder_ operation.
The operations are described below:
* `"../ "` : Move to the parent folder of the current folder. (If you are already in the main folder, **remain in the same folder**).
* `"./ "` : Remain in the same folder.
* `"x/ "... | null |
just parse string | crawler-log-folder | 0 | 1 | # 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)$$ --... | 0 | There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
You are given the `encoded` array. You are also give... | Simulate the process but don’t move the pointer beyond the main folder. Simulate the process but don’t move the pointer beyond the main folder. |
PYTHON3 O(N) SIMPLEST SIMULATION. BEATS 90% USERS. SIMPLE AND ELEGANT | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | ```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n maxProfit=-1\n ans=i=curRounds=curCustomers=rem=0\n while i<len(customers) or rem:\n if i<len(customers):\n rem+=customers[i]\n i+... | 0 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
PYTHON3 O(N) SIMPLEST SIMULATION. BEATS 90% USERS. SIMPLE AND ELEGANT | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | ```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n maxProfit=-1\n ans=i=curRounds=curCustomers=rem=0\n while i<len(customers) or rem:\n if i<len(customers):\n rem+=customers[i]\n i+... | 0 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
Board passengers only when it is possible | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | # Intuition\nParse through all the inputs.\n\nBoard only when it is profitable (onboarding n people makes more money than it costs to run the wheel).\n\n# Code\n```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n result = -1\n pro... | 0 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
Board passengers only when it is possible | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | # Intuition\nParse through all the inputs.\n\nBoard only when it is profitable (onboarding n people makes more money than it costs to run the wheel).\n\n# Code\n```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n result = -1\n pro... | 0 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
[LC-1599-M | Python3] A Plain Solution | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | Determine the actual length of the customers\' queue, and then use the iteration. (This approach is straightforward but not fast.)\n\n```python3 []\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n if 4 * boardingCost < runningCost:\n ... | 0 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
[LC-1599-M | Python3] A Plain Solution | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | Determine the actual length of the customers\' queue, and then use the iteration. (This approach is straightforward but not fast.)\n\n```python3 []\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n if 4 * boardingCost < runningCost:\n ... | 0 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
Python (Simple Maths) | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | # 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)$$ --... | 0 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
Python (Simple Maths) | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | # 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)$$ --... | 0 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
[Python3] simulation | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | \n```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n ans = -1\n most = pnl = waiting = 0\n for i, x in enumerate(customers): \n waiting += x # more people waiting in line \n waiting -= (chg := min(4, ... | 6 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
[Python3] simulation | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | \n```\nclass Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n ans = -1\n most = pnl = waiting = 0\n for i, x in enumerate(customers): \n waiting += x # more people waiting in line \n waiting -= (chg := min(4, ... | 6 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
Python [Simulation] | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | ```\nclass Solution:\n def minOperationsMaxProfit(self, arr: List[int], boardingCost : int, runningCost : int) -> int:\n # Dividing people in the groups of <=4\n grps = []\n # length of customers array\n n = len(arr)\n # rem--> number of people waiting\n rem = 0\n \n ... | 4 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
Python [Simulation] | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | ```\nclass Solution:\n def minOperationsMaxProfit(self, arr: List[int], boardingCost : int, runningCost : int) -> int:\n # Dividing people in the groups of <=4\n grps = []\n # length of customers array\n n = len(arr)\n # rem--> number of people waiting\n rem = 0\n \n ... | 4 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
Python O(n) Solution, faster than 100% | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | **First Observation:** If `boardingCost * 4 <= runningCost`, there is no way to make profit, so return `-1` \n \n**Second Observation**: Instead of looping with increment of 4 per cycle, if we can directly calculate number of rounds for the given number of *waiting* customers, we can save a lot of time.\nLet\'s say t... | 2 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
Python O(n) Solution, faster than 100% | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | **First Observation:** If `boardingCost * 4 <= runningCost`, there is no way to make profit, so return `-1` \n \n**Second Observation**: Instead of looping with increment of 4 per cycle, if we can directly calculate number of rounds for the given number of *waiting* customers, we can save a lot of time.\nLet\'s say t... | 2 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
[Python 3] simulation clean code | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | long code but faster because of less Comparison\'s and less variables used:\n\n\tclass Solution:\n\t\tdef minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n\t\t\tmax_profit=Profit=curr=0\n\t\t\tmax_profit_rotation=-1\n\t\t\tfor i,x in enumerate(customers):\n\t\t\t\tcurr+=x... | 0 | You are the operator of a Centennial Wheel that has **four gondolas**, and each gondola has room for **up** **to** **four people**. You have the ability to rotate the gondolas **counterclockwise**, which costs you `runningCost` dollars.
You are given an array `customers` of length `n` where `customers[i]` is the numbe... | null |
[Python 3] simulation clean code | maximum-profit-of-operating-a-centennial-wheel | 0 | 1 | long code but faster because of less Comparison\'s and less variables used:\n\n\tclass Solution:\n\t\tdef minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:\n\t\t\tmax_profit=Profit=curr=0\n\t\t\tmax_profit_rotation=-1\n\t\t\tfor i,x in enumerate(customers):\n\t\t\t\tcurr+=x... | 0 | You are given the `head` of a linked list, and an integer `k`.
Return _the head of the linked list after **swapping** the values of the_ `kth` _node from the beginning and the_ `kth` _node from the end (the list is **1-indexed**)._
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[1,4,3,2,5\]
**Ex... | Think simulation Note that the number of turns will never be more than 50 / 4 * n |
BEATS 95.00%! | Python3 Fast Easy Solution Explained | throne-inheritance | 0 | 1 | The explanation\'s in the code comments.\n# Code\n```\nclass ThroneInheritance:\n def __init__(self, kingName: str):\n # This is equivalent to the root node in a tree.\n self.kingName = kingName\n # Since we know that all family members\' names are distinct,\n # (no two names are the same... | 0 | A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.
The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function `Successor(x, curOrder)`, which given a ... | null |
BEATS 95.00%! | Python3 Fast Easy Solution Explained | throne-inheritance | 0 | 1 | The explanation\'s in the code comments.\n# Code\n```\nclass ThroneInheritance:\n def __init__(self, kingName: str):\n # This is equivalent to the root node in a tree.\n self.kingName = kingName\n # Since we know that all family members\' names are distinct,\n # (no two names are the same... | 0 | You are given two integer arrays, `source` and `target`, both of length `n`. You are also given an array `allowedSwaps` where each `allowedSwaps[i] = [ai, bi]` indicates that you are allowed to swap the elements at index `ai` and index `bi` **(0-indexed)** of array `source`. Note that you can swap elements at a specifi... | Create a tree structure of the family. Without deaths, the order of inheritance is simply a pre-order traversal of the tree. Mark the dead family members tree nodes and don't include them in the final order. |
Python - N-tree | throne-inheritance | 0 | 1 | # Intuition\nJust construct n-tree and maintain set of dead people.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$ - getInheritanceOrder\n$$O(1)$$ - birth\n$$O(1)$$ - death\n\n# Code\n```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.succ = defaultdict... | 0 | A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.
The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function `Successor(x, curOrder)`, which given a ... | null |
Python - N-tree | throne-inheritance | 0 | 1 | # Intuition\nJust construct n-tree and maintain set of dead people.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$ - getInheritanceOrder\n$$O(1)$$ - birth\n$$O(1)$$ - death\n\n# Code\n```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.succ = defaultdict... | 0 | You are given two integer arrays, `source` and `target`, both of length `n`. You are also given an array `allowedSwaps` where each `allowedSwaps[i] = [ai, bi]` indicates that you are allowed to swap the elements at index `ai` and index `bi` **(0-indexed)** of array `source`. Note that you can swap elements at a specifi... | Create a tree structure of the family. Without deaths, the order of inheritance is simply a pre-order traversal of the tree. Mark the dead family members tree nodes and don't include them in the final order. |
Simple Python3 DFS | throne-inheritance | 0 | 1 | \n\n# Code\n```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.family = defaultdict(list)\n self.king = kingName\n self.dead = defaultdict(bool)\n \n def birth(self, parentName: str, childName: str) -> None:\n self.family[parentName].append(childName)\n\... | 0 | A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.
The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function `Successor(x, curOrder)`, which given a ... | null |
Simple Python3 DFS | throne-inheritance | 0 | 1 | \n\n# Code\n```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.family = defaultdict(list)\n self.king = kingName\n self.dead = defaultdict(bool)\n \n def birth(self, parentName: str, childName: str) -> None:\n self.family[parentName].append(childName)\n\... | 0 | You are given two integer arrays, `source` and `target`, both of length `n`. You are also given an array `allowedSwaps` where each `allowedSwaps[i] = [ai, bi]` indicates that you are allowed to swap the elements at index `ai` and index `bi` **(0-indexed)** of array `source`. Note that you can swap elements at a specifi... | Create a tree structure of the family. Without deaths, the order of inheritance is simply a pre-order traversal of the tree. Mark the dead family members tree nodes and don't include them in the final order. |
Simple DFS | Beats 98% | throne-inheritance | 0 | 1 | ```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.king = kingName\n self.map = {kingName: []}\n self.dead = set()\n\n def birth(self, parentName: str, childName: str) -> None:\n if parentName in self.map:\n self.map[parentName].append(childName)\n ... | 0 | A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.
The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function `Successor(x, curOrder)`, which given a ... | null |
Simple DFS | Beats 98% | throne-inheritance | 0 | 1 | ```\nclass ThroneInheritance:\n\n def __init__(self, kingName: str):\n self.king = kingName\n self.map = {kingName: []}\n self.dead = set()\n\n def birth(self, parentName: str, childName: str) -> None:\n if parentName in self.map:\n self.map[parentName].append(childName)\n ... | 0 | You are given two integer arrays, `source` and `target`, both of length `n`. You are also given an array `allowedSwaps` where each `allowedSwaps[i] = [ai, bi]` indicates that you are allowed to swap the elements at index `ai` and index `bi` **(0-indexed)** of array `source`. Note that you can swap elements at a specifi... | Create a tree structure of the family. Without deaths, the order of inheritance is simply a pre-order traversal of the tree. Mark the dead family members tree nodes and don't include them in the final order. |
Backtracking | C++ | Python | Golang | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Code\n```C++ []\nclass Solution {\npublic:\n int maximumRequests(int n, vector<vector<int>>& requests) {\n int answer = 0;\n vector<int> indegree(n, 0);\n\n function<void(int, int)> maxRequest = [&](int index, int count) {\n if (index == requests.size()) {\n for (int ... | 3 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Backtracking | C++ | Python | Golang | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Code\n```C++ []\nclass Solution {\npublic:\n int maximumRequests(int n, vector<vector<int>>& requests) {\n int answer = 0;\n vector<int> indegree(n, 0);\n\n function<void(int, int)> maxRequest = [&](int index, int count) {\n if (index == requests.size()) {\n for (int ... | 3 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
Python 3 || 5 lines, combinations, w/ explanation || T/M: 91% / 98% | maximum-number-of-achievable-transfer-requests | 0 | 1 | Here\'s how the code works:\n\n1. We use a brute-force approach to find the maximum number of achievable requests (`cnt`). It starts by considering the maximum possible number of requests (`len(requests)`), and decrementing `cnt` until either a solution is found or we exhaust all possibilities.\n\n1. We iterate in reve... | 3 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Python 3 || 5 lines, combinations, w/ explanation || T/M: 91% / 98% | maximum-number-of-achievable-transfer-requests | 0 | 1 | Here\'s how the code works:\n\n1. We use a brute-force approach to find the maximum number of achievable requests (`cnt`). It starts by considering the maximum possible number of requests (`len(requests)`), and decrementing `cnt` until either a solution is found or we exhaust all possibilities.\n\n1. We iterate in reve... | 3 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
EASY PYTHON SOLUTION || BACKTRACKING || DP | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Code\n```\nclass Solution:\n def dp(self,i,lst,requests,n,dct):\n if i<0:\n if lst[:]==[0]*n:\n return 0\n return float("-infinity")\n if (i,tuple(lst)) in dct:\n return dct[(i,tuple(lst))]\n frm=requests[i][0]\n to=requests[i][1]\n ... | 3 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
EASY PYTHON SOLUTION || BACKTRACKING || DP | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Code\n```\nclass Solution:\n def dp(self,i,lst,requests,n,dct):\n if i<0:\n if lst[:]==[0]*n:\n return 0\n return float("-infinity")\n if (i,tuple(lst)) in dct:\n return dct[(i,tuple(lst))]\n frm=requests[i][0]\n to=requests[i][1]\n ... | 3 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
Easy Python Solution, similar to 78. Subsets | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nSimilar approach as Subset, Subset ii\n\nFor each request, we can choose to pick it or not. Once both indegree and outdegree for each building are balanced, we record it and update the maximum request.\n\nI don\'t want to use combination() function du... | 2 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Easy Python Solution, similar to 78. Subsets | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nSimilar approach as Subset, Subset ii\n\nFor each request, we can choose to pick it or not. Once both indegree and outdegree for each building are balanced, we record it and update the maximum request.\n\nI don\'t want to use combination() function du... | 2 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
Python3 Solution | maximum-number-of-achievable-transfer-requests | 0 | 1 | \n```\nclass Solution:\n def maximumRequests(self, n: int, requests: List[List[int]]) -> int:\n l=len(requests)\n for i in range(l,0,-1):\n for j in combinations(requests,i):\n if Counter(x for x ,y in j)==Counter(y for x,y in j):\n return i\n\n retur... | 2 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Python3 Solution | maximum-number-of-achievable-transfer-requests | 0 | 1 | \n```\nclass Solution:\n def maximumRequests(self, n: int, requests: List[List[int]]) -> int:\n l=len(requests)\n for i in range(l,0,-1):\n for j in combinations(requests,i):\n if Counter(x for x ,y in j)==Counter(y for x,y in j):\n return i\n\n retur... | 2 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
Python short and clean. Also a 1-liner. Functional programming. | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Approach\n1. Define a function `is_achievable` which returns `True` if the net change in employees transfer is zero after processing the given `reqs`.\nThis can be computed by, checking if the difference between the counts of `from(u)` and counts of `to(v)` is all zero.\n\n2. Generate the `powerset` of the `requests`... | 2 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Python short and clean. Also a 1-liner. Functional programming. | maximum-number-of-achievable-transfer-requests | 0 | 1 | # Approach\n1. Define a function `is_achievable` which returns `True` if the net change in employees transfer is zero after processing the given `reqs`.\nThis can be computed by, checking if the difference between the counts of `from(u)` and counts of `to(v)` is all zero.\n\n2. Generate the `powerset` of the `requests`... | 2 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
🐍 Combinations.py ---> Python is OP.........🔥 | maximum-number-of-achievable-transfer-requests | 0 | 1 | <h1>DO UPVOTE\uD83D\uDD25\n\n# Approach\nTrying Every Combination\n\n# Complexity\n- Time complexity:\n$$O(2^n)$$ \n\n\n\n\n\n# Code\n```\nclass Solution:\n def maximumRequests(self, n: int, r: List[List[int]]) -> int:\n same=0\n req=[... | 2 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
🐍 Combinations.py ---> Python is OP.........🔥 | maximum-number-of-achievable-transfer-requests | 0 | 1 | <h1>DO UPVOTE\uD83D\uDD25\n\n# Approach\nTrying Every Combination\n\n# Complexity\n- Time complexity:\n$$O(2^n)$$ \n\n\n\n\n\n# Code\n```\nclass Solution:\n def maximumRequests(self, n: int, r: List[List[int]]) -> int:\n same=0\n req=[... | 2 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
✅Back Track🔥 || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | maximum-number-of-achievable-transfer-requests | 1 | 1 | # Intuition:\n\nThe Intuition is to use backtracking approach to explore all possible combinations of taking or not taking transfer requests. It maintains a count of transfer requests and checks if the requests are balanced for each building. The maximum count of transfer requests that satisfies the balanced request co... | 148 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
✅Back Track🔥 || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | maximum-number-of-achievable-transfer-requests | 1 | 1 | # Intuition:\n\nThe Intuition is to use backtracking approach to explore all possible combinations of taking or not taking transfer requests. It maintains a count of transfer requests and checks if the requests are balanced for each building. The maximum count of transfer requests that satisfies the balanced request co... | 148 | You are given an integer array `jobs`, where `jobs[i]` is the amount of time it takes to complete the `ith` job.
There are `k` workers that you can assign jobs to. Each job should be assigned to **exactly** one worker. The **working time** of a worker is the sum of the time it takes to complete all jobs assigned to th... | Think brute force When is a subset of requests okay? |
✅C++|| Java || Python || Solution using Backtracking (faster 80.39%(98 ms), memory 100%(8.6 mb)) | maximum-number-of-achievable-transfer-requests | 1 | 1 | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n\nThe `maximumRequests` function initializes a vector `v` of size `n` with all elements initialized to 0. This vector represents the current state of the buildings. Each element in the vector represents the net change in the number of requests... | 1 | We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to bu... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.