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 |
|---|---|---|---|---|---|---|---|
Python solution in 5 lines | delete-columns-to-make-sorted-iii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is identical to the classic longest non-decreasing subsequence. \nThe problem can be efficiently solved in binary search. \nDue to the small input size, the solution based on the slower DP algorithm can also be accepted. \nTh... | 0 | There are `n` piles of `stones` arranged in a row. The `ith` pile has `stones[i]` stones.
A move consists of merging exactly `k` **consecutive** piles into one pile, and the cost of this move is equal to the total number of stones in these `k` piles.
Return _the minimum cost to merge all piles of stones into one pile... | null |
Python (Simple DP) | delete-columns-to-make-sorted-iii | 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 an array of `n` strings `strs`, all of the same length.
We may choose any deletion indices, and we delete all the characters in those indices for each string.
For example, if we have `strs = [ "abcdef ", "uvwxyz "]` and deletion indices `{0, 2, 3}`, then the final array after deletions is `[ "bef ", "vy... | null |
Python (Simple DP) | delete-columns-to-make-sorted-iii | 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 are `n` piles of `stones` arranged in a row. The `ith` pile has `stones[i]` stones.
A move consists of merging exactly `k` **consecutive** piles into one pile, and the cost of this move is equal to the total number of stones in these `k` piles.
Return _the minimum cost to merge all piles of stones into one pile... | null |
[Python3] top-down dp | delete-columns-to-make-sorted-iii | 0 | 1 | \n```\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n m, n = len(strs), len(strs[0]) # dimensions\n \n @cache \n def fn(k, prev):\n """Return min deleted columns to make sorted."""\n if k == n: return 0 \n ans = 1 + fn(k+1, prev) # ... | 5 | You are given an array of `n` strings `strs`, all of the same length.
We may choose any deletion indices, and we delete all the characters in those indices for each string.
For example, if we have `strs = [ "abcdef ", "uvwxyz "]` and deletion indices `{0, 2, 3}`, then the final array after deletions is `[ "bef ", "vy... | null |
[Python3] top-down dp | delete-columns-to-make-sorted-iii | 0 | 1 | \n```\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n m, n = len(strs), len(strs[0]) # dimensions\n \n @cache \n def fn(k, prev):\n """Return min deleted columns to make sorted."""\n if k == n: return 0 \n ans = 1 + fn(k+1, prev) # ... | 5 | There are `n` piles of `stones` arranged in a row. The `ith` pile has `stones[i]` stones.
A move consists of merging exactly `k` **consecutive** piles into one pile, and the cost of this move is equal to the total number of stones in these `k` piles.
Return _the minimum cost to merge all piles of stones into one pile... | null |
200 ms Solution beats 85 % in runtime only three lines Deadly simple ! | n-repeated-element-in-size-2n-array | 0 | 1 | PLease UPVOTE\n# Code\n```\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n freq=(max(nums)+1)*[0]\n for i in range(len(nums)):freq[nums[i]]+=1\n return freq.index(max(freq))\n``` | 5 | You are given an integer array `nums` with the following properties:
* `nums.length == 2 * n`.
* `nums` contains `n + 1` **unique** elements.
* Exactly one element of `nums` is repeated `n` times.
Return _the element that is repeated_ `n` _times_.
**Example 1:**
**Input:** nums = \[1,2,3,3\]
**Output:** 3
**... | null |
200 ms Solution beats 85 % in runtime only three lines Deadly simple ! | n-repeated-element-in-size-2n-array | 0 | 1 | PLease UPVOTE\n# Code\n```\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n freq=(max(nums)+1)*[0]\n for i in range(len(nums)):freq[nums[i]]+=1\n return freq.index(max(freq))\n``` | 5 | There is a 2D `grid` of size `n x n` where each cell of this grid has a lamp that is initially **turned off**.
You are given a 2D array of lamp positions `lamps`, where `lamps[i] = [rowi, coli]` indicates that the lamp at `grid[rowi][coli]` is **turned on**. Even if the same lamp is listed more than once, it is turned... | null |
1-liner counter ez | n-repeated-element-in-size-2n-array | 0 | 1 | # Code\n```\nfrom collections import Counter\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n return Counter(nums).most_common(1)[0][0]\n``` | 1 | You are given an integer array `nums` with the following properties:
* `nums.length == 2 * n`.
* `nums` contains `n + 1` **unique** elements.
* Exactly one element of `nums` is repeated `n` times.
Return _the element that is repeated_ `n` _times_.
**Example 1:**
**Input:** nums = \[1,2,3,3\]
**Output:** 3
**... | null |
1-liner counter ez | n-repeated-element-in-size-2n-array | 0 | 1 | # Code\n```\nfrom collections import Counter\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n return Counter(nums).most_common(1)[0][0]\n``` | 1 | There is a 2D `grid` of size `n x n` where each cell of this grid has a lamp that is initially **turned off**.
You are given a 2D array of lamp positions `lamps`, where `lamps[i] = [rowi, coli]` indicates that the lamp at `grid[rowi][coli]` is **turned on**. Even if the same lamp is listed more than once, it is turned... | null |
PYTHON 3 : SUPER EASY 99.52% FASTER | n-repeated-element-in-size-2n-array | 0 | 1 | **184 ms, faster than 99.52%** USING LIST\n```\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n \n list1 = []\n for i in nums :\n if i in list1 :\n return i\n else :\n list1.append(i)\n```\n**192 ms, faster than 95.77%** U... | 19 | You are given an integer array `nums` with the following properties:
* `nums.length == 2 * n`.
* `nums` contains `n + 1` **unique** elements.
* Exactly one element of `nums` is repeated `n` times.
Return _the element that is repeated_ `n` _times_.
**Example 1:**
**Input:** nums = \[1,2,3,3\]
**Output:** 3
**... | null |
PYTHON 3 : SUPER EASY 99.52% FASTER | n-repeated-element-in-size-2n-array | 0 | 1 | **184 ms, faster than 99.52%** USING LIST\n```\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n \n list1 = []\n for i in nums :\n if i in list1 :\n return i\n else :\n list1.append(i)\n```\n**192 ms, faster than 95.77%** U... | 19 | There is a 2D `grid` of size `n x n` where each cell of this grid has a lamp that is initially **turned off**.
You are given a 2D array of lamp positions `lamps`, where `lamps[i] = [rowi, coli]` indicates that the lamp at `grid[rowi][coli]` is **turned on**. Even if the same lamp is listed more than once, it is turned... | null |
Solution | n-repeated-element-in-size-2n-array | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& nums)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n map<int, int> count;\n for(int i=0; i<nums.size()/2+2; i++)\n {\n if(count[nums[i]] == 1) return nums[i];\n count[nums[... | 2 | You are given an integer array `nums` with the following properties:
* `nums.length == 2 * n`.
* `nums` contains `n + 1` **unique** elements.
* Exactly one element of `nums` is repeated `n` times.
Return _the element that is repeated_ `n` _times_.
**Example 1:**
**Input:** nums = \[1,2,3,3\]
**Output:** 3
**... | null |
Solution | n-repeated-element-in-size-2n-array | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& nums)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n map<int, int> count;\n for(int i=0; i<nums.size()/2+2; i++)\n {\n if(count[nums[i]] == 1) return nums[i];\n count[nums[... | 2 | There is a 2D `grid` of size `n x n` where each cell of this grid has a lamp that is initially **turned off**.
You are given a 2D array of lamp positions `lamps`, where `lamps[i] = [rowi, coli]` indicates that the lamp at `grid[rowi][coli]` is **turned on**. Even if the same lamp is listed more than once, it is turned... | null |
Solution | maximum-width-ramp | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int maxWidthRamp(vector<int>& a) {\n vector<int>st;\n int n=a.size(),ans=0;\n for(int i=0;i<n;i++){\n while(st.empty()||a[st.back()]>a[i]){\n st.push_back(i);\n }\n }\n for(int i=n-1;i>=0;i--){\n ... | 2 | A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`.
**Example 1:**
**Input:** nums = \[6,0,8,2,1,... | null |
Solution | maximum-width-ramp | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int maxWidthRamp(vector<int>& a) {\n vector<int>st;\n int n=a.size(),ans=0;\n for(int i=0;i<n;i++){\n while(st.empty()||a[st.back()]>a[i]){\n st.push_back(i);\n }\n }\n for(int i=n-1;i>=0;i--){\n ... | 2 | Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.
**Example 1:**
**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]
**Example 2:**
**Input:** words = \["cool"... | null |
Python easy to read and understand | stack | maximum-width-ramp | 0 | 1 | ```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n stack = []\n n = len(nums)\n for i in range(n):\n if not stack or nums[stack[-1]] > nums[i]:\n stack.append(i)\n ans = 0\n for i in range(n-1, -1, -1):\n while stack and nu... | 2 | A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`.
**Example 1:**
**Input:** nums = \[6,0,8,2,1,... | null |
Python easy to read and understand | stack | maximum-width-ramp | 0 | 1 | ```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n stack = []\n n = len(nums)\n for i in range(n):\n if not stack or nums[stack[-1]] > nums[i]:\n stack.append(i)\n ans = 0\n for i in range(n-1, -1, -1):\n while stack and nu... | 2 | Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.
**Example 1:**
**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]
**Example 2:**
**Input:** words = \["cool"... | null |
[Python3] binary search O(NlogN) & stack O(N) | maximum-width-ramp | 0 | 1 | **Approach 1 - binary search**\nKeep a decreasing stack and binary search the number smaller than or equal to the current one. \n\nImplementation\n```\nclass Solution:\n def maxWidthRamp(self, A: List[int]) -> int:\n ans = 0\n stack = []\n for i in range(len(A)): \n if not stack or A[... | 10 | A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`.
**Example 1:**
**Input:** nums = \[6,0,8,2,1,... | null |
[Python3] binary search O(NlogN) & stack O(N) | maximum-width-ramp | 0 | 1 | **Approach 1 - binary search**\nKeep a decreasing stack and binary search the number smaller than or equal to the current one. \n\nImplementation\n```\nclass Solution:\n def maxWidthRamp(self, A: List[int]) -> int:\n ans = 0\n stack = []\n for i in range(len(A)): \n if not stack or A[... | 10 | Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.
**Example 1:**
**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]
**Example 2:**
**Input:** words = \["cool"... | null |
Easy Python Solution | maximum-width-ramp | 0 | 1 | # Code\n```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n stack = []\n\n for i in range(len(nums)):\n if not stack or nums[i] < nums[stack[-1]]:\n stack.append(i)\n \n answer = 0\n\n for i in range(len(nums) - 1, -1, -1):\n ... | 0 | A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`.
**Example 1:**
**Input:** nums = \[6,0,8,2,1,... | null |
Easy Python Solution | maximum-width-ramp | 0 | 1 | # Code\n```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n stack = []\n\n for i in range(len(nums)):\n if not stack or nums[i] < nums[stack[-1]]:\n stack.append(i)\n \n answer = 0\n\n for i in range(len(nums) - 1, -1, -1):\n ... | 0 | Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.
**Example 1:**
**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]
**Example 2:**
**Input:** words = \["cool"... | null |
Sliding Window Solution | maximum-width-ramp | 0 | 1 | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n min_arr = [nums[0]] * len(nums)\n for i in range(1, len(nums)):\n min_arr[i] = min(nums[i], min_arr[i - 1])\n max_arr = [nums... | 0 | A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`.
**Example 1:**
**Input:** nums = \[6,0,8,2,1,... | null |
Sliding Window Solution | maximum-width-ramp | 0 | 1 | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n min_arr = [nums[0]] * len(nums)\n for i in range(1, len(nums)):\n min_arr[i] = min(nums[i], min_arr[i - 1])\n max_arr = [nums... | 0 | Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.
**Example 1:**
**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]
**Example 2:**
**Input:** words = \["cool"... | null |
Solution | minimum-area-rectangle-ii | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n double minAreaFreeRect(vector<vector<int>>& points) {\n double _Area, minArea = 0.0;\n if (points.size() < 4){\n return 0;\n }\n int x0, y0;\n int x1, y1;\n int x2, y2;\n int x3, y3;\n int Lx1, Ly1;\n int... | 1 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
Solution | minimum-area-rectangle-ii | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n double minAreaFreeRect(vector<vector<int>>& points) {\n double _Area, minArea = 0.0;\n if (points.size() < 4){\n return 0;\n }\n int x0, y0;\n int x1, y1;\n int x2, y2;\n int x3, y3;\n int Lx1, Ly1;\n int... | 1 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
[Python3] center point O(N^2) | minimum-area-rectangle-ii | 0 | 1 | **Algo**\nUse a 2-layer nested loops to scan through pair of points `(x0, y0)` and `(x1, y1)`. The key features extracted from this pair are center and length `(cx, cy, d2)`. Those points with the same center and length form rectangles. \n\n**Implementation**\n```\nclass Solution:\n def minAreaFreeRect(self, points:... | 30 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
[Python3] center point O(N^2) | minimum-area-rectangle-ii | 0 | 1 | **Algo**\nUse a 2-layer nested loops to scan through pair of points `(x0, y0)` and `(x1, y1)`. The key features extracted from this pair are center and length `(cx, cy, d2)`. Those points with the same center and length form rectangles. \n\n**Implementation**\n```\nclass Solution:\n def minAreaFreeRect(self, points:... | 30 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
Python 76%+ | Quick Search for Diamond, Determine Rectangle by Diagonal Distances | minimum-area-rectangle-ii | 0 | 1 | ```python\ndef dist_pow2(x1, y1, x2, y2): return (x2 - x1)**2 + (y2 - y1)**2\ndef dist(x1, y1, x2, y2): return dist_pow2(x1, y1, x2, y2)**0.5\n\nclass Solution:\n def minAreaFreeRect(self, points):\n L, m = len(points), float(\'inf\')\n\n quick_search = {(x, y) for x, y in points}\n\n for i in r... | 3 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
Python 76%+ | Quick Search for Diamond, Determine Rectangle by Diagonal Distances | minimum-area-rectangle-ii | 0 | 1 | ```python\ndef dist_pow2(x1, y1, x2, y2): return (x2 - x1)**2 + (y2 - y1)**2\ndef dist(x1, y1, x2, y2): return dist_pow2(x1, y1, x2, y2)**0.5\n\nclass Solution:\n def minAreaFreeRect(self, points):\n L, m = len(points), float(\'inf\')\n\n quick_search = {(x, y) for x, y in points}\n\n for i in r... | 3 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
Linear Algebra Review Problem | Commented and Explained | Graduate Level | minimum-area-rectangle-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a linear algebra problem. As such, I decided to finally implement some parts of my much needed personal linear algebra library of lambda functions, which I showcase here. These come up in a variety of problems as linear algebra is... | 0 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
Linear Algebra Review Problem | Commented and Explained | Graduate Level | minimum-area-rectangle-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a linear algebra problem. As such, I decided to finally implement some parts of my much needed personal linear algebra library of lambda functions, which I showcase here. These come up in a variety of problems as linear algebra is... | 0 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
O(n^3) worst case python solution by finding parallel vectors and right angle corners | minimum-area-rectangle-ii | 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 an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
O(n^3) worst case python solution by finding parallel vectors and right angle corners | minimum-area-rectangle-ii | 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`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
Python Concise explained solution || Dhruv Vavliya | minimum-area-rectangle-ii | 0 | 1 | ```\n# written by : Dhruv Vavliya\n\n\'\'\'\nthe distance between point1 and point2 equals the distance between point3 and point4\nthe midpoint of point1 and point2 equals the midpoint of point3 and point4.\n\'\'\'\n\npoints =[[2,4],[4,2],[1,0],[3,4],[4,4],[2,2],[1,1],[3,0],[1,4],[0,3],[0,1],[2,1],[4,0]]\n\n\ndef rect_... | 2 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
Python Concise explained solution || Dhruv Vavliya | minimum-area-rectangle-ii | 0 | 1 | ```\n# written by : Dhruv Vavliya\n\n\'\'\'\nthe distance between point1 and point2 equals the distance between point3 and point4\nthe midpoint of point1 and point2 equals the midpoint of point3 and point4.\n\'\'\'\n\npoints =[[2,4],[4,2],[1,0],[3,4],[4,4],[2,2],[1,1],[3,0],[1,4],[0,3],[0,1],[2,1],[4,0]]\n\n\ndef rect_... | 2 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
Clean Python | Iterative Centers | minimum-area-rectangle-ii | 0 | 1 | **Clean Python | Iterative Centers**\n\n```\nclass Solution:\n Inf = float(\'inf\')\n def minAreaFreeRect(self, A):\n #\n L = len(A)\n res = self.Inf\n sqrt = math.sqrt\n #\n dist = lambda x1,y1,x2,y2: sqrt( (x2-x1)**2 + (y2-y1)**2 )\n D = defaultdict(list)\... | 1 | You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.
Return _the minimum area of any rectangle formed from these points, with sides **not necessarily parallel** to the X and Y axes_. If there is not any such rectangle, return `0`.
Answers within `10-5` of the actual answer will... | null |
Clean Python | Iterative Centers | minimum-area-rectangle-ii | 0 | 1 | **Clean Python | Iterative Centers**\n\n```\nclass Solution:\n Inf = float(\'inf\')\n def minAreaFreeRect(self, A):\n #\n L = len(A)\n res = self.Inf\n sqrt = math.sqrt\n #\n dist = lambda x1,y1,x2,y2: sqrt( (x2-x1)**2 + (y2-y1)**2 )\n D = defaultdict(list)\... | 1 | Given a string `s`, determine if it is **valid**.
A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**:
* Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab... | null |
Solution | least-operators-to-express-number | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int leastOpsExpressTarget(int x, int target) {\n int r = target%x, c = x - r;\n int nr = min(2*r, 1 + 2*(x - r));\n int nc = min(2*c, 1 + 2*(x-c));\n return min(nr + dfs(target - r, x), nc + dfs(target + c, x)) - 1;\n }\nprivate:\n unordered_ma... | 2 | Given a single positive integer `x`, we will write an expression of the form `x (op1) x (op2) x (op3) x ...` where each operator `op1`, `op2`, etc. is either addition, subtraction, multiplication, or division (`+`, `-`, `*`, or `/)`. For example, with `x = 3`, we might write `3 * 3 / 3 + 3 - 3` which is a value of 3.
... | null |
Solution | least-operators-to-express-number | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int leastOpsExpressTarget(int x, int target) {\n int r = target%x, c = x - r;\n int nr = min(2*r, 1 + 2*(x - r));\n int nc = min(2*c, 1 + 2*(x-c));\n return min(nr + dfs(target - r, x), nc + dfs(target + c, x)) - 1;\n }\nprivate:\n unordered_ma... | 2 | Given a binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Explanation:** \[1,1,1,0,0,**1**,1,1,1,1,**1**\]
Bolded numbers were flipped from 0 to 1.... | null |
[Python3] top-down dp | least-operators-to-express-number | 0 | 1 | \n```\nclass Solution:\n def leastOpsExpressTarget(self, x: int, target: int) -> int:\n \n @cache\n def fn(val): \n """Return min ops to express val."""\n if val < x: return min(2*val-1, 2*(x-val))\n k = int(log(val)//log(x))\n ans = k + fn(val - x**k)... | 4 | Given a single positive integer `x`, we will write an expression of the form `x (op1) x (op2) x (op3) x ...` where each operator `op1`, `op2`, etc. is either addition, subtraction, multiplication, or division (`+`, `-`, `*`, or `/)`. For example, with `x = 3`, we might write `3 * 3 / 3 + 3 - 3` which is a value of 3.
... | null |
[Python3] top-down dp | least-operators-to-express-number | 0 | 1 | \n```\nclass Solution:\n def leastOpsExpressTarget(self, x: int, target: int) -> int:\n \n @cache\n def fn(val): \n """Return min ops to express val."""\n if val < x: return min(2*val-1, 2*(x-val))\n k = int(log(val)//log(x))\n ans = k + fn(val - x**k)... | 4 | Given a binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Explanation:** \[1,1,1,0,0,**1**,1,1,1,1,**1**\]
Bolded numbers were flipped from 0 to 1.... | null |
Python heapq beats 80% time/space | least-operators-to-express-number | 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 single positive integer `x`, we will write an expression of the form `x (op1) x (op2) x (op3) x ...` where each operator `op1`, `op2`, etc. is either addition, subtraction, multiplication, or division (`+`, `-`, `*`, or `/)`. For example, with `x = 3`, we might write `3 * 3 / 3 + 3 - 3` which is a value of 3.
... | null |
Python heapq beats 80% time/space | least-operators-to-express-number | 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 binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Explanation:** \[1,1,1,0,0,**1**,1,1,1,1,**1**\]
Bolded numbers were flipped from 0 to 1.... | null |
PYTHON SOL || RECURSION + MEMOIZATION || WELL EXPLAINED || APPROACH EXPLAINED || WELL COMMENTED || | least-operators-to-express-number | 0 | 1 | # EXPLANATION\n```\nSay number = x and target = target\n\nWhen target == 1: we can make it by using only one way i.e. x/x\nNow we start with our current value cur = x\n\nNow fastest way to reach the target is via multplication\n\t\tExample x = 5 target = 125\n\t\tWhat is the fastest way to reach 125 with x = 5 and oper... | 3 | Given a single positive integer `x`, we will write an expression of the form `x (op1) x (op2) x (op3) x ...` where each operator `op1`, `op2`, etc. is either addition, subtraction, multiplication, or division (`+`, `-`, `*`, or `/)`. For example, with `x = 3`, we might write `3 * 3 / 3 + 3 - 3` which is a value of 3.
... | null |
PYTHON SOL || RECURSION + MEMOIZATION || WELL EXPLAINED || APPROACH EXPLAINED || WELL COMMENTED || | least-operators-to-express-number | 0 | 1 | # EXPLANATION\n```\nSay number = x and target = target\n\nWhen target == 1: we can make it by using only one way i.e. x/x\nNow we start with our current value cur = x\n\nNow fastest way to reach the target is via multplication\n\t\tExample x = 5 target = 125\n\t\tWhat is the fastest way to reach 125 with x = 5 and oper... | 3 | Given a binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Explanation:** \[1,1,1,0,0,**1**,1,1,1,1,**1**\]
Bolded numbers were flipped from 0 to 1.... | null |
Python || wow ! what's a Problem || conceptual solution with explanation | least-operators-to-express-number | 1 | 1 | ```\n# written by : Dhruv vavliya\n\nx = 5\ntarget = 501\n\nfrom functools import lru_cache\n@lru_cache(None)\ndef go(x,target):\n if target == 1:\n return 1 # 5/5 (only 1 possible soln)\n\n op =0\n current=x\n while current < target:\n current*=x ... | 1 | Given a single positive integer `x`, we will write an expression of the form `x (op1) x (op2) x (op3) x ...` where each operator `op1`, `op2`, etc. is either addition, subtraction, multiplication, or division (`+`, `-`, `*`, or `/)`. For example, with `x = 3`, we might write `3 * 3 / 3 + 3 - 3` which is a value of 3.
... | null |
Python || wow ! what's a Problem || conceptual solution with explanation | least-operators-to-express-number | 1 | 1 | ```\n# written by : Dhruv vavliya\n\nx = 5\ntarget = 501\n\nfrom functools import lru_cache\n@lru_cache(None)\ndef go(x,target):\n if target == 1:\n return 1 # 5/5 (only 1 possible soln)\n\n op =0\n current=x\n while current < target:\n current*=x ... | 1 | Given a binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Explanation:** \[1,1,1,0,0,**1**,1,1,1,1,**1**\]
Bolded numbers were flipped from 0 to 1.... | null |
Solution | univalued-binary-tree | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n bool isUnivalTree(TreeNode* root) {\n if(root==NULL)\n return true;\n if(root->left == NULL && root->right == NULL)\n return true;\n bool left = isUnivalTree(root->left);\n bool right = isUnivalTree(root->right);\n bool c... | 1 | A binary tree is **uni-valued** if every node in the tree has the same value.
Given the `root` of a binary tree, return `true` _if the given tree is **uni-valued**, or_ `false` _otherwise._
**Example 1:**
**Input:** root = \[1,1,1,1,1,null,1\]
**Output:** true
**Example 2:**
**Input:** root = \[2,2,2,5,2\]
**Outpu... | null |
Solution | univalued-binary-tree | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n bool isUnivalTree(TreeNode* root) {\n if(root==NULL)\n return true;\n if(root->left == NULL && root->right == NULL)\n return true;\n bool left = isUnivalTree(root->left);\n bool right = isUnivalTree(root->right);\n bool c... | 1 | Given an integer array `nums` and an integer `k`, modify the array in the following way:
* choose an index `i` and replace `nums[i]` with `-nums[i]`.
You should apply this process exactly `k` times. You may choose the same index `i` multiple times.
Return _the largest possible sum of the array after modifying it i... | null |
Recursive Approach | univalued-binary-tree | 0 | 1 | \n\n# 1. Recursive Approach\n```\nclass Solution:\n def isUnivalTree(self, root: Optional[TreeNode]) -> bool:\n def unique(root,x):\n if not root:\n return True\n if root.val!=x:\n return False\n return unique(root.left,x) and unique(root.right,x)... | 5 | A binary tree is **uni-valued** if every node in the tree has the same value.
Given the `root` of a binary tree, return `true` _if the given tree is **uni-valued**, or_ `false` _otherwise._
**Example 1:**
**Input:** root = \[1,1,1,1,1,null,1\]
**Output:** true
**Example 2:**
**Input:** root = \[2,2,2,5,2\]
**Outpu... | null |
Recursive Approach | univalued-binary-tree | 0 | 1 | \n\n# 1. Recursive Approach\n```\nclass Solution:\n def isUnivalTree(self, root: Optional[TreeNode]) -> bool:\n def unique(root,x):\n if not root:\n return True\n if root.val!=x:\n return False\n return unique(root.left,x) and unique(root.right,x)... | 5 | Given an integer array `nums` and an integer `k`, modify the array in the following way:
* choose an index `i` and replace `nums[i]` with `-nums[i]`.
You should apply this process exactly `k` times. You may choose the same index `i` multiple times.
Return _the largest possible sum of the array after modifying it i... | null |
Python || Easy To Understand || Inorder Traversal 🔥 | univalued-binary-tree | 0 | 1 | # Code\n```\nclass Solution:\n def isUnivalTree(self, root: Optional[TreeNode]) -> bool:\n val = root.val\n def inorder(root, val):\n if root is None: return True\n if root.val != val: return False\n return inorder(root.left, val) and inorder(root.right, val)\n r... | 3 | A binary tree is **uni-valued** if every node in the tree has the same value.
Given the `root` of a binary tree, return `true` _if the given tree is **uni-valued**, or_ `false` _otherwise._
**Example 1:**
**Input:** root = \[1,1,1,1,1,null,1\]
**Output:** true
**Example 2:**
**Input:** root = \[2,2,2,5,2\]
**Outpu... | null |
Python || Easy To Understand || Inorder Traversal 🔥 | univalued-binary-tree | 0 | 1 | # Code\n```\nclass Solution:\n def isUnivalTree(self, root: Optional[TreeNode]) -> bool:\n val = root.val\n def inorder(root, val):\n if root is None: return True\n if root.val != val: return False\n return inorder(root.left, val) and inorder(root.right, val)\n r... | 3 | Given an integer array `nums` and an integer `k`, modify the array in the following way:
* choose an index `i` and replace `nums[i]` with `-nums[i]`.
You should apply this process exactly `k` times. You may choose the same index `i` multiple times.
Return _the largest possible sum of the array after modifying it i... | null |
Python 3 || 14 lines, w/ comments || T/M: 95% / 74% | vowel-spellchecker | 0 | 1 | ```\nclass Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:\n\n f = lambda x: \'\'.join(\'$\' if ch in \'aeiou\' else ch for ch in x)\n cap, vow = defaultdict(str), defaultdict(str)\n word_set, ans = set(wordlist), []\n \n for w in wordlist:... | 3 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
Python 3 || 14 lines, w/ comments || T/M: 95% / 74% | vowel-spellchecker | 0 | 1 | ```\nclass Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:\n\n f = lambda x: \'\'.join(\'$\' if ch in \'aeiou\' else ch for ch in x)\n cap, vow = defaultdict(str), defaultdict(str)\n word_set, ans = set(wordlist), []\n \n for w in wordlist:... | 3 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
Solution | vowel-spellchecker | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {\n unordered_set<string> exact;\n unordered_map<string, string> cap, vow;\n \n for(string &s : wordlist){\n exact.insert(s);\n string s2 = s;\n ... | 1 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
Solution | vowel-spellchecker | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {\n unordered_set<string> exact;\n unordered_map<string, string> cap, vow;\n \n for(string &s : wordlist){\n exact.insert(s);\n string s2 = s;\n ... | 1 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
[Python] One Case At A Time | vowel-spellchecker | 0 | 1 | **Approach:**\n\nThere are 4 possible scenarios for each word, we can try them in order of priority:\n1. The word matches a word in `wordlist`\nCreating a set of `wordlist` allows us to check if this is true in O(1) time.\n\n2. The word matches a word in `wordlist` up to capitalization.\nConvert the word to lowercase l... | 5 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
[Python] One Case At A Time | vowel-spellchecker | 0 | 1 | **Approach:**\n\nThere are 4 possible scenarios for each word, we can try them in order of priority:\n1. The word matches a word in `wordlist`\nCreating a set of `wordlist` allows us to check if this is true in O(1) time.\n\n2. The word matches a word in `wordlist` up to capitalization.\nConvert the word to lowercase l... | 5 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
[Python3] Good enough | vowel-spellchecker | 0 | 1 | ``` Python3 []\nclass Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:\n seen = set()\n lower = {}\n mapping = {}\n final = []\n\n def convert(word: str) -> Tuple[str]:\n word = list(word.lower())\n\n for i in range(len... | 0 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
[Python3] Good enough | vowel-spellchecker | 0 | 1 | ``` Python3 []\nclass Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:\n seen = set()\n lower = {}\n mapping = {}\n final = []\n\n def convert(word: str) -> Tuple[str]:\n word = list(word.lower())\n\n for i in range(len... | 0 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
Logical Elimination For Speed Up | Commented and Explained | vowel-spellchecker | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe set of all unique words in wordlist is a subset of all words in wordlist\nThe set of all lower unique words in wordlist is a subset of all unique words in word list \nThe set of all decapitalized and devoweled lower unique words in wo... | 0 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
Logical Elimination For Speed Up | Commented and Explained | vowel-spellchecker | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe set of all unique words in wordlist is a subset of all words in wordlist\nThe set of all lower unique words in wordlist is a subset of all unique words in word list \nThe set of all decapitalized and devoweled lower unique words in wo... | 0 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
[Python] Three dictionary to match the word; Explained | vowel-spellchecker | 0 | 1 | Dictionary 1 record the original form of word in the list, It is used for exactly matching;\n\nDictionary 2 record the lower case form of words in the list, only the location of the first word with the same lower cases form is recorded. It is for lower case matching;\n\nDictionary 3 record the word with vowel replaced ... | 0 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
[Python] Three dictionary to match the word; Explained | vowel-spellchecker | 0 | 1 | Dictionary 1 record the original form of word in the list, It is used for exactly matching;\n\nDictionary 2 record the lower case form of words in the list, only the location of the first word with the same lower cases form is recorded. It is for lower case matching;\n\nDictionary 3 record the word with vowel replaced ... | 0 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
[Python3] simple solution | vowel-spellchecker | 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$$O(n + m)$$\n- $$n$$ is wordlist length\n- $$m$$ is queries length\n\n- Spa... | 0 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
[Python3] simple solution | vowel-spellchecker | 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$$O(n + m)$$\n- $$n$$ is wordlist length\n- $$m$$ is queries length\n\n- Spa... | 0 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
[Python3] - Readable and Commented Hashmap Solution | vowel-spellchecker | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to identify the priority of the rules and also how to quickly check them.\n\nFor me the most complicated one was: check whether vowel replacement has a match in our wordlist.\n# Approach\n<!-- Describe your approach to solving the... | 0 | Given a `wordlist`, we want to implement a spellchecker that converts a query word into a correct word.
For a given `query` word, the spell checker handles two categories of spelling mistakes:
* Capitalization: If the query matches a word in the wordlist (**case-insensitive**), then the query word is returned with ... | null |
[Python3] - Readable and Commented Hashmap Solution | vowel-spellchecker | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to identify the priority of the rules and also how to quickly check them.\n\nFor me the most complicated one was: check whether vowel replacement has a match in our wordlist.\n# Approach\n<!-- Describe your approach to solving the... | 0 | The **factorial** of a positive integer `n` is the product of all positive integers less than or equal to `n`.
* For example, `factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1`.
We make a **clumsy factorial** using the integers in decreasing order by swapping out the multiply operations for a fixed rotation o... | null |
Solution | numbers-with-same-consecutive-differences | 1 | 1 | ```C++ []\nclass Solution {\n public:\n vector<int> numsSameConsecDiff(int n, int k) {\n if (n == 1)\n return {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n\n vector<int> ans;\n\n if (k == 0) {\n for (char c = \'1\'; c <= \'9\'; ++c)\n ans.push_back(stoi(string(n, c)));\n return ans;\n }\n\n fo... | 1 | Given two integers n and k, return _an array of all the integers of length_ `n` _where the difference between every two consecutive digits is_ `k`. You may return the answer in **any order**.
Note that the integers should not have leading zeros. Integers as `02` and `043` are not allowed.
**Example 1:**
**Input:** n... | null |
Solution | numbers-with-same-consecutive-differences | 1 | 1 | ```C++ []\nclass Solution {\n public:\n vector<int> numsSameConsecDiff(int n, int k) {\n if (n == 1)\n return {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n\n vector<int> ans;\n\n if (k == 0) {\n for (char c = \'1\'; c <= \'9\'; ++c)\n ans.push_back(stoi(string(n, c)));\n return ans;\n }\n\n fo... | 1 | In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values.
Return the minimum number of rotations so that all... | null |
🔥 [LeetCode The Hard Way]🔥 Easy BFS 100% Explained Line By Line | numbers-with-same-consecutive-differences | 0 | 1 | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. I\'ll explain my solution line by line daily. \nIf you like it, please give a star, watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way) and upvote this ... | 70 | Given two integers n and k, return _an array of all the integers of length_ `n` _where the difference between every two consecutive digits is_ `k`. You may return the answer in **any order**.
Note that the integers should not have leading zeros. Integers as `02` and `043` are not allowed.
**Example 1:**
**Input:** n... | null |
🔥 [LeetCode The Hard Way]🔥 Easy BFS 100% Explained Line By Line | numbers-with-same-consecutive-differences | 0 | 1 | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. I\'ll explain my solution line by line daily. \nIf you like it, please give a star, watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way) and upvote this ... | 70 | In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values.
Return the minimum number of rotations so that all... | null |
🔥44ms PYTHON 91% Faster 93% Memory Efficient Solution MULTIPLE APPROACHES 🔥 | numbers-with-same-consecutive-differences | 0 | 1 | # DON\'T FORGET TO UPVOTE\n# 1. 91% faster\n\n\tclass Solution:\n\t\tdef numsSameConsecDiff(self, n: int, k: int) -> List[int]:\n\t\t\tgraph = defaultdict(list)\n\t\t\tfor i in range(0, 10):\n\t\t\t\tif i-k >= 0:\n\t\t\t\t\tgraph[i].append(i-k)\n\t\t\t\tif i +k < 10:\n\t\t\t\t\tgraph[i].append(i+k)\n\t\t\tstart = [i fo... | 5 | Given two integers n and k, return _an array of all the integers of length_ `n` _where the difference between every two consecutive digits is_ `k`. You may return the answer in **any order**.
Note that the integers should not have leading zeros. Integers as `02` and `043` are not allowed.
**Example 1:**
**Input:** n... | null |
🔥44ms PYTHON 91% Faster 93% Memory Efficient Solution MULTIPLE APPROACHES 🔥 | numbers-with-same-consecutive-differences | 0 | 1 | # DON\'T FORGET TO UPVOTE\n# 1. 91% faster\n\n\tclass Solution:\n\t\tdef numsSameConsecDiff(self, n: int, k: int) -> List[int]:\n\t\t\tgraph = defaultdict(list)\n\t\t\tfor i in range(0, 10):\n\t\t\t\tif i-k >= 0:\n\t\t\t\t\tgraph[i].append(i-k)\n\t\t\t\tif i +k < 10:\n\t\t\t\t\tgraph[i].append(i+k)\n\t\t\tstart = [i fo... | 5 | In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values.
Return the minimum number of rotations so that all... | null |
Python Elegant & Short | DFS + BFS | numbers-with-same-consecutive-differences | 0 | 1 | ## DFS solution\n\n\tfrom typing import Generator, List\n\n\n\tclass Solution:\n\t\t"""\n\t\tTime: O(2^n)\n\t\tMemory: O(2^n)\n\t\t"""\n\n\t\tdef numsSameConsecDiff(self, n: int, k: int) -> List[int]:\n\t\t\tif n == 1:\n\t\t\t\treturn [i for i in range(10)]\n\t\t\treturn [num for digit in range(1, 10) for num in self... | 2 | Given two integers n and k, return _an array of all the integers of length_ `n` _where the difference between every two consecutive digits is_ `k`. You may return the answer in **any order**.
Note that the integers should not have leading zeros. Integers as `02` and `043` are not allowed.
**Example 1:**
**Input:** n... | null |
Python Elegant & Short | DFS + BFS | numbers-with-same-consecutive-differences | 0 | 1 | ## DFS solution\n\n\tfrom typing import Generator, List\n\n\n\tclass Solution:\n\t\t"""\n\t\tTime: O(2^n)\n\t\tMemory: O(2^n)\n\t\t"""\n\n\t\tdef numsSameConsecDiff(self, n: int, k: int) -> List[int]:\n\t\t\tif n == 1:\n\t\t\t\treturn [i for i in range(10)]\n\t\t\treturn [num for digit in range(1, 10) for num in self... | 2 | In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values.
Return the minimum number of rotations so that all... | null |
Python3 || 46 ms, faster than 91.39% of Python3 || Clean and Easy to Understand | binary-tree-cameras | 0 | 1 | ```\ndef minCameraCover(self, root: Optional[TreeNode]) -> int:\n self.output = 0\n def dfs(node):\n #camera monitor\n if not node:\n return False,True\n c1, m1 = dfs(node.left)\n c2, m2 = dfs(node.right)\n camera = False\n m... | 1 | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
Return _the minimum number of cameras needed to monitor all nodes of the tree_.
**Example 1:**
**Input:** root = \[0,0,null,0,0\]
**Output:** 1
**Exp... | null |
Python3 || 46 ms, faster than 91.39% of Python3 || Clean and Easy to Understand | binary-tree-cameras | 0 | 1 | ```\ndef minCameraCover(self, root: Optional[TreeNode]) -> int:\n self.output = 0\n def dfs(node):\n #camera monitor\n if not node:\n return False,True\n c1, m1 = dfs(node.left)\n c2, m2 = dfs(node.right)\n camera = False\n m... | 1 | Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_.
It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases.
A **binary search tr... | null |
[Python] Making a Hard Problem Easy! Postorder Traversal with Explanation | binary-tree-cameras | 0 | 1 | ### Introduction\n\nGiven a binary tree, we want to place some cameras on some of the nodes in the tree such that all nodes in the tree are monitored by at least one camera.\n\n---\n\n### Intuition\n\nConsider the following binary tree. Where would you place cameras such that the least number of cameras are used to mon... | 54 | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
Return _the minimum number of cameras needed to monitor all nodes of the tree_.
**Example 1:**
**Input:** root = \[0,0,null,0,0\]
**Output:** 1
**Exp... | null |
[Python] Making a Hard Problem Easy! Postorder Traversal with Explanation | binary-tree-cameras | 0 | 1 | ### Introduction\n\nGiven a binary tree, we want to place some cameras on some of the nodes in the tree such that all nodes in the tree are monitored by at least one camera.\n\n---\n\n### Intuition\n\nConsider the following binary tree. Where would you place cameras such that the least number of cameras are used to mon... | 54 | Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_.
It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases.
A **binary search tr... | null |
✔️ PYTHON || EXPLAINED || ;] | binary-tree-cameras | 0 | 1 | **UPVOTE IF HELPFuuL**\n \n* The root of the tree can be covered by left child, or right child, or itself.\n* One leaf of the tree can be covered by its parent or by itself.\n\n* A camera at the leaf, the camera can cover the leaf and its parent.\n* A camera at its parent, the camera can cover the leaf, its parent and ... | 8 | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
Return _the minimum number of cameras needed to monitor all nodes of the tree_.
**Example 1:**
**Input:** root = \[0,0,null,0,0\]
**Output:** 1
**Exp... | null |
✔️ PYTHON || EXPLAINED || ;] | binary-tree-cameras | 0 | 1 | **UPVOTE IF HELPFuuL**\n \n* The root of the tree can be covered by left child, or right child, or itself.\n* One leaf of the tree can be covered by its parent or by itself.\n\n* A camera at the leaf, the camera can cover the leaf and its parent.\n* A camera at its parent, the camera can cover the leaf, its parent and ... | 8 | Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_.
It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases.
A **binary search tr... | null |
📌 Python3 DFS solution | binary-tree-cameras | 0 | 1 | ```\nclass Solution(object):\n def minCameraCover(self, root):\n result = [0]\n \n # 0 indicates that it doesn\'t need cam which might be a leaf node or a parent node which is already covered\n # < 3 indicates that it has already covered\n # >= 3 indicates that it needs a cam\n ... | 5 | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
Return _the minimum number of cameras needed to monitor all nodes of the tree_.
**Example 1:**
**Input:** root = \[0,0,null,0,0\]
**Output:** 1
**Exp... | null |
📌 Python3 DFS solution | binary-tree-cameras | 0 | 1 | ```\nclass Solution(object):\n def minCameraCover(self, root):\n result = [0]\n \n # 0 indicates that it doesn\'t need cam which might be a leaf node or a parent node which is already covered\n # < 3 indicates that it has already covered\n # >= 3 indicates that it needs a cam\n ... | 5 | Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_.
It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases.
A **binary search tr... | null |
✅ Python Easy Postorder with explanation | binary-tree-cameras | 0 | 1 | For this problem, we first need to identify which tree traversal should be used(top down or bottom up). \n\nLet\'s take the following example, \n```\n\t A\n\t/ \\\n B C\n / \\ / \\\n D E F G\n```\n\nIf we go with top-down approach, we will start installing the cameras from root node `A`. So if we do tha... | 19 | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
Return _the minimum number of cameras needed to monitor all nodes of the tree_.
**Example 1:**
**Input:** root = \[0,0,null,0,0\]
**Output:** 1
**Exp... | null |
✅ Python Easy Postorder with explanation | binary-tree-cameras | 0 | 1 | For this problem, we first need to identify which tree traversal should be used(top down or bottom up). \n\nLet\'s take the following example, \n```\n\t A\n\t/ \\\n B C\n / \\ / \\\n D E F G\n```\n\nIf we go with top-down approach, we will start installing the cameras from root node `A`. So if we do tha... | 19 | Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_.
It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases.
A **binary search tr... | null |
Solution | pancake-sorting | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<int> pancakeSort(vector<int>& arr) {\n vector<int>res;\n for(int i=0;i<arr.size();i++)\n {\n auto mx = max_element(arr.begin(),arr.end()-i);\n\n auto pos = find(arr.begin(),arr.end()-i,*mx);\n\n if((*mx)==pos-arr.begi... | 2 | Given an array of integers `arr`, sort the array by performing a series of **pancake flips**.
In one pancake flip we do the following steps:
* Choose an integer `k` where `1 <= k <= arr.length`.
* Reverse the sub-array `arr[0...k-1]` (**0-indexed**).
For example, if `arr = [3,2,1,4]` and we performed a pancake f... | null |
Solution | pancake-sorting | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<int> pancakeSort(vector<int>& arr) {\n vector<int>res;\n for(int i=0;i<arr.size();i++)\n {\n auto mx = max_element(arr.begin(),arr.end()-i);\n\n auto pos = find(arr.begin(),arr.end()-i,*mx);\n\n if((*mx)==pos-arr.begi... | 2 | The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation.
* For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`.
Given an integer `n`, return _its complement_.
**Ex... | null |
Simple python 🐍 solution with comments beats 99% time | pancake-sorting | 0 | 1 | Idea is i put the maximum element at index 0, then flip the whole array to make the max at the **end**, and keep repeating \n\nTime O(n^2) { (reversed is O(n) + index is O(n) + max is O(n)) * while O(n) = O(n^2) }\n```\nclass Solution:\n def pancakeSort(self, A: List[int]) -> List[int]:\n\n end=len(A)\n ... | 11 | Given an array of integers `arr`, sort the array by performing a series of **pancake flips**.
In one pancake flip we do the following steps:
* Choose an integer `k` where `1 <= k <= arr.length`.
* Reverse the sub-array `arr[0...k-1]` (**0-indexed**).
For example, if `arr = [3,2,1,4]` and we performed a pancake f... | null |
Simple python 🐍 solution with comments beats 99% time | pancake-sorting | 0 | 1 | Idea is i put the maximum element at index 0, then flip the whole array to make the max at the **end**, and keep repeating \n\nTime O(n^2) { (reversed is O(n) + index is O(n) + max is O(n)) * while O(n) = O(n^2) }\n```\nclass Solution:\n def pancakeSort(self, A: List[int]) -> List[int]:\n\n end=len(A)\n ... | 11 | The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation.
* For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`.
Given an integer `n`, return _its complement_.
**Ex... | null |
Python Simple Solution Explained (video + code) | pancake-sorting | 0 | 1 | [](https://www.youtube.com/watch?v=4WQouWU9XXE)\nhttps://www.youtube.com/watch?v=4WQouWU9XXE\n```\nclass Solution:\n def pancakeSort(self, A: List[int]) -> List[int]:\n x = len(A)\n k = []\n \n for indx in range(x):\n max_ = max(A[:x - indx])\n max_indx = A.index(max... | 10 | Given an array of integers `arr`, sort the array by performing a series of **pancake flips**.
In one pancake flip we do the following steps:
* Choose an integer `k` where `1 <= k <= arr.length`.
* Reverse the sub-array `arr[0...k-1]` (**0-indexed**).
For example, if `arr = [3,2,1,4]` and we performed a pancake f... | null |
Python Simple Solution Explained (video + code) | pancake-sorting | 0 | 1 | [](https://www.youtube.com/watch?v=4WQouWU9XXE)\nhttps://www.youtube.com/watch?v=4WQouWU9XXE\n```\nclass Solution:\n def pancakeSort(self, A: List[int]) -> List[int]:\n x = len(A)\n k = []\n \n for indx in range(x):\n max_ = max(A[:x - indx])\n max_indx = A.index(max... | 10 | The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation.
* For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`.
Given an integer `n`, return _its complement_.
**Ex... | null |
Easy Understanding||Recursion | pancake-sorting | 0 | 1 | \n# Code\n```\nclass Solution:\n def __init__(self):\n self.result = []\n def pancakeSort(self, arr: List[int]) -> List[int]:\n if len(arr) == 0:\n return self.result\n max_index = arr.index(max(arr))\n left = arr[:max_index+1]\n left.reverse()\n self.result.ap... | 0 | Given an array of integers `arr`, sort the array by performing a series of **pancake flips**.
In one pancake flip we do the following steps:
* Choose an integer `k` where `1 <= k <= arr.length`.
* Reverse the sub-array `arr[0...k-1]` (**0-indexed**).
For example, if `arr = [3,2,1,4]` and we performed a pancake f... | null |
Easy Understanding||Recursion | pancake-sorting | 0 | 1 | \n# Code\n```\nclass Solution:\n def __init__(self):\n self.result = []\n def pancakeSort(self, arr: List[int]) -> List[int]:\n if len(arr) == 0:\n return self.result\n max_index = arr.index(max(arr))\n left = arr[:max_index+1]\n left.reverse()\n self.result.ap... | 0 | The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation.
* For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`.
Given an integer `n`, return _its complement_.
**Ex... | null |
Python Solutions | pancake-sorting | 0 | 1 | # Code\n```\nclass Solution:\n def pancakeSort(self, arr: List[int]) -> List[int]:\n res=[]\n for i in range(len(arr)-1,-1,-1):\n mx=i\n for j in range(i,-1,-1):\n if(arr[mx]<arr[j]):\n mx=j\n self.flip(mx,arr)\n self.flip(i,... | 0 | Given an array of integers `arr`, sort the array by performing a series of **pancake flips**.
In one pancake flip we do the following steps:
* Choose an integer `k` where `1 <= k <= arr.length`.
* Reverse the sub-array `arr[0...k-1]` (**0-indexed**).
For example, if `arr = [3,2,1,4]` and we performed a pancake f... | null |
Python Solutions | pancake-sorting | 0 | 1 | # Code\n```\nclass Solution:\n def pancakeSort(self, arr: List[int]) -> List[int]:\n res=[]\n for i in range(len(arr)-1,-1,-1):\n mx=i\n for j in range(i,-1,-1):\n if(arr[mx]<arr[j]):\n mx=j\n self.flip(mx,arr)\n self.flip(i,... | 0 | The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation.
* For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`.
Given an integer `n`, return _its complement_.
**Ex... | null |
[Python 3] Using logarithm boundaries || beats 98% || 39ms 🥷🏼 | powerful-integers | 0 | 1 | ```python3 []\nclass Solution:\n def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:\n if bound <= 1: return []\n \n res = set()\n L = int(log(bound, x)) + 1 if x > 1 else 1\n M = int(log(bound, y)) + 1 if y > 1 else 1\n\n for i in range(L):\n for... | 1 | Given three integers `x`, `y`, and `bound`, return _a list of all the **powerful integers** that have a value less than or equal to_ `bound`.
An integer is **powerful** if it can be represented as `xi + yj` for some integers `i >= 0` and `j >= 0`.
You may return the answer in **any order**. In your answer, each value... | null |
[Python 3] Using logarithm boundaries || beats 98% || 39ms 🥷🏼 | powerful-integers | 0 | 1 | ```python3 []\nclass Solution:\n def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:\n if bound <= 1: return []\n \n res = set()\n L = int(log(bound, x)) + 1 if x > 1 else 1\n M = int(log(bound, y)) + 1 if y > 1 else 1\n\n for i in range(L):\n for... | 1 | You are given a list of songs where the `ith` song has a duration of `time[i]` seconds.
Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`.
**Example 1:**
**Input... | null |
Solution | powerful-integers | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<int> powerfulIntegers(int x, int y, int bound) {\n vector<int>powx;\n vector<int>powy;\n powx.push_back(1);\n powy.push_back(1);\n if(x!=1){\n int pow=x;\n while(pow<bound){\n powx.push_back(pow);\n ... | 1 | Given three integers `x`, `y`, and `bound`, return _a list of all the **powerful integers** that have a value less than or equal to_ `bound`.
An integer is **powerful** if it can be represented as `xi + yj` for some integers `i >= 0` and `j >= 0`.
You may return the answer in **any order**. In your answer, each value... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.