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
100 % faster Linear Python solution | Prefix sum | O(N)
plates-between-candles
0
1
The basic idea is I am pre-calculating the no of plates for every position along with left nearest and right nearest candles for a given point for all i = 0 -> length\nThen to form the answer -> check if 2 candles are present inside the given boundary area [ if left nearest candle of right boundary is after left bounda...
17
There is a long table with a line of plates and candles arranged on top of it. You are given a **0-indexed** string `s` consisting of characters `'*'` and `'|'` only, where a `'*'` represents a **plate** and a `'|'` represents a **candle**. You are also given a **0-indexed** 2D integer array `queries` where `queries[i...
Can we sort the segments in a way to help solve the problem? How can we dynamically keep track of the sum of the current segment(s)?
[Python3] binary search & O(N) approach
plates-between-candles
0
1
\n```\nclass Solution:\n def platesBetweenCandles(self, s: str, queries: List[List[int]]) -> List[int]:\n prefix = [0]\n candles = []\n for i, ch in enumerate(s): \n if ch == \'|\': candles.append(i)\n if ch == \'|\': prefix.append(prefix[-1])\n else: prefix.appe...
11
There is a long table with a line of plates and candles arranged on top of it. You are given a **0-indexed** string `s` consisting of characters `'*'` and `'|'` only, where a `'*'` represents a **plate** and a `'|'` represents a **candle**. You are also given a **0-indexed** 2D integer array `queries` where `queries[i...
Can we sort the segments in a way to help solve the problem? How can we dynamically keep track of the sum of the current segment(s)?
Custom Binary Search
plates-between-candles
0
1
# Idea of the approach \n # Store all the plates position in an array\n # Ex, s = "***|**|*****|**||**|*"\n # index = [3,5,12,15,16,19]\n # For example for query [1,17] ,I have to find the count of stars\n # Idea is to search if there is a plate in 1st postion if n...
8
There is a long table with a line of plates and candles arranged on top of it. You are given a **0-indexed** string `s` consisting of characters `'*'` and `'|'` only, where a `'*'` represents a **plate** and a `'|'` represents a **candle**. You are also given a **0-indexed** 2D integer array `queries` where `queries[i...
Can we sort the segments in a way to help solve the problem? How can we dynamically keep track of the sum of the current segment(s)?
Python3 | DFS with backtracking | Clean code with comments
number-of-valid-move-combinations-on-chessboard
0
1
```\nclass Solution:\n BOARD_SIZE = 8\n \n def diag(self, r, c):\n # Return all diagonal indices except (r, c)\n # Diagonal indices has the same r - c\n inv = r - c\n result = []\n for ri in range(self.BOARD_SIZE):\n ci = ri - inv\n if 0 <= ci < self.BOA...
2
There is an `8 x 8` chessboard containing `n` pieces (rooks, queens, or bishops). You are given a string array `pieces` of length `n`, where `pieces[i]` describes the type (rook, queen, or bishop) of the `ith` piece. In addition, you are given a 2D integer array `positions` also of length `n`, where `positions[i] = [ri...
null
[Python3] traversal
number-of-valid-move-combinations-on-chessboard
0
1
\n```\nclass Solution:\n def countCombinations(self, pieces: List[str], positions: List[List[int]]) -> int:\n n = len(pieces)\n mp = {"bishop": ((-1, -1), (-1, 1), (1, -1), (1, 1)),\n "queen" : ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)), \n "rook" ...
0
There is an `8 x 8` chessboard containing `n` pieces (rooks, queens, or bishops). You are given a string array `pieces` of length `n`, where `pieces[i]` describes the type (rook, queen, or bishop) of the `ith` piece. In addition, you are given a 2D integer array `positions` also of length `n`, where `positions[i] = [ri...
null
Py solution simple
smallest-index-with-equal-value
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
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Super Logic Using Python3
smallest-index-with-equal-value
0
1
\n\n# Simple explained Solution In Python3\n```\nclass Solution:\n def smallestEqual(self, nums: List[int]) -> int:\n list1=[]\n for i in range(len(nums)):\n if((i%10) == nums[i]):\n list1.append(i)\n if len(nums)==len(list1):\n return 0\n if list1:\n ...
1
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Python3|| Beats 98.62% || Beginner simple solution
smallest-index-with-equal-value
0
1
![image.png](https://assets.leetcode.com/users/images/e2f89b95-ef02-4717-8c6f-8b4a6e2b1d2c_1677840452.4258904.png)\n\n\n# Code\n```\nclass Solution:\n def smallestEqual(self, nums: List[int]) -> int:\n for i in range(len(nums)):\n if i%10 == nums[i]:\n return i\n break...
4
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Easy Solution | Java | Python
smallest-index-with-equal-value
1
1
# Java\n```\nclass Solution {\n public int smallestEqual(int[] nums) {\n for(int i=0; i<nums.length; i++) {\n if(i % 10 == nums[i]) {\n return i;\n }\n }\n return -1;\n }\n}\n```\n# Python\n```\nclass Solution:\n def smallestEqual(self, nums: List[int])...
1
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Python O(N)
smallest-index-with-equal-value
0
1
# Intuition JUET\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach easy understanding \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: best: O(1)\n- wrost :O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Spac...
1
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
python easy solution!
smallest-index-with-equal-value
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition for this problem is to iterate through the indices and values of the given list nums and check for the condition where the index modulo 10 is equal to the value at that index.\n\n# Approach\n<!-- Describe your approach to so...
1
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Python simple and short solution
smallest-index-with-equal-value
0
1
**Python :**\n\n```\ndef smallestEqual(self, nums: List[int]) -> int:\n\tfor idx, n in enumerate(nums):\n\t\tif idx % 10 == n:\n\t\t\treturn idx\n\treturn -1 \n```\n\n**Like it ? please upvote !**
11
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
[Python3] 1-line
smallest-index-with-equal-value
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/4001168494179e85482f91afbf0cd66b908544f3) for my solutions of weekly 265. \n```\nclass Solution:\n def smallestEqual(self, nums: List[int]) -> int:\n return next((i for i, x in enumerate(nums) if i%10 == x), -1)\n```
14
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
Python 1 line - 99% speed 95% memory usage
smallest-index-with-equal-value
0
1
![image](https://assets.leetcode.com/users/images/2f825987-9b44-4e1a-9f80-502bf041cc7f_1635991024.3918374.png)\n\nMake use of recursion to loop over ```nums``` array. Return ```-1``` if ```i``` exceeds the last index of ```nums```\n```\nclass Solution(object):\n def smallestEqual(self, nums, i=0):\n return -1...
5
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. `x mod y` denotes the **remainder** when `x` is divided by `y`. **Example 1:** **Input:** nums = \[0,1,2\] **Output:** 0 **Explanation:** i=0: 0 mo...
null
[Python 3] Save critical points, then return min and max diff
find-the-minimum-and-maximum-number-of-nodes-between-critical-points
0
1
```python3 []\nclass Solution:\n def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:\n idx, i = [], 1\n prev, cur = head, head.next\n while cur and cur.next:\n if prev.val < cur.val > cur.next.val or prev.val > cur.val < cur.next.val:\n idx.appe...
1
A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. A node is a **local minima** if the current node has a value **strictly smaller** than th...
Build an array of size 2 * n and assign num[i] to ans[i] and ans[i + n]
Python || Easy Solution
find-the-minimum-and-maximum-number-of-nodes-between-critical-points
0
1
class Solution:\n\t\n\tdef nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:\n \n prev = None\n temp = head\n \n mini, maxi = 10 ** 5, 0\n count = 1\n \n diff = 10 ** 5\n while temp.next.next != None:\n prev = temp\n ...
5
A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. A node is a **local minima** if the current node has a value **strictly smaller** than th...
Build an array of size 2 * n and assign num[i] to ans[i] and ans[i + n]
90% TC and 87% SC easy python solution
find-the-minimum-and-maximum-number-of-nodes-between-critical-points
0
1
```\ndef nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:\n\tans = [float(\'inf\'), -float(\'inf\')]\n\tcurr = head.next\n\tprev = head\n\ti = 1\n\tpos = []\n\twhile(curr.next):\n\t\tif(prev.val < curr.val > curr.next.val):\n\t\t\tpos.append(i)\n\t\telif(prev.val > curr.val < curr.next.val):\n\t...
3
A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. A node is a **local minima** if the current node has a value **strictly smaller** than th...
Build an array of size 2 * n and assign num[i] to ans[i] and ans[i + n]
BEET 100%
find-the-minimum-and-maximum-number-of-nodes-between-critical-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)$$ --...
0
A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. A node is a **local minima** if the current node has a value **strictly smaller** than th...
Build an array of size 2 * n and assign num[i] to ans[i] and ans[i + n]
O(n) solution, runtime 88.32%, memory 95.33%
find-the-minimum-and-maximum-number-of-nodes-between-critical-points
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCreate list L to store all critical position.\nInitiate pos = 0, prev for holding previous node value.\n\nThen iterate whole linked list.\n(while head.next) make sure it\'s not the last node.\n(if pos > 0) make sure it\'s no...
0
A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. A node is a **local minima** if the current node has a value **strictly smaller** than th...
Build an array of size 2 * n and assign num[i] to ans[i] and ans[i + n]
[Python3] bfs
minimum-operations-to-convert-number
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/4001168494179e85482f91afbf0cd66b908544f3) for my solutions of weekly 265. \n```\nclass Solution:\n def minimumOperations(self, nums: List[int], start: int, goal: int) -> int:\n ans = 0\n seen = {start}\n queue = deque([...
19
You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on th...
What is the maximum number of length-3 palindromic strings? How can we keep track of the characters that appeared to the left of a given position?
📌📌 BFS Approach || Well-coded || Easy-to-understand 🐍
minimum-operations-to-convert-number
0
1
## IDEA :\n*Go through all the possibilities. \nwe are storing each possibility in seen so Maximum space required is 1000.*\n\n\'\'\'\n\n\tclass Solution:\n def minimumOperations(self, nums: List[int], start: int, goal: int) -> int:\n if start==goal:\n return 0\n \n q = [(start,0)]\n ...
5
You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on th...
What is the maximum number of length-3 palindromic strings? How can we keep track of the characters that appeared to the left of a given position?
Python 3 BFS with a Queue
minimum-operations-to-convert-number
0
1
```\nfrom collections import deque\n\n\nclass Solution:\n def minimumOperations(self, nums, start: int, goal: int) -> int:\n """\n Given an array of integers (nums), a start value (start),\n and a target value (goal), this program uses breadth-\n first search (BFS) with the help of a queu...
8
You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on th...
What is the maximum number of length-3 palindromic strings? How can we keep track of the characters that appeared to the left of a given position?
[py3] Simple BFS
minimum-operations-to-convert-number
0
1
```\nclass Solution:\n def minimumOperations(self, nums: List[int], start: int, goal: int) -> int:\n seen = set()\n que = deque([(start, 0)])\n \n while que:\n item, cnt = que.popleft()\n if item == goal:\n return cnt\n if item in seen:\n ...
4
You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on th...
What is the maximum number of length-3 palindromic strings? How can we keep track of the characters that appeared to the left of a given position?
Python3 clean BFS solution
minimum-operations-to-convert-number
0
1
\n\n# Code\n```\nclass Solution:\n def minimumOperations(self, nums: List[int], start: int, target: int) -> int:\n \n \n q=deque()\n q.append(start)\n seen=set([start])\n steps=0\n \n while q:\n \n for i in range(len(q)):\n ...
0
You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on th...
What is the maximum number of length-3 palindromic strings? How can we keep track of the characters that appeared to the left of a given position?
[Python3] dp
check-if-an-original-string-exists-given-two-encoded-strings
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/4001168494179e85482f91afbf0cd66b908544f3) for my solutions of weekly 265. \n```\nclass Solution:\n def possiblyEquals(self, s1: str, s2: str) -> bool:\n \n def gg(s): \n """Return possible length"""\n ans...
89
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Clean, concise code with elaborate explanations
check-if-an-original-string-exists-given-two-encoded-strings
0
1
```\nclass Solution:\n def possiblyEquals(self, s1: str, s2: str) -> bool:\n def parse_int(s: str, i: int) -> Iterator[tuple[int, int]]:\n """\n Incrementally parses an integer starting from s[i].\n\n Example:\n "456" is parsed as (4,1), (45,2), and (456,3)\n\n ...
4
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Python | DFS with memo
check-if-an-original-string-exists-given-two-encoded-strings
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\ndigits essentially served as wildcard, explicitly count digits as wildcard match quotas while dfs.\n\n\n# Code\n```\nfrom functools import lru_cache\n\nclass Solution:\n\n def possiblyEquals(self, s1: str, s2: str) -> bool:\n\n ...
0
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Python DFS solution with caching
check-if-an-original-string-exists-given-two-encoded-strings
0
1
Full credit to this YouTube video for this solution: https://www.youtube.com/watch?v=K6d524jDH3A\n\nI just translated it roughly from C++ to Python.\n\nHe broke it down with an example:\ns1 = 3b3c, s2 = 2bb3\nstep 1: if both have matchers, reduce until the minimum matcher reaches 0: s1 = 1b3c, s2 = bb3\nstep 2: if one ...
0
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
[Python3] relative easy to understand, backtracking with memorization
check-if-an-original-string-exists-given-two-encoded-strings
0
1
# Intuition\n\nCalculate diff\n\nAlgorithm:\n\n```\ns1 s2 diff desc\n2a aba 0 initial state\na aba 2 read 2 from s1, remove 2 from s1, diff + 2\na ba 1 since diff 2 > 0, remove 1 char from s2, diff - 1\na a 0 since diff 1 > 0, remove 1 char from s2, diff - 1\n\'\' \'\' 0 since diff == 0 and...
0
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Python recursive O(n^3) : one case at a time
check-if-an-original-string-exists-given-two-encoded-strings
0
1
\n```\n\nclass Solution:\n def possiblyEquals(self, s: str, t: str) -> bool:\n @cache\n def solve(i, j, gap):\n if i == len(s) and j == len(t):\n return gap == 0\n if i > len(s) or j > len(t):\n return False\n\n if i < len(s) and s[i].isdi...
0
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Python (Simple DP)
check-if-an-original-string-exists-given-two-encoded-strings
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
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
Python Solution: Recursion with memoization / DP - The code easy to follow
check-if-an-original-string-exists-given-two-encoded-strings
0
1
Here is my Solution. I hope the code is easy to follow compared to other post. I originally tried to compute all of possible strings with wildcards; that approach worked but proof to be too slow. \n\nThis approach similar to others; using a `diff` to track the wildcards in `s1` and `s2`; wildcards in `s2` make `diff` g...
0
An original string, consisting of lowercase English letters, can be encoded by the following steps: * Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. * Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric s...
Is it possible to have multiple leaf nodes with the same values? How many possible positions are there for each tree? The root value of the final tree does not occur as a value in any of the leaves of the original tree.
count-vowel-substrings-of-a-string
count-vowel-substrings-of-a-string
0
1
\n# Code\n```\nclass Solution:\n def countVowelSubstrings(self, s: str) -> int:\n count = 0\n l = []\n b = ["a","e","i","o","u"]\n for i in range(len(s)+1):\n for j in range(i):\n a = s[j:i]\n if "a" in a and "e" in a and "i" in a and "o" in a and ...
1
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
Two pointer approach, run time is slow but low memory needed. Starightforward approach.
count-vowel-substrings-of-a-string
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)$$ --...
2
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
[Python3] sliding window O(N)
count-vowel-substrings-of-a-string
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/6b6e6b9115d2b659e68dcf3ea8e21befefaae16c) for solutions of weekly 266. \n\n```\nclass Solution:\n def countVowelSubstrings(self, word: str) -> int:\n ans = 0 \n freq = defaultdict(int)\n for i, x in enumerate(word): \n ...
18
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
Python. Time: one pass O(N), space: O(1). Not a sliding window.
count-vowel-substrings-of-a-string
0
1
```\nclass Solution:\n def countVowelSubstrings(self, word: str) -> int:\n vowels = (\'a\', \'e\', \'i\', \'o\', \'u\')\n \n result = 0\n start = 0\n vowel_idx = {}\n for idx, c in enumerate(word):\n if c in vowels:\n if not vowel_idx:\n ...
17
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
[Python3] One-line Solution
count-vowel-substrings-of-a-string
0
1
```python\nclass Solution:\n def countVowelSubstrings(self, word: str) -> int:\n return sum(set(word[i:j+1]) == set(\'aeiou\') for i in range(len(word)) for j in range(i+1, len(word)))\n```
8
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
python straightforward solution
count-vowel-substrings-of-a-string
0
1
```\nclass Solution:\n def countVowelSubstrings(self, word: str) -> int:\n count = 0 \n current = set() \n for i in range(len(word)):\n if word[i] in \'aeiou\':\n current.add(word[i])\n \n for j in range(i+1, len(word)): \n ...
11
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
[Python3] Sliding Window O(N) with explanations
count-vowel-substrings-of-a-string
0
1
\n```python\nclass Solution:\n def countVowelSubstrings(self, word: str) -> int:\n result = 0\n vowels = \'aeiou\'\n # dictionary to record counts of each char\n mp = defaultdict(lambda: 0)\n\n for i, char in enumerate(word):\n # if the current letter is a vowel\n ...
8
A **substring** is a contiguous (non-empty) sequence of characters within a string. A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. Given a string `word`, return _the number of **vowel substrings** in_ `word`. **...
Simulate the game and try all possible moves for each player.
Detailed explanation of why (len - pos) * (pos + 1) works
vowels-of-all-substrings
1
1
<br>\nLet us understand this problem with an example\n<br>let word = "abei"\n\n**All possible substrings:**\n```\na b e i\nab be ei\nabe bei\nabei\n```\n\nSo for counting occurences of vowels in each substring, we can count the occurence of each vowel in each substring\nIn this example...
101
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
(i + 1) * (sz - i)
vowels-of-all-substrings
1
1
A vowel at position `i` appears in `(i + 1) * (sz - i)` substrings. \n\nSo, we just sum and return the appearances for all vowels.\n\n**Python 3**\n```python\nclass Solution:\n def countVowels(self, word: str) -> int:\n return sum((i + 1) * (len(word) - i) for i, ch in enumerate(word) if ch in \'aeiou\')\n```...
38
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
Python3 | Explained | Top Down DP | O(n)
vowels-of-all-substrings
0
1
We have to iterate over the list and just have to count the number of times a vovel is used in a substring, so if we are at index i and it is a vovel then it will be used in i+1 (from 0 to i) and x-i (form i to x) where x is the length of the string.\nAnd if we multiply these two to get the sum for that vovel i.e (i+1)...
1
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
Fastest Python Solution | 108ms
vowels-of-all-substrings
0
1
# Fastest Python Solution | 108ms\n**Runtime: 108 ms, faster than 100.00% of Python3 online submissions for Vowels of All Substrings.\nMemory Usage: 14.8 MB, less than 100.00% of Python3 online submissions for Vowels of All Substrings.**\n```\nclass Solution:\n def countVowels(self, word: str) -> int:\n c, l ...
6
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
[Python] DP, no extra memory
vowels-of-all-substrings
0
1
# Intuition\nWe can approach this problem with DP. Let\'s count total number of vowels in the substrings of ``word`` prefix ``word[0..i]`` and call it ``DP(i)``. \nThus given we have ``DP(i-1)`` we can calculate ``DP(i)`` in the following way:\n1. If ``word[i]`` is a consonant, then total number of vowels in all substr...
1
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
[Python] One liner O(N)
vowels-of-all-substrings
0
1
\n```\nclass Solution:\n def countVowels(self, word: str) -> int:\n return sum((i+1)*(len(word)-i) for i in range(len(word)) if word[i] in "aeiou")\n\n\n\n \n\n\n \n```
0
Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. A **substring** is a contiguous (non-empty) sequence of characters within a string. **Note:** Due to the large constraints, the answer may not fit in a signed 32-bit inte...
null
[Python3] Binary Search - Easy to Understand
minimized-maximum-of-products-distributed-to-any-store
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:$$O(logk)$$ k is maximum `quantity` in `quantities`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O...
2
You are given an integer `n` indicating there are `n` specialty retail stores. There are `m` product types of varying amounts, which are given as a **0-indexed** integer array `quantities`, where `quantities[i]` represents the number of products of the `ith` product type. You need to distribute **all products** to the...
null
[Python3] binary search
minimized-maximum-of-products-distributed-to-any-store
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/6b6e6b9115d2b659e68dcf3ea8e21befefaae16c) for solutions of weekly 266. \n\n```\nclass Solution:\n def minimizedMaximum(self, n: int, quantities: List[int]) -> int:\n lo, hi = 1, max(quantities)\n while lo < hi: \n m...
9
You are given an integer `n` indicating there are `n` specialty retail stores. There are `m` product types of varying amounts, which are given as a **0-indexed** integer array `quantities`, where `quantities[i]` represents the number of products of the `ith` product type. You need to distribute **all products** to the...
null
Simple Python solution using binary search
minimized-maximum-of-products-distributed-to-any-store
0
1
https://www.youtube.com/watch?v=wRO1kW7pQqA\n# Code\n```\n// youtube solution: https://www.youtube.com/watch?v=wRO1kW7pQqA\nclass Solution:\n def minimizedMaximum(self, n: int, quantities: List[int]) -> int:\n lo, hi, res = 1, max(quantities), -1\n\n while lo <= hi:\n mid = lo + (hi - lo)//2...
0
You are given an integer `n` indicating there are `n` specialty retail stores. There are `m` product types of varying amounts, which are given as a **0-indexed** integer array `quantities`, where `quantities[i]` represents the number of products of the `ith` product type. You need to distribute **all products** to the...
null
BFS 177ms Beats 100.00%of users with Python3
maximum-path-quality-of-a-graph
0
1
# Intuition\nGraph question - first think about using BFS\n\n# Approach\nBFS\n\n# Complexity\n![Screenshot 2023-07-18 at 3.40.29 PM.png](https://assets.leetcode.com/users/images/7305d8e8-92d6-4b5e-be59-a806c94ce0db_1689720115.546126.png)\n\n# Code\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int...
1
There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the `ith` node. You are also given a **0-indexed** 2D integer array `edges`, where each `edges[j] = [uj, vj, timej]` indicates that the...
null
python super easy to understand dfs
maximum-path-quality-of-a-graph
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
There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the `ith` node. You are also given a **0-indexed** 2D integer array `edges`, where each `edges[j] = [uj, vj, timej]` indicates that the...
null
[Python3] iterative dfs
maximum-path-quality-of-a-graph
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/6b6e6b9115d2b659e68dcf3ea8e21befefaae16c) for solutions of weekly 266. \n\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = [[] for _ in values]\n f...
2
There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the `ith` node. You are also given a **0-indexed** 2D integer array `edges`, where each `edges[j] = [uj, vj, timej]` indicates that the...
null
[Python] DFS and BFS solution
maximum-path-quality-of-a-graph
0
1
DFS solution:\n```python\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n ans = 0\n graph = collections.defaultdict(dict)\n for u, v, t in edges:\n graph[u][v] = t\n graph[v][u] = t\n \n def dfs...
3
There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the `ith` node. You are also given a **0-indexed** 2D integer array `edges`, where each `edges[j] = [uj, vj, timej]` indicates that the...
null
Iterative DFS | Bitmask | Commented and Explained
maximum-path-quality-of-a-graph
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is very similar to a house robbing problem. Due to this, much of the terminology in the intuition is similar. The nice thing about this problem for an interview, is there are actually a fair number of ways to approach it, and if thou...
0
There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the `ith` node. You are also given a **0-indexed** 2D integer array `edges`, where each `edges[j] = [uj, vj, timej]` indicates that the...
null
93.5% Time beat
check-whether-two-strings-are-almost-equivalent
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
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
[Python] Learn the use of any() and character count using array | Concise Code
check-whether-two-strings-are-almost-equivalent
0
1
# Code\n```\nclass Solution:\n def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:\n A = [0] * 26\n for char in word1: A[ord(char) - ord("a")] += 1\n for char in word2: A[ord(char) - ord("a")] -= 1\n return not any ([(f < -3 or f > 3) for f in A]) \n\n```
3
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
Check Whether Two Strings are Almost Equivalent
check-whether-two-strings-are-almost-equivalent
0
1
\n\n# Code\n```\nclass Solution:\n def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:\n check = set(word1 + word2)\n for i in check:\n limit = abs(word1.count(i) - word2.count(i)) >= 4\n if limit:\n return False\n return True\n\n```
2
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
Python one line counter solution
check-whether-two-strings-are-almost-equivalent
0
1
**Python :**\n\n```\ndef checkAlmostEquivalent(self, word1: str, word2: str) -> bool:\n\treturn all(v <= 3 for v in ((Counter(list(word1)) - Counter(list(word2))) + (Counter(list(word2)) - Counter(list(word1)))).values())\n```\n\n**Like it ? please upvote !**
12
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
Python3 simple solution
check-whether-two-strings-are-almost-equivalent
0
1
# Code\n```\nclass Solution:\n def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:\n words = set(word1 + word2)\n for w in words:\n if abs(word1.count(w) - word2.count(w)) >3:\n return False\n return True\n\n```
5
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
[Python] - Concise Array Solution - No Counter/Hash-Map - Beats 98%
check-whether-two-strings-are-almost-equivalent
0
1
Most solution are using a hash map/Counter to count the occurences for every word itself and then compare these counters.\n\nBut since the alphabet is limited to 26 characters, we can just do the same using an array and do it in one pass through both words at the same time. This allows us to make one pass instead of tw...
10
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
Easy Solution - Beats 100%
check-whether-two-strings-are-almost-equivalent
0
1
# Code\n```\nclass Solution:\n def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:\n check = set(word1 + word2)\n\n for i in check:\n res = abs(word1.count(i) - word2.count(i)) >= 4\n if res:\n return False\n return True\n```
2
Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent...
How can we use a trie to store all the XOR values in the path from a node to the root? How can we dynamically add the XOR values with a DFS search?
NOT BAD
walking-robot-simulation-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)$$ --...
1
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
O(1) Easy Solution
walking-robot-simulation-ii
0
1
# Approach\nI represent the outer edge of the grid as a continuous circular array and store the position of the robot on that array as the index.\n\n\n# Complexity\n- Time complexity:\n\nAll functions are $$O(1)$$\n\n- Space complexity:\n\nAll functions are $$O(1)$$\n\n# Code\n```\nclass Robot:\n\n def __init__(self...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
Easy to understand python solution
walking-robot-simulation-ii
0
1
\n\n# Complexity\n- Time complexity: O((m+n)*num) i.e O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m*n) i.e O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfrom typing import List\n\nclass Robot:\n def __init__(self, width: int, height: int):\n...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
Python Solution with explanation and comments on code
walking-robot-simulation-ii
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe start moving the robot first by one turn around the board. When the robot moves one turn, it doesn\'t change the direction either, only in case if its current location was [0,0], then we need to make sure the direction will be saved as...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
O(1) Laps on the edge + initial direction edge case
walking-robot-simulation-ii
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe robot only moves around the edge of the grid in counterclockwise laps.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nA lap consists of `2 * (width + height - 2)` steps because the robot doesn\'t skip a move a...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
Beats 90 % on python
walking-robot-simulation-ii
0
1
\n```\nclass Robot:\n\n def __init__(self, width, height):\n \n from collections import deque \n self.width = height\n self.height = width \n self.directions=deque([ (0,1) ,(1,0),(0,-1),(-1,0) ]) \n self.pos=(0,0)\n self.hashmap = {(0,1):\'East\',(1,0):\'N...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
Pure simulation with modulo , still slow but simple .
walking-robot-simulation-ii
0
1
\n```\nclass Robot:\n\n def __init__(self, width, height):\n \n from collections import deque \n self.width = height\n self.height = width \n self.directions=deque([ (0,1) ,(1,0),(0,-1),(-1,0) ]) \n self.pos=(0,0)\n self.hashmap = {(0,1):\'East\',(1,0):\'N...
0
A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions ( `"North "`, `"East "`, `"South "`, and `"West "`). A robot is **initially** at cell `(0, 0)` facing direction `"East "`. T...
How can you compute the number of subarrays with a sum less than a given value? Can we use binary search to help find the answer?
[Python3] - Sort + Binary Search - Easy to understand
most-beautiful-item-for-each-query
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nProblem said `price is less than or equal` so it means we can think about sorting by `price` and then do binary search to find `price is less than or equal` to the `queries[j]`. But it is not only that simple. In here we have to find the ...
5
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
Python3 | Solved Using Sorting + Binary Search
most-beautiful-item-for-each-query
0
1
```\nclass Solution:\n #Let n = len(items) and m = len(queries)!\n #Time-Complexity: O(nlog(n) + n + m*log(n)) -> O((n+m) * logn)\n #Space-Complexity: O(1)\n def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n #First of all, I need to sort the list of items by the incr...
0
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
📌📌 Well-Explained || 99% faster || Mainly for Beginners 🐍
most-beautiful-item-for-each-query
0
1
## IDEA :\n\n* Step 1. Sort the items by price, O(nlog)\n\n* Step 2. Iterate items, find maximum value up to now, O(n) and store the max value in dictionary(MAP) here `dic`.\n* Step 3. For each queries, binary search the maximum beauty, O(log k) in key of the map which we formed and append the max value of the query fr...
5
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
[Python3] greedy
most-beautiful-item-for-each-query
0
1
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/e61879b77928a08bb15cc182a69259d6e2bce59a) for solutions of biweekly 65. \n```\nclass Solution:\n def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n items.sort()\n ans = [0]*len(queries)\n ...
4
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
Python Sorting - Concise and Easy to Understand
most-beautiful-item-for-each-query
0
1
# Intuition\n1 Since we need to query by less and equal, that we want to use binary search. To do binary Search we need to sort the items.\n\n2 Only Binary Search can\'t ensure the beauty is max, given the below case\n((1, 3), (2, 2))\nNeed to update the beauty to max on the left.\n\n# Approach\n<!-- Describe your appr...
0
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
Simple sort + max heap solution
most-beautiful-item-for-each-query
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each query, we\'ll need to get the max value but iterating the array each time is expensive. Using a simple heap should help us with getting the max value so far.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\...
0
You are given a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
Binary Search
most-beautiful-item-for-each-query
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 a 2D integer array `items` where `items[i] = [pricei, beautyi]` denotes the **price** and **beauty** of an item respectively. You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal*...
Keep looking for 3-equals, if you find a 3-equal, keep going. If you don't find a 3-equal, check if it is a 2-equal. Make sure that it is the only 2-equal. If it is neither a 3-equal nor a 2-equal, then it is impossible.
Binary Search + Linear Greedy in Python3
maximum-number-of-tasks-you-can-assign
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis solution employs binary search to find the largest $k$ so that $k$ tasks can be completed by $k$ workers. To check if $k$ tasks can be completed, this solution performs an efficient linear time greedy algorithm by using a monotonic q...
0
You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
[Python3] binary search
maximum-number-of-tasks-you-can-assign
0
1
I thought a greedy algo would be enough but have spent hours and couldn\'t get a solution. It turns out that the direction was wrong in the first place. Below implementation is based on other posts in the discuss. \n\nPlease check out this [commit](https://github.com/gaosanyong/leetcode/commit/e61879b77928a08bb15cc182a...
10
You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
[python] binary search + greedy with deque O(nlogn)
maximum-number-of-tasks-you-can-assign
0
1
Use binary search with greedy check. Each check can be done in O(n) using a deque. Within a check, we iterate through the workers from the weakiest to the strongest. Each worker needs to take a task. \nThere are two cases:\n1. The worker can take the easiest task available: we assign it to the worker.\n2. The worker ca...
11
You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
Python 100%
maximum-number-of-tasks-you-can-assign
0
1
# Code\n```\nimport bisect\nimport collections\n\ndef binsearch(low, high, do_not_search_less_than):\n while high - low > 1:\n mid = (low + high) // 2\n if do_not_search_less_than(mid):\n low = mid\n else:\n high = mid\n return low\n\nclass TaskAssigner:\n def __init_...
0
You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
Python (Simple Binary Search)
maximum-number-of-tasks-you-can-assign
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 have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
Python 3 (No binary search) Faster than 100%
maximum-number-of-tasks-you-can-assign
0
1
![Screenshot 2023-07-27 at 1.28.48 PM.png](https://assets.leetcode.com/users/images/502027f1-967d-4dc5-86f9-5023ae6a8bde_1690491263.5724463.png)\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe inituition: Starts with realizing that you can complete at most k tasks. \nWhere `k = mi...
0
You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the `ith` task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the `jth` worker having `workers[j]` strength. E...
Fix one array. Choose the next array and get the common elements. Use the common elements as the new fixed array and keep merging with the rest of the arrays.
Two simple solutions in Python3 || Queue DS || Inifinite looping
time-needed-to-buy-tickets
0
1
# Intuition\nFollowing to the description of the problem, the task goal is to calculate **min amount of time**, that `K`- buyer needs to spend in order to buy tickets.\n\nSomehow we need to iterate over all buyers, reduce the current amount of tickets they\'re bying at the moment, shift the current buyer to **the END o...
2
There are `n` people in a line queuing to buy tickets, where the `0th` person is at the **front** of the line and the `(n - 1)th` person is at the **back** of the line. You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the `ith` person would like to buy is `tickets[i]...
n is very small, how can we use that? What shape is the region when two viruses intersect?
[Python] | BruteForce and O(N)
time-needed-to-buy-tickets
0
1
Please upvote if you find it helpful\n\nBruteForce:\n```\nclass Solution:\n def timeRequiredToBuy(self, tickets: list[int], k: int) -> int:\n secs = 0 \n i = 0\n while tickets[k] != 0:\n if tickets[i] != 0: # if it is zero that means we dont have to count it anymore\n t...
39
There are `n` people in a line queuing to buy tickets, where the `0th` person is at the **front** of the line and the `(n - 1)th` person is at the **back** of the line. You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the `ith` person would like to buy is `tickets[i]...
n is very small, how can we use that? What shape is the region when two viruses intersect?
Python3 queue
time-needed-to-buy-tickets
0
1
\n\n# Code\n```\nclass Solution:\n def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n \n n=len(tickets)\n q=deque([i for i in range(n)])\n \n time=0\n \n while q:\n for i in range(len(q)):\n\n node=q.popleft()\n ...
3
There are `n` people in a line queuing to buy tickets, where the `0th` person is at the **front** of the line and the `(n - 1)th` person is at the **back** of the line. You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the `ith` person would like to buy is `tickets[i]...
n is very small, how can we use that? What shape is the region when two viruses intersect?
Python O(N) easy method
time-needed-to-buy-tickets
0
1
```\nclass Solution:\n def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n\t\t#Loop through all elements in list only once. \n\t\t\n nums = tickets \n time_sec = 0\n\t\t# save the number of tickets to be bought by person standing at k position\n least_tickets = nums[k] \n\t\t#...
13
There are `n` people in a line queuing to buy tickets, where the `0th` person is at the **front** of the line and the `(n - 1)th` person is at the **back** of the line. You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the `ith` person would like to buy is `tickets[i]...
n is very small, how can we use that? What shape is the region when two viruses intersect?
O(n) Python - treat <=kth and kth differently
time-needed-to-buy-tickets
0
1
```\nclass Solution:\n def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n c=0\n l=len(tickets)\n for i in range(l):\n if i <= k:\n c+= min(tickets[k],tickets[i])\n else:\n c+= min(tickets[k]-1,tickets[i])\n return c\n```
1
There are `n` people in a line queuing to buy tickets, where the `0th` person is at the **front** of the line and the `(n - 1)th` person is at the **back** of the line. You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the `ith` person would like to buy is `tickets[i]...
n is very small, how can we use that? What shape is the region when two viruses intersect?
Not So Fast But Understandable.py
reverse-nodes-in-even-length-groups
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****1)First convert linked list to list.\n\n2)Then create the temporary list of the desired length like 1,2,3,4...\n\n3)Then check if length of temp list is even:\nif ...
1
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
🔥 Clean 🐍python solution 🔥 simple 🔥 beats 100% 🔥 explanation 🔥
reverse-nodes-in-even-length-groups
0
1
# Intuition\nWhen considering this problem, we need to be comfortable with various linked list operations and concepts. These include understanding how to traverse a linked list, reverse a section of it without disrupting the rest of the list, and reconnect reversed segments seamlessly back into the list. With these to...
9
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python & C++✅✅ | Faster🧭 than 90%🔥 | Easy Implementation🆗 | Clean & Concise Code |
reverse-nodes-in-even-length-groups
0
1
# Approach\n```txt\nk = odd\ndummy -> 1 -> || 2 -> 3 -> 4 || -> 5 -> 6 -> 7\n grpPrev kth grpNxt --> No Reverse \n```\n```txt\nk = even\ndummy -> 1 -> || 2 -> 3 -> 4 -> 5 || -> 6 -> 7\n grpPrev kth grpNxt --> Reverse \n```\n\n# Complexity\n- Time complexity: O(N)\n- Space co...
2
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python Simple | Neat Solution | O(n) Time, O(1) Space
reverse-nodes-in-even-length-groups
0
1
```\nclass Solution:\n def reverseEvenLengthGroups(self, head: Optional[ListNode]) -> Optional[ListNode]:\n start_joint = head \n group_size = 1\n while start_joint and start_joint.next: \n group_size += 1\n start = end = start_joint.next \n group_num = 1 \n ...
7
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
[Python3] using stack
reverse-nodes-in-even-length-groups
0
1
Downvoters, leave a comment! \n\nPlease check out this [commit](https://github.com/gaosanyong/leetcode/commit/8d693371fa97ea3b0717d02448c77201b15e5d12) for solutions of weekly 267.\n```\nclass Solution:\n def reverseEvenLengthGroups(self, head: Optional[ListNode]) -> Optional[ListNode]:\n n, node = 0, head\n ...
13
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python Solution Use 4 Pointers with Clear Explanation
reverse-nodes-in-even-length-groups
0
1
This solution was inspired by @astroash\'s C++ solution, which can be found at https://leetcode.com/problems/reverse-nodes-in-even-length-groups/solutions/1576952/c-well-commented-clear-code-idea-explained-in-brief/. \nThis is an implementation of the same solution in Python. The key aspects of this solution will be ou...
1
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python easy to understand
reverse-nodes-in-even-length-groups
0
1
\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = va...
2
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python 3 || 14 lines, w/ example || T/M: 97%/52%
reverse-nodes-in-even-length-groups
0
1
```\nclass Solution:\n def reverseEvenLengthGroups(self, head: ListNode) -> ListNode:\n\n node, nums, ans = head, [], []\n T = lambda x: x*(x+1)//2\n flip = lambda x: x if len(x)%2 else x[::-1] # Example: head = 1->5->4->2->6->3->0->8\n\n while node: ...
3
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Python solution using stack
reverse-nodes-in-even-length-groups
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 the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
2.5 hrs----use pen , page--- trust yourself
reverse-nodes-in-even-length-groups
0
1
# Intuition\n![hard.png](https://assets.leetcode.com/users/images/72e00de3-5671-4f3d-847b-4d5ed49d5b03_1703356901.8685808.png)\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 ti...
0
You are given the `head` of a linked list. The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, * The `1st` node is assigned to t...
First, we need to note that this is a classic problem given n points you need to find the minimum enclosing circle to bind them Second, we need to apply a well known algorithm called welzls algorithm to help us find the minimum enclosing circle
Jump Columns + 1
decode-the-slanted-ciphertext
1
1
Knowing `rows`, we can find out `cols`. Knowing `cols`, we can jump to the next letter (`cols + 1`).\n\nExample: `"ch ie pr"`, rows = 3, columns = 12 / 3 = 4.\n0: [0, 5, 10] `"cip"`\n1: [1, 6, 11] `"her"`\n2: [2, 7] `" "` <- we will trim this.\n3: [3, 8] `" "` <- we will trim this.\n\n**Java**\n```java\npublic St...
64
A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. `originalText` is placed first in a top-left to bottom-right manner. The blue cells are filled first, followed by the red cells, then the yellow cel...
Convert lights into an array of ranges representing the range where each street light can light up and sort the start and end points of the ranges. Do we need to traverse all possible positions on the street? No, we don't, we only need to go to the start and end points of the ranges for each streetlight.
Python3 solution | Time : 99.33% & Space : 100%
decode-the-slanted-ciphertext
0
1
![Capture d\u2019\xE9cran (96).png](https://assets.leetcode.com/users/images/3e9f8a31-b0d3-4995-ae49-64d20c8c39d1_1681219407.2042663.png)\n\n\n# Complexity\n- Time complexity: $$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 decode...
1
A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. `originalText` is placed first in a top-left to bottom-right manner. The blue cells are filled first, followed by the red cells, then the yellow cel...
Convert lights into an array of ranges representing the range where each street light can light up and sort the start and end points of the ranges. Do we need to traverse all possible positions on the street? No, we don't, we only need to go to the start and end points of the ranges for each streetlight.
Google 😍🔥 || Easy Beginner's Approach || Using Map || C++
decode-the-slanted-ciphertext
1
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
A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. `originalText` is placed first in a top-left to bottom-right manner. The blue cells are filled first, followed by the red cells, then the yellow cel...
Convert lights into an array of ranges representing the range where each street light can light up and sort the start and end points of the ranges. Do we need to traverse all possible positions on the street? No, we don't, we only need to go to the start and end points of the ranges for each streetlight.
Bad Edge Cases :-(
decode-the-slanted-ciphertext
0
1
# Intuition\nGood intuition but bad edgecases\n# Approach\nWhy would someone have empty spaces in edges of decipher text!!\n# Complexity\n- Time complexity:\nO(69*N)\n- Space complexity:\nO(Edge_Fricking_cases)\n# Code\n```\nclass Solution:\n def decodeCiphertext(self, encodedText: str, rows: int) -> str:\n i...
0
A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. `originalText` is placed first in a top-left to bottom-right manner. The blue cells are filled first, followed by the red cells, then the yellow cel...
Convert lights into an array of ranges representing the range where each street light can light up and sort the start and end points of the ranges. Do we need to traverse all possible positions on the street? No, we don't, we only need to go to the start and end points of the ranges for each streetlight.
✅simple simulation || python
decode-the-slanted-ciphertext
0
1
\n# Code\n```\nclass Solution:\n def decodeCiphertext(self, encodedText: str, rows: int) -> str:\n c=ceil(len(encodedText)/rows)\n ans=""\n for i in range(c):\n j=0\n while(i+j<len(encodedText)):\n ans+=encodedText[i+j]\n j+=c+1\n i=len(...
0
A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. `originalText` is placed first in a top-left to bottom-right manner. The blue cells are filled first, followed by the red cells, then the yellow cel...
Convert lights into an array of ranges representing the range where each street light can light up and sort the start and end points of the ranges. Do we need to traverse all possible positions on the street? No, we don't, we only need to go to the start and end points of the ranges for each streetlight.