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 |
|---|---|---|---|---|---|---|---|
easy solution using backtracking | splitting-a-string-into-descending-consecutive-values | 0 | 1 | \n# Code\n```\nclass Solution:\n def splitString(self, s: str) -> bool:\n\n def backtrack(index,prev):\n if index == len(s):\n return True\n\n for j in range(index,len(s)):\n val = int(s[index:j+1])\n if val + 1 == prev and backtrack(j+1,val):... | 1 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
easy solution using backtracking | splitting-a-string-into-descending-consecutive-values | 0 | 1 | \n# Code\n```\nclass Solution:\n def splitString(self, s: str) -> bool:\n\n def backtrack(index,prev):\n if index == len(s):\n return True\n\n for j in range(index,len(s)):\n val = int(s[index:j+1])\n if val + 1 == prev and backtrack(j+1,val):... | 1 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
This also works too | splitting-a-string-into-descending-consecutive-values | 0 | 1 | I am sure all you smart pants can figure out the basic algorithm behind this, but the part I had a lot of trouble figuring out was the edge case. However, as long as I made sure that the previous number I had was not int(s) itself, it all worked out itself.\n\n\n# Code\n```\nclass Solution:\n def splitString(self, s... | 0 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
This also works too | splitting-a-string-into-descending-consecutive-values | 0 | 1 | I am sure all you smart pants can figure out the basic algorithm behind this, but the part I had a lot of trouble figuring out was the edge case. However, as long as I made sure that the previous number I had was not int(s) itself, it all worked out itself.\n\n\n# Code\n```\nclass Solution:\n def splitString(self, s... | 0 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
💡💡 Neatly coded backtracking solution using python3 | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuitive Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe use backtracking (DFS approach) to solve this as we have to go brute anyway to find the different splits possible. \n\nOutside the function:\nWe first loop from 0 to len(s)-2 (we leave the last character for the second part), ... | 0 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
💡💡 Neatly coded backtracking solution using python3 | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuitive Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe use backtracking (DFS approach) to solve this as we have to go brute anyway to find the different splits possible. \n\nOutside the function:\nWe first loop from 0 to len(s)-2 (we leave the last character for the second part), ... | 0 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
Python: 95% | Simple and Detailed Code | DFS | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\nThe main idea of solving this problem is this idea of "chunking" your input string into every possible substring all the while keeping track of the remaining part of the string. These chunks of possible solution and remaining will be passed into futher recursive calls.\n\nI.E. take the string "05004" which... | 0 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
Python: 95% | Simple and Detailed Code | DFS | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\nThe main idea of solving this problem is this idea of "chunking" your input string into every possible substring all the while keeping track of the remaining part of the string. These chunks of possible solution and remaining will be passed into futher recursive calls.\n\nI.E. take the string "05004" which... | 0 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
O(n^n) time | O(n) space | solution explained | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are given a string of digits and need to split it into substrings such that the substrings are in descending order with a difference of 1 between the values that the adjacent substrings represent.\n\nUse backtracking to explore all pos... | 0 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
O(n^n) time | O(n) space | solution explained | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are given a string of digits and need to split it into substrings such that the substrings are in descending order with a difference of 1 between the values that the adjacent substrings represent.\n\nUse backtracking to explore all pos... | 0 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
Python3 Backtracking | splitting-a-string-into-descending-consecutive-values | 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 string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
Python3 Backtracking | splitting-a-string-into-descending-consecutive-values | 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 in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
Python (Simple Backtracking) | splitting-a-string-into-descending-consecutive-values | 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 string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
Python (Simple Backtracking) | splitting-a-string-into-descending-consecutive-values | 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 in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
Python Solution | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->Check if every digit segments are in decreasing order and differ by one\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBacktracking\n# Complexity\n- Time complexity: O(n^2)/n! (?)\n<!-- Add your time complexity here... | 0 | You are given a string `s` that consists of only digits.
Check if we can split `s` into **two or more non-empty substrings** such that the **numerical values** of the substrings are in **descending order** and the **difference** between numerical values of every two **adjacent** **substrings** is equal to `1`.
* Fo... | What if we asked for maximum sum, not absolute sum? It's a standard problem that can be solved by Kadane's algorithm. The key idea is the max absolute sum will be either the max sum or the min sum. So just run kadane twice, once calculating the max sum and once calculating the min sum. |
Python Solution | splitting-a-string-into-descending-consecutive-values | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->Check if every digit segments are in decreasing order and differ by one\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBacktracking\n# Complexity\n- Time complexity: O(n^2)/n! (?)\n<!-- Add your time complexity here... | 0 | You are in a city that consists of `n` intersections numbered from `0` to `n - 1` with **bi-directional** roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are given an in... | One solution is to try all possible splits using backtrack Look out for trailing zeros in string |
[Python3] brute-force | minimum-adjacent-swaps-to-reach-the-kth-smallest-number | 0 | 1 | \n```\nclass Solution:\n def getMinSwaps(self, num: str, k: int) -> int:\n num = list(num)\n orig = num.copy()\n \n for _ in range(k): \n for i in reversed(range(len(num)-1)): \n if num[i] < num[i+1]: \n ii = i+1 \n while ii ... | 7 | You are given a string `num`, representing a large integer, and an integer `k`.
We call some integer **wonderful** if it is a **permutation** of the digits in `num` and is **greater in value** than `num`. There can be many wonderful integers. However, we only care about the **smallest-valued** ones.
* For example, ... | If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can. Note that if the length is equal 1 the answer is 1 |
Python Next Permutation + Minimum Adjacent Swaps | minimum-adjacent-swaps-to-reach-the-kth-smallest-number | 0 | 1 | \n# Complexity\n- Time complexity:O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def nextPermutation(self,nums):\n i=len(nums)-2\n while i>=0:\n if nums[i]<nums... | 0 | You are given a string `num`, representing a large integer, and an integer `k`.
We call some integer **wonderful** if it is a **permutation** of the digits in `num` and is **greater in value** than `num`. There can be many wonderful integers. However, we only care about the **smallest-valued** ones.
* For example, ... | If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can. Note that if the length is equal 1 the answer is 1 |
Python 44ms :) | minimum-adjacent-swaps-to-reach-the-kth-smallest-number | 0 | 1 | \n# Code\n```\n# this function modifies l to a new list, which is\n# strictly after l and before or equal to the k-th successor of l\n# in the lex order.\n# "find the minimum i such that l[i:] is reverse-sorted.\n# find the maximum j >= i with l[j] > l[i - 1].\n# swap l[j] and l[i - 1] and then sort l[i:]."\n# note tha... | 0 | You are given a string `num`, representing a large integer, and an integer `k`.
We call some integer **wonderful** if it is a **permutation** of the digits in `num` and is **greater in value** than `num`. There can be many wonderful integers. However, we only care about the **smallest-valued** ones.
* For example, ... | If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can. Note that if the length is equal 1 the answer is 1 |
Greedy Python solution | minimum-adjacent-swaps-to-reach-the-kth-smallest-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 | You are given a string `num`, representing a large integer, and an integer `k`.
We call some integer **wonderful** if it is a **permutation** of the digits in `num` and is **greater in value** than `num`. There can be many wonderful integers. However, we only care about the **smallest-valued** ones.
* For example, ... | If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can. Note that if the length is equal 1 the answer is 1 |
next greater value | minimum-adjacent-swaps-to-reach-the-kth-smallest-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 | You are given a string `num`, representing a large integer, and an integer `k`.
We call some integer **wonderful** if it is a **permutation** of the digits in `num` and is **greater in value** than `num`. There can be many wonderful integers. However, we only care about the **smallest-valued** ones.
* For example, ... | If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can. Note that if the length is equal 1 the answer is 1 |
Clean Python3 | Sorting & Heap | minimum-interval-to-include-each-query | 0 | 1 | Please upvote if it helps!\n```\nclass Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n\t\n queries_asc = sorted((q, i) for i, q in enumerate(queries))\n intervals.sort()\n \n i, num_intervals = 0, len(intervals)\n size_heap = [] # (... | 2 | You are given a 2D integer array `intervals`, where `intervals[i] = [lefti, righti]` describes the `ith` interval starting at `lefti` and ending at `righti` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `righti - lefti + 1`.
You are also given an intege... | Sort the events by its startTime. For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search. |
Clean Python3 | Sorting & Heap | minimum-interval-to-include-each-query | 0 | 1 | Please upvote if it helps!\n```\nclass Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n\t\n queries_asc = sorted((q, i) for i, q in enumerate(queries))\n intervals.sort()\n \n i, num_intervals = 0, len(intervals)\n size_heap = [] # (... | 2 | You wrote down many **positive** integers in a string called `num`. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was **non-decreasing** and that **no** integer had leading zeros.
Return _the **number of possible lists of integers** that y... | Is there a way to order the intervals and queries such that it takes less time to query? Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size? |
Python 3 || hashMap, priority queue, min-heap | minimum-interval-to-include-each-query | 0 | 1 | \tclass Solution:\n\t\tdef minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n\t\t\thashMap = {}\n\t\t\tintervals.sort()\n\n\t\t\tminHeap = []\n\n\t\t\ti_l = len(intervals)\n\t\t\ti = 0\n\t\t\tfor q in sorted(queries):\n\t\t\t\twhile i < i_l and intervals[i][0] <= q:\n\t\t\t\t\tstart, end ... | 1 | You are given a 2D integer array `intervals`, where `intervals[i] = [lefti, righti]` describes the `ith` interval starting at `lefti` and ending at `righti` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `righti - lefti + 1`.
You are also given an intege... | Sort the events by its startTime. For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search. |
Python 3 || hashMap, priority queue, min-heap | minimum-interval-to-include-each-query | 0 | 1 | \tclass Solution:\n\t\tdef minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n\t\t\thashMap = {}\n\t\t\tintervals.sort()\n\n\t\t\tminHeap = []\n\n\t\t\ti_l = len(intervals)\n\t\t\ti = 0\n\t\t\tfor q in sorted(queries):\n\t\t\t\twhile i < i_l and intervals[i][0] <= q:\n\t\t\t\t\tstart, end ... | 1 | You wrote down many **positive** integers in a string called `num`. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was **non-decreasing** and that **no** integer had leading zeros.
Return _the **number of possible lists of integers** that y... | Is there a way to order the intervals and queries such that it takes less time to query? Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size? |
📌📌 For Beginners || Easy-Approach || Well-Explained || Clean & Concise 🐍 | minimum-interval-to-include-each-query | 0 | 1 | ## IDEA:\n\uD83D\uDC49 *Sort the intervals by size and the queries in increasing order, then iterate over the intervals.\n\uD83D\uDC49 For each interval (left, right) binary search for the queries (q) that are contained in the interval (left <= q <= right), pop them from the array queries and insert them in the array ... | 5 | You are given a 2D integer array `intervals`, where `intervals[i] = [lefti, righti]` describes the `ith` interval starting at `lefti` and ending at `righti` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `righti - lefti + 1`.
You are also given an intege... | Sort the events by its startTime. For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search. |
📌📌 For Beginners || Easy-Approach || Well-Explained || Clean & Concise 🐍 | minimum-interval-to-include-each-query | 0 | 1 | ## IDEA:\n\uD83D\uDC49 *Sort the intervals by size and the queries in increasing order, then iterate over the intervals.\n\uD83D\uDC49 For each interval (left, right) binary search for the queries (q) that are contained in the interval (left <= q <= right), pop them from the array queries and insert them in the array ... | 5 | You wrote down many **positive** integers in a string called `num`. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was **non-decreasing** and that **no** integer had leading zeros.
Return _the **number of possible lists of integers** that y... | Is there a way to order the intervals and queries such that it takes less time to query? Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size? |
SIMPLE HEAP PYTHON (BEATS 100%) | minimum-interval-to-include-each-query | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n intervals.sort(reverse=True)\n heap = []\n ans = {}\n\n for q in sorted(queries):\n while intervals and intervals[-1][0] <= q:\n interval = in... | 0 | You are given a 2D integer array `intervals`, where `intervals[i] = [lefti, righti]` describes the `ith` interval starting at `lefti` and ending at `righti` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `righti - lefti + 1`.
You are also given an intege... | Sort the events by its startTime. For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search. |
SIMPLE HEAP PYTHON (BEATS 100%) | minimum-interval-to-include-each-query | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:\n intervals.sort(reverse=True)\n heap = []\n ans = {}\n\n for q in sorted(queries):\n while intervals and intervals[-1][0] <= q:\n interval = in... | 0 | You wrote down many **positive** integers in a string called `num`. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was **non-decreasing** and that **no** integer had leading zeros.
Return _the **number of possible lists of integers** that y... | Is there a way to order the intervals and queries such that it takes less time to query? Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size? |
💡💡 Neatly coded minheap solution in python3 | minimum-interval-to-include-each-query | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse minheap to store the possible intervals for the current query and pop the minimum interval.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe start with creating a minheap. Now, we sort the queries dynamically... | 0 | You are given a 2D integer array `intervals`, where `intervals[i] = [lefti, righti]` describes the `ith` interval starting at `lefti` and ending at `righti` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `righti - lefti + 1`.
You are also given an intege... | Sort the events by its startTime. For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search. |
💡💡 Neatly coded minheap solution in python3 | minimum-interval-to-include-each-query | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse minheap to store the possible intervals for the current query and pop the minimum interval.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe start with creating a minheap. Now, we sort the queries dynamically... | 0 | You wrote down many **positive** integers in a string called `num`. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was **non-decreasing** and that **no** integer had leading zeros.
Return _the **number of possible lists of integers** that y... | Is there a way to order the intervals and queries such that it takes less time to query? Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size? |
Python3 O(N) | maximum-population-year | 0 | 1 | ### Steps\n1. For each log, update an array which stores the population changes in each year. The first index corresponds to the year 1950, and the last to the year 2050. \n1. Then, iterate through the years while updating the running sum, max population and year of that max population.\n1. Return that year.\n\n```\ncl... | 35 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
Simple Python solution with explanation | maximum-population-year | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
Easy Python Solution for beginners | maximum-population-year | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- This solution iterates through each year in the range of birth years to death years and counts the population by checking if the year falls within the inclusive range for each individual. \n- It then keeps track of the maximum populatio... | 2 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
Python || 97.44% Faster || O(N) Solution || Hashmap | maximum-population-year | 0 | 1 | ```\nclass Solution:\n def maximumPopulation(self, logs: List[List[int]]) -> int:\n a,n=[0]*101,len(logs)\n for birth,death in logs:\n a[birth-1950]+=1\n a[death-1950]-=1\n c=m=year=0\n for i in range(101):\n c+=a[i]\n if c>m:\n m... | 5 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
[Python3] greedy | maximum-population-year | 0 | 1 | \n```\nclass Solution:\n def maximumPopulation(self, logs: List[List[int]]) -> int:\n vals = []\n for x, y in logs: \n vals.append((x, 1))\n vals.append((y, -1))\n ans = prefix = most = 0\n for x, k in sorted(vals): \n prefix += k\n if prefix > ... | 9 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
4 liner, hash map solution | maximum-population-year | 0 | 1 | ```\ncount = {}\nfor i in logs:\n for v in range(i[0],i[1]):\n count[v] = count.get(v,0) + 1\n m = max(count.values())\n return min([i for i in count if count[i] == m])\n``` | 2 | You are given a 2D integer array `logs` where each `logs[i] = [birthi, deathi]` indicates the birth and death years of the `ith` person.
The **population** of some year `x` is the number of people alive during that year. The `ith` person is counted in year `x`'s population if `x` is in the **inclusive** range `[birthi... | null |
Binary Search Python Explained | maximum-distance-between-a-pair-of-values | 0 | 1 | # Intuition\nThrough the given problem we have few conditions\n`1. j >= i`\n`2. nums2[j] > nums1[i]`\n\nNow to satisfy these conditions for every element in of nums1 we have to iterate over nums2(i, len(nums2))\n\nso we will use **binary search** having the above range always\nnow if we find *nums[mid] < nums1[i] => we... | 2 | You are given two **non-increasing 0-indexed** integer arrays `nums1` and `nums2`.
A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i] <= nums2[j]`. The **distance** of the pair is `j - i`.
Return _the **maximum distance** ... | null |
Binary Search Python Explained | maximum-distance-between-a-pair-of-values | 0 | 1 | # Intuition\nThrough the given problem we have few conditions\n`1. j >= i`\n`2. nums2[j] > nums1[i]`\n\nNow to satisfy these conditions for every element in of nums1 we have to iterate over nums2(i, len(nums2))\n\nso we will use **binary search** having the above range always\nnow if we find *nums[mid] < nums1[i] => we... | 2 | You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`.
Pick the scores of any `k` students from the array so that the **difference** between the **highest** and the **lowest** of the `k` scores is **minimized**.
Return _the **m... | Since both arrays are sorted in a non-increasing way this means that for each value in the first array. We can find the farthest value smaller than it using binary search. There is another solution using a two pointers approach since the first array is non-increasing the farthest j such that nums2[j] ≥ nums1[i] is at l... |
📌 Python3 simple solution using two pointers | maximum-distance-between-a-pair-of-values | 0 | 1 | ```\nclass Solution:\n def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:\n length1, length2 = len(nums1), len(nums2)\n i,j = 0,0\n \n result = 0\n while i < length1 and j < length2:\n if nums1[i] > nums2[j]:\n i+=1\n else:\n ... | 6 | You are given two **non-increasing 0-indexed** integer arrays `nums1` and `nums2`.
A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i] <= nums2[j]`. The **distance** of the pair is `j - i`.
Return _the **maximum distance** ... | null |
📌 Python3 simple solution using two pointers | maximum-distance-between-a-pair-of-values | 0 | 1 | ```\nclass Solution:\n def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:\n length1, length2 = len(nums1), len(nums2)\n i,j = 0,0\n \n result = 0\n while i < length1 and j < length2:\n if nums1[i] > nums2[j]:\n i+=1\n else:\n ... | 6 | You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`.
Pick the scores of any `k` students from the array so that the **difference** between the **highest** and the **lowest** of the `k` scores is **minimized**.
Return _the **m... | Since both arrays are sorted in a non-increasing way this means that for each value in the first array. We can find the farthest value smaller than it using binary search. There is another solution using a two pointers approach since the first array is non-increasing the farthest j such that nums2[j] ≥ nums1[i] is at l... |
Binary Search | maximum-distance-between-a-pair-of-values | 0 | 1 | # Intuition\nWe just have to iterate over the first list and find the index of largest number in the second list using binary search.\n\n# Complexity\nm = len(nums1)\nn = len(nums2)\n- Time complexity:\nO(m*log(n))\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def maxDistance(self, nums1: List[int],... | 2 | You are given two **non-increasing 0-indexed** integer arrays `nums1` and `nums2`.
A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i] <= nums2[j]`. The **distance** of the pair is `j - i`.
Return _the **maximum distance** ... | null |
Binary Search | maximum-distance-between-a-pair-of-values | 0 | 1 | # Intuition\nWe just have to iterate over the first list and find the index of largest number in the second list using binary search.\n\n# Complexity\nm = len(nums1)\nn = len(nums2)\n- Time complexity:\nO(m*log(n))\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def maxDistance(self, nums1: List[int],... | 2 | You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`.
Pick the scores of any `k` students from the array so that the **difference** between the **highest** and the **lowest** of the `k` scores is **minimized**.
Return _the **m... | Since both arrays are sorted in a non-increasing way this means that for each value in the first array. We can find the farthest value smaller than it using binary search. There is another solution using a two pointers approach since the first array is non-increasing the farthest j such that nums2[j] ≥ nums1[i] is at l... |
[Python 3] Monotomic Stack + Prefix Sum - Simple | maximum-subarray-min-product | 0 | 1 | # Intuition\nsimilar to this problem: https://leetcode.com/problems/largest-rectangle-in-histogram/\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(N)$$\n<!-- Add your time complexity here... | 4 | The **min-product** of an array is equal to the **minimum value** in the array **multiplied by** the array's **sum**.
* For example, the array `[3,2,5]` (minimum value is `2`) has a min-product of `2 * (3+2+5) = 2 * 10 = 20`.
Given an array of integers `nums`, return _the **maximum min-product** of any **non-empty ... | null |
[Python 3] Monotomic Stack + Prefix Sum - Simple | maximum-subarray-min-product | 0 | 1 | # Intuition\nsimilar to this problem: https://leetcode.com/problems/largest-rectangle-in-histogram/\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(N)$$\n<!-- Add your time complexity here... | 4 | You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.
Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.
**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 ... | Is there a way we can sort the elements to simplify the problem? Can we find the maximum min-product for every value in the array? |
[Python] Disjoint Set Union, iterate from largest to smallest | maximum-subarray-min-product | 0 | 1 | This is a intuition of the process\n- We iterate from the largest number to the smallest number.\n- At every iteration, if the adjacent number(s) is larger than the current number, merge it with the adjacent group(s).\n- After every merge, we update the sum of the group and the minimum value of the group. We update the... | 8 | The **min-product** of an array is equal to the **minimum value** in the array **multiplied by** the array's **sum**.
* For example, the array `[3,2,5]` (minimum value is `2`) has a min-product of `2 * (3+2+5) = 2 * 10 = 20`.
Given an array of integers `nums`, return _the **maximum min-product** of any **non-empty ... | null |
[Python] Disjoint Set Union, iterate from largest to smallest | maximum-subarray-min-product | 0 | 1 | This is a intuition of the process\n- We iterate from the largest number to the smallest number.\n- At every iteration, if the adjacent number(s) is larger than the current number, merge it with the adjacent group(s).\n- After every merge, we update the sum of the group and the minimum value of the group. We update the... | 8 | You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.
Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.
**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 ... | Is there a way we can sort the elements to simplify the problem? Can we find the maximum min-product for every value in the array? |
[Python3] mono-stack | maximum-subarray-min-product | 0 | 1 | \n```\nclass Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:\n prefix = [0]\n for x in nums: prefix.append(prefix[-1] + x)\n \n ans = 0 \n stack = []\n for i, x in enumerate(nums + [-inf]): # append "-inf" to force flush all elements\n while stack ... | 12 | The **min-product** of an array is equal to the **minimum value** in the array **multiplied by** the array's **sum**.
* For example, the array `[3,2,5]` (minimum value is `2`) has a min-product of `2 * (3+2+5) = 2 * 10 = 20`.
Given an array of integers `nums`, return _the **maximum min-product** of any **non-empty ... | null |
[Python3] mono-stack | maximum-subarray-min-product | 0 | 1 | \n```\nclass Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:\n prefix = [0]\n for x in nums: prefix.append(prefix[-1] + x)\n \n ans = 0 \n stack = []\n for i, x in enumerate(nums + [-inf]): # append "-inf" to force flush all elements\n while stack ... | 12 | You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.
Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.
**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 ... | Is there a way we can sort the elements to simplify the problem? Can we find the maximum min-product for every value in the array? |
Python monotonic stack beats 100% | maximum-subarray-min-product | 0 | 1 | a monotonic stack with index and prefix sum\n\n```\nclass Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:\n mod=int(1e9+7)\n stack=[] # (index, prefix sum at index)\n rsum=0\n res=0\n \n nums.append(0)\n \n for i, v in enumerate(nums):\n ... | 5 | The **min-product** of an array is equal to the **minimum value** in the array **multiplied by** the array's **sum**.
* For example, the array `[3,2,5]` (minimum value is `2`) has a min-product of `2 * (3+2+5) = 2 * 10 = 20`.
Given an array of integers `nums`, return _the **maximum min-product** of any **non-empty ... | null |
Python monotonic stack beats 100% | maximum-subarray-min-product | 0 | 1 | a monotonic stack with index and prefix sum\n\n```\nclass Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:\n mod=int(1e9+7)\n stack=[] # (index, prefix sum at index)\n rsum=0\n res=0\n \n nums.append(0)\n \n for i, v in enumerate(nums):\n ... | 5 | You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.
Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.
**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 ... | Is there a way we can sort the elements to simplify the problem? Can we find the maximum min-product for every value in the array? |
Step by step Intuition for DP Solution | maximum-subarray-min-product | 0 | 1 | # Intuition\nTo find the maximum min-product, we want to check all min products. This means for each element in nums, we want to find the min product it is associated with assuming that element is the minimum.\n\nNow finding and summing up the longest subarray in which each element is the minimum is very costly. **Pref... | 1 | The **min-product** of an array is equal to the **minimum value** in the array **multiplied by** the array's **sum**.
* For example, the array `[3,2,5]` (minimum value is `2`) has a min-product of `2 * (3+2+5) = 2 * 10 = 20`.
Given an array of integers `nums`, return _the **maximum min-product** of any **non-empty ... | null |
Step by step Intuition for DP Solution | maximum-subarray-min-product | 0 | 1 | # Intuition\nTo find the maximum min-product, we want to check all min products. This means for each element in nums, we want to find the min product it is associated with assuming that element is the minimum.\n\nNow finding and summing up the longest subarray in which each element is the minimum is very costly. **Pref... | 1 | You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.
Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.
**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 ... | Is there a way we can sort the elements to simplify the problem? Can we find the maximum min-product for every value in the array? |
python3 Solution | largest-color-value-in-a-directed-graph | 0 | 1 | \n```\nclass Solution:\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\n n = len(colors)\n graph = collections.defaultdict(list)\n indegree = [0] * len(colors)\n for u, v in edges:\n graph[v].append(u)\n indegree[u] += 1\n \n c... | 2 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
python3 Solution | largest-color-value-in-a-directed-graph | 0 | 1 | \n```\nclass Solution:\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\n n = len(colors)\n graph = collections.defaultdict(list)\n indegree = [0] * len(colors)\n for u, v in edges:\n graph[v].append(u)\n indegree[u] += 1\n \n c... | 2 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Simple DFS approach with comments | largest-color-value-in-a-directed-graph | 0 | 1 | Run dfs for each node.\r\nKeep `state` of each node as a dictionary: `letter` to longest count of `letter` starting in this node\r\n\r\nDetect cycles by "algorithm biting on its own tail": `visit[node] == -1`\r\n# Code\r\n```\r\ndef largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\r\n n = len(colo... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
Simple DFS approach with comments | largest-color-value-in-a-directed-graph | 0 | 1 | Run dfs for each node.\r\nKeep `state` of each node as a dictionary: `letter` to longest count of `letter` starting in this node\r\n\r\nDetect cycles by "algorithm biting on its own tail": `visit[node] == -1`\r\n# Code\r\n```\r\ndef largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\r\n n = len(colo... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
python 3 - DP | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n(This is a fun question!)\r\n\r\nAfter looking at the constraints, you know you need to use DP because input size is large.\r\n\r\nState variables: index of colors\r\nbase case: when reaching leaf node\r\nrecursion: read and return a count dict\r\n\r\nThe hardest part can be: "how to cache".\r\n\r\n# App... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
python 3 - DP | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n(This is a fun question!)\r\n\r\nAfter looking at the constraints, you know you need to use DP because input size is large.\r\n\r\nState variables: index of colors\r\nbase case: when reaching leaf node\r\nrecursion: read and return a count dict\r\n\r\nThe hardest part can be: "how to cache".\r\n\r\n# App... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Python || 95% TC || Topological Sort (with explanation) | largest-color-value-in-a-directed-graph | 0 | 1 | # Complexity\r\n- Time complexity: $$O(n)$$\r\n\r\n- Space complexity : $$O(n)$$\r\n\r\n# Code\r\n```\r\nclass Solution:\r\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\r\n if not edges: return 1 # Edge Case -> no edge -> 1\r\n n = len(colors) # number of nodes\r\n ro... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
Python || 95% TC || Topological Sort (with explanation) | largest-color-value-in-a-directed-graph | 0 | 1 | # Complexity\r\n- Time complexity: $$O(n)$$\r\n\r\n- Space complexity : $$O(n)$$\r\n\r\n# Code\r\n```\r\nclass Solution:\r\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:\r\n if not edges: return 1 # Edge Case -> no edge -> 1\r\n n = len(colors) # number of nodes\r\n ro... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Beats 99% | O(n) solution | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
Beats 99% | O(n) solution | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
[Python] Topological Sort | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
[Python] Topological Sort | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Image Explanation🏆- [Simple BFS - "COMPLETE" Intuition] - C++/Java/Python | largest-color-value-in-a-directed-graph | 1 | 1 | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\r\n`Largest Color Value in a Directed Graph` by `Aryan Mittal`\r\n\r\n\r\n\r\n\r\n# Approach & Intution\r\n. You are also given a 2D array `edges` where `edges[j]... | null |
Image Explanation🏆- [Simple BFS - "COMPLETE" Intuition] - C++/Java/Python | largest-color-value-in-a-directed-graph | 1 | 1 | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\r\n`Largest Color Value in a Directed Graph` by `Aryan Mittal`\r\n\r\n\r\n\r\n\r\n# Approach & Intution\r\n |
Beating 67% in speed and my original way - I did not know how to ID circles in directed graphs | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe path starts with a node without ancestor. If we count the max number of nodes with a certain color in paths starting from a certain node and we traverse with all scenarios, the max count is the results, if no circle. And since colors ... | 1 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
Beating 67% in speed and my original way - I did not know how to ID circles in directed graphs | largest-color-value-in-a-directed-graph | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe path starts with a node without ancestor. If we count the max number of nodes with a certain color in paths starting from a certain node and we traverse with all scenarios, the max count is the results, if no circle. And since colors ... | 1 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Python DFS + DP | largest-color-value-in-a-directed-graph | 0 | 1 | # Approach\r\n\r\nDFS with cycle detection. Similar to Course Schedules.\r\n\r\nImagine each node as having it\'s own dictionary. Each node\'s color values is the max of its children node\'s color values.\r\n\r\nThis approach prevents us from having to do a DFS starting at every node, which would be quadratic time. Sin... | 3 | There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.
You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j]... | null |
Python DFS + DP | largest-color-value-in-a-directed-graph | 0 | 1 | # Approach\r\n\r\nDFS with cycle detection. Similar to Course Schedules.\r\n\r\nImagine each node as having it\'s own dictionary. Each node\'s color values is the max of its children node\'s color values.\r\n\r\nThis approach prevents us from having to do a DFS starting at every node, which would be quadratic time. Sin... | 3 | There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.
You should finish the given tasks in a way tha... | Use topological sort. let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905) |
Python solution using for loop and list comprehension | sorting-the-sentence | 0 | 1 | # Intuition\nLooking at the test cases I knew I could use the numbers to sort it\n\n# Approach\nI started by converting the string into a list by using .spilt(). I followed that by going into a for loop and getting the last char which is the number. The next step was to put the number at the beginning and to remove the... | 0 | A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence.
* For example... | Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to... |
Python solution using for loop and list comprehension | sorting-the-sentence | 0 | 1 | # Intuition\nLooking at the test cases I knew I could use the numbers to sort it\n\n# Approach\nI started by converting the string into a list by using .spilt(). I followed that by going into a for loop and getting the last char which is the number. The next step was to put the number at the beginning and to remove the... | 0 | There is a **1-based** binary matrix where `0` represents land and `1` represents water. You are given integers `row` and `col` representing the number of rows and columns in the matrix, respectively.
Initially on day `0`, the **entire** matrix is **land**. However, each day a new cell becomes flooded with **water**. ... | Divide the string into the words as an array of strings Sort the words by removing the last character from each word and sorting according to it |
Easiest Python3 Approach | sorting-the-sentence | 0 | 1 | \n# Code\n```\nclass Solution:\n def sortSentence(self, s: str) -> str:\n a = s.split()\n b = [0] * len(a)\n for i in a:\n b[int(i[-1]) - 1] = i[0:-1]\n return " ".join(b)\n``` | 4 | A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence.
* For example... | Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to... |
Easiest Python3 Approach | sorting-the-sentence | 0 | 1 | \n# Code\n```\nclass Solution:\n def sortSentence(self, s: str) -> str:\n a = s.split()\n b = [0] * len(a)\n for i in a:\n b[int(i[-1]) - 1] = i[0:-1]\n return " ".join(b)\n``` | 4 | There is a **1-based** binary matrix where `0` represents land and `1` represents water. You are given integers `row` and `col` representing the number of rows and columns in the matrix, respectively.
Initially on day `0`, the **entire** matrix is **land**. However, each day a new cell becomes flooded with **water**. ... | Divide the string into the words as an array of strings Sort the words by removing the last character from each word and sorting according to it |
[Java/C++/Python] Solution | incremental-memory-leak | 1 | 1 | **Java**\n\n```\nclass Solution {\n public int[] memLeak(int memory1, int memory2) {\n int i = 1;\n while(Math.max(memory1, memory2) >= i){\n if(memory1 >= memory2)\n memory1 -= i;\n else\n memory2 -= i;\n i++;\n }\n return ne... | 29 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
[Java/C++/Python] Solution | incremental-memory-leak | 1 | 1 | **Java**\n\n```\nclass Solution {\n public int[] memLeak(int memory1, int memory2) {\n int i = 1;\n while(Math.max(memory1, memory2) >= i){\n if(memory1 >= memory2)\n memory1 -= i;\n else\n memory2 -= i;\n i++;\n }\n return ne... | 29 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
[Python3] simulation | incremental-memory-leak | 0 | 1 | \n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n k = 1\n while k <= memory1 or k <= memory2: \n if memory1 < memory2: memory2 -= k \n else: memory1 -= k \n k += 1\n return [k, memory1, memory2]\n``` | 4 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
[Python3] simulation | incremental-memory-leak | 0 | 1 | \n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n k = 1\n while k <= memory1 or k <= memory2: \n if memory1 < memory2: memory2 -= k \n else: memory1 -= k \n k += 1\n return [k, memory1, memory2]\n``` | 4 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
[Python3] Solution with using simulation | incremental-memory-leak | 0 | 1 | # Code\n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n memory_in_use, cur_sec = 0,0\n\n while True:\n memory_in_use += 1\n cur_sec += 1\n\n if memory1 < memory_in_use and memory2 < memory_in_use: break\n\n if memory1 >= m... | 0 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
[Python3] Solution with using simulation | incremental-memory-leak | 0 | 1 | # Code\n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n memory_in_use, cur_sec = 0,0\n\n while True:\n memory_in_use += 1\n cur_sec += 1\n\n if memory1 < memory_in_use and memory2 < memory_in_use: break\n\n if memory1 >= m... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
Simple While Loop Implementation using Python | incremental-memory-leak | 0 | 1 | # Approach\nSimple While Loop Implementation using Python\n\n# Complexity\n- Time complexity:\nO(N) where N is the \n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n crashTime = 1\n memoryAllocation = 1\n while max(memory... | 0 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
Simple While Loop Implementation using Python | incremental-memory-leak | 0 | 1 | # Approach\nSimple While Loop Implementation using Python\n\n# Complexity\n- Time complexity:\nO(N) where N is the \n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n crashTime = 1\n memoryAllocation = 1\n while max(memory... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
[ Python | C++ ] one-liner | incremental-memory-leak | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe could use recursion while simulating memory leak. \n\n# Python\n```\nclass Solution:\n def memLeak(self, a, b, t=1):\n return [t,a,b] if max(a,b)<t else self.memLeak(a-t*(a>=b),b-t*(b>a),t+1)\n```\n\n# C++\n```\nclass Solution {\npublic:\... | 0 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
[ Python | C++ ] one-liner | incremental-memory-leak | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe could use recursion while simulating memory leak. \n\n# Python\n```\nclass Solution:\n def memLeak(self, a, b, t=1):\n return [t,a,b] if max(a,b)<t else self.memLeak(a-t*(a>=b),b-t*(b>a),t+1)\n```\n\n# C++\n```\nclass Solution {\npublic:\... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
Solution Using While Loop Only 8 Lines | incremental-memory-leak | 0 | 1 | # Intuition\nWe need to subtract i from the stick which has more memory left and continue this process until there is no memory left in either of the sticks.\n\n# Approach\ninitialise i=1 which denotes the seconds and create a while loop that checks if either memory1 or memory2 has space and if it does subtract that fr... | 0 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
Solution Using While Loop Only 8 Lines | incremental-memory-leak | 0 | 1 | # Intuition\nWe need to subtract i from the stick which has more memory left and continue this process until there is no memory left in either of the sticks.\n\n# Approach\ninitialise i=1 which denotes the seconds and create a while loop that checks if either memory1 or memory2 has space and if it does subtract that fr... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
[Python3] Good enough | incremental-memory-leak | 0 | 1 | ``` Python3 []\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n\n time = 0\n while True:\n time += 1\n if memory1 >= memory2:\n if memory1 - time < 0:\n return [time,memory1,memory2]\n else:\n ... | 0 | You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
[Python3] Good enough | incremental-memory-leak | 0 | 1 | ``` Python3 []\nclass Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:\n\n time = 0\n while True:\n time += 1\n if memory1 >= memory2:\n if memory1 - time < 0:\n return [time,memory1,memory2]\n else:\n ... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
Brute-Force | incremental-memory-leak | 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 two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai... | Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. |
Brute-Force | incremental-memory-leak | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1` (**inclusive**). The edges in the graph are represented as a 2D integer array `edges`, where each `edges[i] = [ui, vi]` denotes a bi-directional edge between vertex `ui` and vertex `vi`. Every vertex pair is connecte... | What is the upper bound for the number of seconds? Simulate the process of allocating memory. |
1861. Rotating the Box | rotating-the-box | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe solution first performs a clockwise rotation of the \'box\' by assigning the values from the original matrix box to the new matrix \'res\' in the rotated positions.\n\nNext, the solution iterates through each column of the \'res\' mat... | 6 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
[Python] Easy explanation | rotating-the-box | 0 | 1 | **First**, move every stone to the right, (or you can rotate the box first and then drop stones. Both as fine).\nThe current location of stone does not matter. \nWe only need to remember how many stones each interval (seperated by obstacles) has, \nand place the stones before the first seeing obstacle.\n\n**Second**, r... | 13 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Python | Two Pointers | rotating-the-box | 0 | 1 | # Algorithm\n1. Create a skeleton matrix with the number of rows and columns interchanged.\n2. Rotate the box -> matrix\n3. Iterate through each column and use two pointers in bottom-up fashion to seach for stone and blanks.\n4. Throughout the entire iteration the points to be kept in mind are:\n\t* \tThe index for sto... | 3 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
two pointers | Beats 86% | rotating-the-box | 0 | 1 | ```\nclass Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n m, n = len(box), len(box[0])\n for row in box:\n i, j = len(row) - 2, len(row) - 1\n while i >= 0:\n if row[j] == \'.\':\n if row[i] == \'#\':\n ... | 1 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Simple Python Solution | rotating-the-box | 0 | 1 | The idea is to look for the rocks closest to the bottom first. Move them to the the last empty cell (the one left of nearest obstacle).\n\n```\ndef rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n # Constants\n ROWS, COLS = len(box), len(box[0])\n \n # Falling logic\n fo... | 1 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
easy solution using sorting || beats 78.95% RT , Memory 61.60 | rotating-the-box | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n lst=[]\n for i in box:\n v=[]\n val=""\n st=""\n ... | 3 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Simple Solution With Lists | rotating-the-box | 0 | 1 | ```\nclass Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n new_box = []\n for row in box:\n adjusted_row = []\n curr_section = []\n for idx, elem in enumerate(row):\n if elem == ".":\n curr_section.insert(... | 0 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Python, runtime O(mn), memory O(1) | rotating-the-box | 0 | 1 | ```\nclass Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n M = len(box)\n N = len(box[0])\n ans = [[\'.\']*M for _ in range(N)]\n for i in range(M):\n q = deque([])\n for j in range(N-1, -1, -1):\n if box[i][j] == \'*\':\... | 0 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Simple python solution with Sort | 2 mins enough to understand | rotating-the-box | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Iterate over the `box` line by line. For each line:\n + split at each `*` (You can regard each segment as a seperate problem, because all the falling happens independently in the current segment.)\n + Let the little squares "fall... | 0 | You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:
* A stone `'#'`
* A stationary obstacle `'*'`
* Empty `'.'`
The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u... | Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.