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 |
|---|---|---|---|---|---|---|---|
Easiest Python Solution | convert-a-number-to-hexadecimal | 0 | 1 | ```\ndef toHex(self, num: int) -> str:\n\tif num == 0: return \'0\'\n\tmap = \'0123456789abcdef\'\n\tresult = \'\'\n\t#if negative (two\'s compliment)\n\tif num<0: num += 2 ** 32\n\twhile num > 0:\n\t\tdigit = num % 16\n\t\tnum = (num-digit) // 16\n\t\tresult += str(map[digit])\n\treturn result[::-1]\n```\nIf you like ... | 19 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
O(1) Python solution | convert-a-number-to-hexadecimal | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy first thought is that this problem can be solved by converting the decimal number to its hexadecimal representation. I can achieve this by using bit manipulation and a lookup table to convert the last 4 bits of the decimal number to it... | 4 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
[Python3] One line | convert-a-number-to-hexadecimal | 0 | 1 | Using **str.format()** method we can convert to **hexadecimal** format. This option is also aviable for **binary**, **octal** and **decimal** representation with \'b\', \'o\', \'d\' case respectively.\n```\nclass Solution:\n def toHex(self, num: int) -> str:\n return "{0:x}".format(num) if num >= 0 else "{0:x... | 4 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
4-Lines Python Solution || 98% Faster (24ms) || Memory less than 76% | convert-a-number-to-hexadecimal | 0 | 1 | ```\nclass Solution:\n def toHex(self, num: int) -> str:\n Hex=\'0123456789abcdef\' ; ans=\'\'\n if num<0: num+=2**32\n while num>0: ans=Hex[num%16]+ans ; num//=16\n return ans if ans else \'0\'\n```\n-------------------\n***----- Taha Choura -----***\n*taha.choura@outlook.com* | 2 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
Python : 🐍 Only 2 Line❗️Easy❗️ | convert-a-number-to-hexadecimal | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n \n**If you think this is easy, Please Vote for everyone !**\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 comple... | 2 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
Easy Solution with simple explanation : ) | convert-a-number-to-hexadecimal | 1 | 1 | Let\'s break down the problem and the provided code in simpler terms:\n\n### Problem Explanation:\nThe task is to convert an integer `num` into its hexadecimal representation. The hexadecimal system uses base-16, where each digit can be one of 16 values (0-9 and A-F). For negative numbers, a method called two\'s comple... | 0 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
Hexadecimal Conversion with Two's Complement | convert-a-number-to-hexadecimal | 0 | 1 | # Intuition\nUse the two\'s complement method to convert integers to their hexadecimal representation.\n\n# Approach\nIterate through 8 groups of 4 bits in the 32-bit integer, extract each group\'s value, and convert it to hexadecimal. Remove leading zeros.\n\n# Complexity\n- Time complexity: O(1)\n- Space complexity: ... | 0 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
easy python soultion | convert-a-number-to-hexadecimal | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
Python | 3 lines | Build in functions | convert-a-number-to-hexadecimal | 0 | 1 | # Code\n```\nclass Solution:\n def toHex(self, num: int) -> str:\n if num < 0:\n num = 2**32 + num\n return hex(num)[2:]\n\n``` | 0 | Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.
All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer... | null |
Trivial solution with Sorting in Python3 | queue-reconstruction-by-height | 0 | 1 | # Intuition\nHere we have:\n- `people`, that is tuple `[height, pos]`\n- our goal is to reconstruct a Queue\n\nTo reconstruct this Queue, the only thing we should do is to insert a particular `people[i]` into `pos`, after sorting people by height in **descending** order. \n\n# Approach\n1. define `ans` as **deque**\n2.... | 1 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Trivial solution with Sorting in Python3 | queue-reconstruction-by-height | 0 | 1 | # Intuition\nHere we have:\n- `people`, that is tuple `[height, pos]`\n- our goal is to reconstruct a Queue\n\nTo reconstruct this Queue, the only thing we should do is to insert a particular `people[i]` into `pos`, after sorting people by height in **descending** order. \n\n# Approach\n1. define `ans` as **deque**\n2.... | 1 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python Easy Greedy O(1) Space approach | queue-reconstruction-by-height | 0 | 1 | ```\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n output=[] \n \n # sort the array in decreasing order of height \n # within the same height group, you would sort it in increasing order of k\n # eg: Input : [[7,0],[4,4],[7,1],[5,0],[6,... | 91 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python Easy Greedy O(1) Space approach | queue-reconstruction-by-height | 0 | 1 | ```\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n output=[] \n \n # sort the array in decreasing order of height \n # within the same height group, you would sort it in increasing order of k\n # eg: Input : [[7,0],[4,4],[7,1],[5,0],[6,... | 91 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
📌 Python3 naive solution: Insert into result array | queue-reconstruction-by-height | 0 | 1 | ```\nfrom bisect import insort\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n dic = {}\n heights = []\n result = []\n for height, peopleAhead in people:\n if height in dic:\n insort(dic[height],peopleAhead)\n ... | 6 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
📌 Python3 naive solution: Insert into result array | queue-reconstruction-by-height | 0 | 1 | ```\nfrom bisect import insort\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n dic = {}\n heights = []\n result = []\n for height, peopleAhead in people:\n if height in dic:\n insort(dic[height],peopleAhead)\n ... | 6 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python 96% Fast and 93% space efficient solution | queue-reconstruction-by-height | 0 | 1 | optimal best solution:\n\n\n\tclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n people.sort(key = lambda x: (-x[0], x[1]))\n queue = []\n for p in people:\n queue.insert(p[1], p) \n return queue\n\t\t\n\t\t\naverage time solution:\n\t... | 2 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python 96% Fast and 93% space efficient solution | queue-reconstruction-by-height | 0 | 1 | optimal best solution:\n\n\n\tclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n people.sort(key = lambda x: (-x[0], x[1]))\n queue = []\n for p in people:\n queue.insert(p[1], p) \n return queue\n\t\t\n\t\t\naverage time solution:\n\t... | 2 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
[Python] O(NlogN) Solution using SortedList | queue-reconstruction-by-height | 0 | 1 | The `O(N^2)` solution is well explained by others. Here we present an `O(NlogN)` solution using Python\'s SortedList (or other similar data structures, e.g. binary indexed tree).\n```\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n from sortedcontainers import Sort... | 3 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
[Python] O(NlogN) Solution using SortedList | queue-reconstruction-by-height | 0 | 1 | The `O(N^2)` solution is well explained by others. Here we present an `O(NlogN)` solution using Python\'s SortedList (or other similar data structures, e.g. binary indexed tree).\n```\nclass Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n from sortedcontainers import Sort... | 3 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
406: Solution with step by step explanation | queue-reconstruction-by-height | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. First, sort the input list people in decreasing order by height (hi). If multiple people have the same height, they should be sorted in increasing order by the number of people in front of them (ki). This can be achieved ... | 5 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
406: Solution with step by step explanation | queue-reconstruction-by-height | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. First, sort the input list people in decreasing order by height (hi). If multiple people have the same height, they should be sorted in increasing order by the number of people in front of them (ki). This can be achieved ... | 5 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python 3 simple solution with explanation | queue-reconstruction-by-height | 0 | 1 | **Idea**\nIn order to achieve the requested output order, a sorted input list can be processed by inserting the new value at index=`k`. In the given example, sort the input by `h` in decreasing order and by `k` in increasing order:\n```\n[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] -> [[7,0], [7,1], [6,1], [5,0], [5,2], ... | 30 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Python 3 simple solution with explanation | queue-reconstruction-by-height | 0 | 1 | **Idea**\nIn order to achieve the requested output order, a sorted input list can be processed by inserting the new value at index=`k`. In the given example, sort the input by `h` in decreasing order and by `k` in increasing order:\n```\n[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] -> [[7,0], [7,1], [6,1], [5,0], [5,2], ... | 30 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Solution.py | queue-reconstruction-by-height | 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 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
Solution.py | queue-reconstruction-by-height | 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 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
easy peasy python solution | queue-reconstruction-by-height | 0 | 1 | \tdef reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n ln = len(people)\n if ln == 0:\n return []\n \n people = sorted(people, key = lambda x: (-x[0], x[1]))\n \n ls = []\n for pep in people:\n ls.insert(pep[1], pep)\n \n... | 13 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
easy peasy python solution | queue-reconstruction-by-height | 0 | 1 | \tdef reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:\n ln = len(people)\n if ln == 0:\n return []\n \n people = sorted(people, key = lambda x: (-x[0], x[1]))\n \n ls = []\n for pep in people:\n ls.insert(pep[1], pep)\n \n... | 13 | You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.
Reconstruct and return _the queu... | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? |
[Python3][Visualization] BFS Solution With Explanation | trapping-rain-water-ii | 0 | 1 | Cells which can trap the rain water, must be surrounded by cells with higher heights. We can maintain a `level` and increases1 by 1 from 0. At the same time, use BFS with a Min-Heap to iterate each cell. \n<br/>\n\n# Graph\n<ins>**Green**</ins>: The cell added in the heap\n<ins>**Yellow**</ins>: The current cell\n<ins>... | 309 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
407: Time 96.51%, Solution with step by step explanation | trapping-rain-water-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Check for edge cases\nThe function starts by checking if the input height map is empty or has no columns, in which case there is no water that can be trapped and the function returns 0.\n\n2. Initialize variables\nThe fun... | 3 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Python 3 || 15 lines, heap || T/M: 85%/24% | trapping-rain-water-ii | 0 | 1 | ```\nclass Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:\n \n m, n = len(heightMap), len(heightMap[0])\n M, N = range(m), range(n)\n\n border = set().union({(i,0) for i in M}, {(i,n-1) for i in M},\n {(0,j) for j in N}, {(m-1,j) for j in ... | 5 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Python solution beats 99% | trapping-rain-water-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition is to use a heap to keep track of the lowest points in the grid and use Dijkstra\'s algorithm to traverse the grid and fill the trapped water.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMy approach is ... | 2 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Share my novel solution with horizontal scanning (No heap used) | trapping-rain-water-ii | 0 | 1 | I didn\'t check other posts when first solving this problem. After my solution got AC, I checked the discussions and found no similar solution (most people use heap). This approach is quite intuitive. After a few optimization, it can beat 90%.\n\n**Intuition**\nThe basic idea is to horizontally scan the whole building ... | 5 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Python BFS + Minheap with explanation | trapping-rain-water-ii | 0 | 1 | ```\n# Solution Logic: MinHeap+BFS\n# 1. Start from the boundary elements\n# 2. Maintain a minheap of heights \n# 3. Maintain a a set of visited elements\n# 4. push all outer boundary elements to the minheap\n# 5. while minheap is not empty:\n# pop the element from minheap\n# check all 4 neighbors \n# ... | 3 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Going up step by step | trapping-rain-water-ii | 0 | 1 | # Code\n```\nclass Solution:\n def trapRainWater(self, ht: List[List[int]]) -> int:\n m,n = len(ht),len(ht[0])\n m1,n1 = m-1,n-1\n hp = []\n for i in range(m):\n heappush(hp,(ht[i][0],i,0))\n heappush(hp,(ht[i][-1],i,n1))\n ht[i][0] = -1\n ht[i]... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Iterative solution to find the maximum height of water. | trapping-rain-water-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTaking inspiration from the 1D problem, I first tried to solve by finding the max height on either of the four sides but realised after submitting that this will fail as the limiting factor for the height either of the sides could be anot... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Python Easy Solution | trapping-rain-water-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Priority Queue | trapping-rain-water-ii | 0 | 1 | # Code\n```\nimport heapq\nfrom typing import List\n\nclass Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:\n if not heightMap:\n return 0\n \n m, n = len(heightMap), len(heightMap[0])\n pq = []\n visited = set()\n water_volume = 0\n ... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Trapping Rain Water II using Python3 | trapping-rain-water-ii | 0 | 1 | # Intuition\nThe problem asks us to find the amount of water that can be trapped between the blocks in a 2D elevation map after raining. To solve this problem, we can make use of the concept of BFS (Breadth-First Search) and Heap (Priority Queue).\n\n# Approach\nOne approach to solve this problem is to use the concept ... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Solution using priority queue | trapping-rain-water-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. -->\n1. Initialize a heap to store the cells on the boundary of the height map along with their corresponding heights. Mark these cells as visited.\n2. Iterate over the hei... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Solution | trapping-rain-water-ii | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n struct val {\n int _height;\n int16_t _x;\n int16_t _y;\n bool operator> (val const & v) const {\n return _height > v._height;\n }\n };\n int trapRainWater(vector<vector<int>>& heightMap) {\n ios_base::sync_with_stdio(0... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
Heap BFS + DFS for a more convincing explanation | trapping-rain-water-ii | 0 | 1 | I didn\'t found the explanation for BFS with heap solutions convincing enough.\n**Here is my intuition for this problem**:\n`Since the water level (not depth) must remain the same across every connected point. If a point in the matrix is connected to a corner point then the maximum water level can be at max the value o... | 0 | Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.
**Example 1:**
**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped... | null |
C++ - Easiest Beginner Friendly Sol || O(n) time and O(128) = O(1) space | longest-palindrome | 1 | 1 | # Intuition of this Problem:\n<!-- Describe your first thoughts on how to solve this problem. -->\n**NOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Approach for this Problem:\n1. Initialize two variables, oddCount to store the ... | 243 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Simple python solution | longest-palindrome | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n arr=[x for x in s]\n frq=Counter(arr)\n count=list(frq.values())\n res=0\n for i in range(len(count)):\n if count[i]%2==0:\n res+=count[i]\n else:\n ... | 2 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Python 3 solution using Set() | longest-palindrome | 0 | 1 | **Idea**:\nStart adding letters to a set. If a given letter not in the set, add it. If the given letter is already in the set, remove it from the set. \nIf the set isn\'t empty, you need to return length of the string minus length of the set plus 1.\nOtherwise, you return the length of the string (example \'bb.\' Your ... | 111 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Make all Odds as Even || Example and Comments || Python | longest-palindrome | 0 | 1 | # Intuition\nA palindrome repeats itself from the middle this means for making longest palindrome we need as many even count of chars.\nBut in a palindrome you can adjust "at most" one odd count char\neg => bbbabbb , bbbcccbbb ....\nSo to maximize the length of palindrome add the count of all even char + 1 odd char cou... | 1 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Python Easy Solution || Hashmap | longest-palindrome | 0 | 1 | # Code\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n dic={}\n tot=0\n flg=0\n for i in s:\n if i in dic:\n dic[i]+=1\n else:\n dic[i]=1\n for i in dic:\n if dic[i]%2==0:\n tot+=dic... | 2 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
[Python] Hash Table faster than 99.88% | longest-palindrome | 0 | 1 | Upvote If you like it \uFF1A\uFF09\n\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n count = {} # Hash Table \n ans = [] # every word\'s frequency \n odd= 0 # store an odd number\'s frequency \n for word in s:\n if word not in count:\n ... | 12 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
409: Solution with step by step explanation | longest-palindrome | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Initialize an empty dictionary freq_dict to store the frequency of each character in the string s.\n2. Iterate over each character char in the string s and add it to the dictionary freq_dict if it doesn\'t exist, or incre... | 9 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Easiest python solution | longest-palindrome | 0 | 1 | class Solution:\n1. def longestPalindrome(self, s: str) -> int:\n c=Counter(s)\n count=0\n p=0\n for a in c:\n if c[a]%2==0:\n count+=c[a]\n if c[a]%2==1:\n count+=c[a]-1\n p=1\n if p==1:\n return count+... | 2 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
python3 easy to understand solution 98.12% beats with froop | longest-palindrome | 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)$$ --... | 5 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
Hindi + English easy Python solution | longest-palindrome | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf number of repeated letters is even, there will not be any single central letter. But if there are any single letters (not repeated), then maximum one can be in the centre of the palindrome.\n\n# Approach\n<!-- Describe your approach to... | 3 | Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Input:** s = "abccccdd "
**Output:** 7
**Explanation... | null |
BINARY SEARCH SOLUTION ✅💯 | split-array-largest-sum | 0 | 1 | # Intuition\nUse **Binary Search**\n# Approach\nUse Binary Search\n# Complexity\n- Time complexity:\n**O(nlogm)**\n\n- Space complexity:\n**O(1)**\n\n# Code\n```\nclass Solution:\n def splitArray(self, nums: List[int], k: int) -> int:\n def check(arr, guess, k):\n total = 0\n count = 1\n... | 1 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
Most optimal solution using binary search with explanation | split-array-largest-sum | 1 | 1 | \n\n# Approach\nThe countPartitions function takes an array and a maximum sum as input and returns the number of partitions needed to ensure that no subarray\'s sum exceeds the maximum sum. It iterates through the array, keeping track of a running sum (subSum). If adding the current element to subSum keeps it within th... | 2 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
Python Binary Search. Readable code | split-array-largest-sum | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def splitArray(self, nums: List[int], k: int) -> int:\n def check(x):\n splits = 1\n n = 0\n for num in nums:\n n += num\n if n > x:\n n = num\n splits += 1\n ... | 2 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
THE ONLY PYTHON SOLUTION WITH DP + MEMOIZATION | split-array-largest-sum | 0 | 1 | \n# Code\n```\nclass Solution:\n def splitArray(self, nums: List[int], k: int) -> int:\n x = nums.count(0)\n if x>k:\n nums.sort()\n while(nums.count(0)!=k):\n nums.pop(0)\n \n\n\n \n ind = 0\n dp = {}\n return self.splitAray(nums,ind,k,... | 4 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
410: Solution with step by step explanation | split-array-largest-sum | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. First, we define the range for our binary search. The minimum value can be the maximum value in the array since we cannot have a subarray with a sum greater than the maximum value. The maximum value can be the sum of all ... | 5 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
✅ Python Short and Simple NLogSum | split-array-largest-sum | 0 | 1 | ```\nclass Solution:\n def splitArray(self, nums: List[int], m: int) -> int:\n def isPossible(maxSum):\n curr = count = 0\n for i in nums:\n count += (i + curr > maxSum)\n curr = curr + i if i + curr <= maxSum else i\n return count + 1 <= m\n ... | 3 | Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:*... | null |
43sec & 17.3MB in python | fizz-buzz | 0 | 1 | **Bold**# 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... | 0 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
i am a new learner. any tips would be great | fizz-buzz | 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 an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
simple solution in python | fizz-buzz | 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)$$ --... | 3 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Python beats 83% | fizz-buzz | 0 | 1 | # Intuition\nWe could use a for loop to iterate through list and if statements to check.\n\n# Approach\nFirst I made a list that will return at the end.\n\nSecond I created a for loop with range of n + 1 and I started it at index 1 since we didnt need to look at zero.\n\nThe if statements were pretty simple and explain... | 0 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Easy Solution | Beats : 88.23% | fizz-buzz | 0 | 1 | \n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(1)\n\n# Code\n```\ncl... | 2 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Python one-line solution beats 82% | fizz-buzz | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nList comprehension\n\n# Code\n```\nclass Solution:\n def fizzBuzz(self, n: int) -> List[str]:\n return ("FizzBuzz" if not(i%3) and not(i%5) else "Fizz" if not(i%3) else "Buzz" if not(i%5) else str(i) for i in range(1, n + 1))\n\... | 2 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Python3 readable solution using for and if | fizz-buzz | 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)$$ --... | 4 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Python 3 Beats 100.0% Simple | fizz-buzz | 0 | 1 | This solution beats 100% both experimentally and should a lot run faster than the average solution theoretically too.\n\nHere\'s the "average" solution:\n```\n def fizzBuzz(self, n: int) -> List[str]:\n arr = []\n\t\t\n for x in range(1, n + 1):\n if x % 15 == 0:\n arr.append(... | 57 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Simple Solution with python with best space and time complexity. | fizz-buzz | 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 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Python3 most easy solution | fizz-buzz | 0 | 1 | Code:\n```\nclass Solution:\n def fizzBuzz(self, n: int) -> List[str]:\n l=[]\n for i in range(1,n+1):\n if i%3==0 and i%5==0:\n l.append("FizzBuzz")\n elif i%3==0:\n l.append("Fizz")\n elif i%5==0:\n l.append("Buzz")\n ... | 1 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Oneliner! | fizz-buzz | 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)$$ --... | 16 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Simple solution with time complexity O(n) | fizz-buzz | 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(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. $$... | 2 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
Beats : 86.83% [37/145 Top Interview Question] | fizz-buzz | 0 | 1 | # Intuition\n*When seeing the FizzBuzz problem for the first time, my intuition would be to use a loop to iterate from 1 to n, and for each number, check if it is divisible by both 3 and 5, only 3, only 5, or neither. Based on the divisibility, we would append the corresponding string to a result list. At the end of th... | 3 | Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:
* `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
* `answer[i] == "Fizz "` if `i` is divisible by `3`.
* `answer[i] == "Buzz "` if `i` is divisible by `5`.
* `answer[i] == i` (as a string) if none of the above condit... | null |
413: Solution with step by step explanation | arithmetic-slices | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We define a class Solution with a function numberOfArithmeticSlices that takes in an integer list nums and returns an integer representing the number of arithmetic slices in nums.\n\n2. We initialize a counter variable co... | 2 | An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
Given an integer array `nums`, return _the number of arithmetic **subarr... | null |
Python || O(n) | arithmetic-slices | 0 | 1 | # Intuition\nI thought about dp and math in my high school\n\n# Approach\nIf the length of the input list is less than or equal to 2, there are no arithmetic slices, so we return 0.\n\n\n\n\n\n\n1.We create a list dp of length n (the length of the input list) and initialize all its elements to 0. This list will store t... | 2 | An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
Given an integer array `nums`, return _the number of arithmetic **subarr... | null |
Faster than 99.44% PYTHON 3 Simple solution | arithmetic-slices | 0 | 1 | \n\n\n**-->** Create an array of size le (le=len(A))\n\n**-->** as given \'\'A sequence of numbers is called arithmetic if it consists of at **least three elements**\'\', start for loop from 2 to le.(**because... | 72 | An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
Given an integer array `nums`, return _the number of arithmetic **subarr... | null |
Clean, Fast Python3 | O(n) Time, O(1) Space | arithmetic-slices | 0 | 1 | Please upvote if it helps! :)\n```\nclass Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:\n n, subs = len(nums), 0\n last_diff, count = None, 0\n for i in range(1, n):\n this_diff = nums[i] - nums[i - 1]\n if this_diff == last_diff:\n ... | 1 | An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
Given an integer array `nums`, return _the number of arithmetic **subarr... | null |
beginners solution, Easy to understand | arithmetic-slices | 0 | 1 | 93.60% Faster\n```\nclass Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:\n count = 0\n for i in range(len(nums)-2):\n j = i+1\n while(j<len(nums)-1):\n if nums[j]-nums[j-1] == nums[j+1]-nums[j]:\n count += 1\n ... | 3 | An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
Given an integer array `nums`, return _the number of arithmetic **subarr... | null |
Python | 99% Faster | Easy Solution✅ | third-maximum-number | 0 | 1 | ```\ndef thirdMax(self, nums: List[int]) -> int:\n nums = sorted(list(set(nums)))\n if len(nums) > 2:\n return nums[-3]\n return nums[-1]\n```\n\n | 12 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
Awesome Code Python3 | third-maximum-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)$$ --... | 5 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
one liner . easy to understand.beginner solution | third-maximum-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)$$ --... | 7 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
Python easy soln using set() fn. | third-maximum-number | 0 | 1 | # Intuition\nsorted the array in descending order to get the 3rd max number\n\n# Approach\ncreated new array (res) to remove duplicates from \'nums\'\nthen applied the conditon to return the index \'2\' where the array of lenght is more than \'3\'\nfor less than \'3\' use max(nums)\n\n# Complexity\n- Time complexity:\n... | 1 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
Easy Python solution | third-maximum-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)$$ --... | 1 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
414: Time 93.15%, Solution with step by step explanation | third-maximum-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Eliminate duplicates: First, eliminate duplicates from the input list nums using the set() method and convert it back to a list.\n2. Handle edge cases: If the length of the modified nums list is less than 3, then return t... | 3 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
O(N) Time complexity python3 | third-maximum-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)$$ --... | 6 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
using Heapq Solution | third-maximum-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)$$ --... | 4 | Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.
**Example 1:**
**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distin... | null |
Easiest Solution using unecessary variables | add-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)$$ --... | 2 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Easy Solution in Python3 | add-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)$$ --... | 1 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
LeetCode 415 | Using String Operations Only !!! | Python3 Solution | ✅ | add-strings | 0 | 1 | # Intuition\nThis approach just does addition like humans do.\n\n# Approach\n1. **Patiently** list all possibility of the addition. (It\'s stupid, but that\'s it. `:))`)\n2. Fill the leading zero to the shorter number string.\n3. Initial the carry as `0`.\n4. Iterate from the lowest digit to the highest digit.\n5. Chec... | 1 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Non-effective Python solution | add-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)$$ --... | 1 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Simple python solution | add-strings | 0 | 1 | **Method 1:**\nUse of dictionary\n```\nclass Solution:\n def addStrings(self, num1: str, num2: str) -> str:\n \n def str2int(num):\n numDict = {\'0\' : 0, \'1\' : 1, \'2\' : 2, \'3\' : 3, \'4\' : 4, \'5\' : 5,\n \'6\' : 6, \'7\' : 7, \'8\' : 8, \'9\' : 9}\n output... | 77 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Python ||Simple Code || Optimize code beats 89.6% || 2 Different way - same approach | add-strings | 0 | 1 | Approach Same but Differnent Way\nLong way -> To understand\nShort way -> To optimize \n\n# Code\n```\n<!-- Long Way -->\nclass Solution:\n def addStrings(self, num1: str, num2: str) -> str:\n # As we can\'nt use any built-in library and also not to convert input to int. So we Create Dict to handle this Prob... | 2 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
415: Solution with step by step explanation | add-strings | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Reverse the input strings num1 and num2 so that we start adding from the least significant digits.\n\n2. Pad the shorter input string with zeros so that both strings are the same length.\n\n3. Initialize an empty string r... | 14 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Single line Python Solution | add-strings | 0 | 1 | \n\n# Code\n```\nclass Solution(object):\n def addStrings(self, num1, num2):\n """\n :type num1: str\n :type num2: str\n :rtype: str\n """\n return str(int(num1)+int(num2))\n \n``` | 1 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
🔥Easy way using python🔥 | add-strings | 0 | 1 | # Intuition\nEasy way using python inbuilt functions\n\n# Approach\nconverting strings to int solve it and again convert to string\n\n# Complexity\n- Time complexity:\n- Space complexity:\n# Code\n```\nclass Solution:\n def addStrings(self, num1: str, num2: str) -> str:\n sys.set_int_max_str_digits(10000)\n ... | 4 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
[Python3] Easy Code with One Loop; guides provided | add-strings | 0 | 1 | # Approach:\nThis code uses similar logic explained in solution for question #[2 Add Two Numbers](https://leetcode.com/problems/add-two-numbers/solution/). Make sure to read that. The only difference is that here we are dealing with strings and not linked lists. The algorithm is the same as adding two numbers on a piec... | 29 | Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.
You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.
**Example 1:**
... | null |
Python Top Down memoization solution for reference | partition-equal-subset-sum | 0 | 1 | ```\nclass Solution:\n def canPartition(self, nums: List[int]) -> bool:\n def rec(i,rsum ):\n if(rsum==0): return True\n if(i==len(nums) or rsum < 0): return False \n elif(self.dp[i][rsum] != -1 ):\n return self.dp[i][rsum]\n self.dp[i][rsum]= rec(i+1... | 1 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
Python || DP || Memoization+Tabulation || Space Optimization | partition-equal-subset-sum | 0 | 1 | ```\n#Memoization (Top-Down)\n#Time Complexity: O(n*k)\n#Space Complexity: O(n) + O(n*k)\nclass Solution1:\n def canPartition(self, arr: List[int]) -> bool:\n def solve(ind,target):\n if target==0:\n return True\n if ind==0:\n return arr[ind]==target\n ... | 2 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
416: Space 99.79%, Solution with step by step explanation | partition-equal-subset-sum | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We calculate the total sum of the input array and store it in a variable called total_sum.\n2. If the total sum is odd, we cannot partition the array into two equal sum subsets, so we return False.\n3. Otherwise, we calcu... | 22 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
[Python] DP & DFS Solutions - Easy-to-understand with Explanation | partition-equal-subset-sum | 0 | 1 | ### Introduction\n\nWe want to partition `nums` into two subsets such that their sums are equal. Intuitively, we can establish that the total sum of the elements in `nums` **has to be an even number** for this to be possible:\n\n```python\nclass Solution:\n def canPartition(self, nums: List[int]) -> bool:\n\t if ... | 58 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
Easy To Undestand | DP 🚀🚀 | partition-equal-subset-sum | 1 | 1 | # Intuition\n\n\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 comp... | 2 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
✅ Dynamic Programming Top Down Approach | partition-equal-subset-sum | 0 | 1 | # Complexity\n- Time complexity: $$O(n*sum)$$.\n\n- Space complexity: $$O(n*sum)$$.\n\n# Code\n```\nclass Solution:\n def canPartition(self, nums: List[int]) -> bool:\n summ = sum(nums)\n if summ%2:\n return False\n\n self.cache = {}\n \n return self.check(nums, 0, summ/... | 10 | Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].
**E... | null |
Cleaned up public solution | pacific-atlantic-water-flow | 0 | 1 | # Desription\nCleaned up public solution https://leetcode.com/problems/pacific-atlantic-water-flow/solutions/4187974/python-bfs/\nThank you @nanzhuangdalao\n\n# Code\n```\nclass Solution:\n\n def __init__(self):\n\n self.heights = None\n self.row_l = None\n self.row_r = None\n self.direct... | 1 | There is an `m x n` rectangular island that borders both the **Pacific Ocean** and **Atlantic Ocean**. The **Pacific Ocean** touches the island's left and top edges, and the **Atlantic Ocean** touches the island's right and bottom edges.
The island is partitioned into a grid of square cells. You are given an `m x n` i... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.