question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-building-height | Java O(1) space O(klogk) time with comments. | java-o1-space-oklogk-time-with-comments-xqous | \n// This is quite similar to 135-Candy https://leetcode.com/problems/candy/\n// \n// Complexity: \n// Time: O(klogk), k is length of restrictions\n// Space: O( | janevans | NORMAL | 2021-04-25T04:02:18.617099+00:00 | 2021-04-25T20:54:59.764985+00:00 | 1,490 | false | ```\n// This is quite similar to 135-Candy https://leetcode.com/problems/candy/\n// \n// Complexity: \n// Time: O(klogk), k is length of restrictions\n// Space: O(1) no extra space is needed\n// \nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n Arrays.sort(restrictions, (a, b) -> In... | 12 | 0 | [] | 3 |
maximum-building-height | Java | O(NlogN) | java-onlogn-by-changeme-r8du | Intuition\nIf you have no limits, you can have a building with height n - 1. Example 2 in the problem.\nSequence of building: 0, 1, 2, 3, 4, 5\n\nRestrictions h | changeme | NORMAL | 2021-04-25T04:01:28.549616+00:00 | 2021-04-25T08:29:35.836062+00:00 | 861 | false | **Intuition**\nIf you have no limits, you can have a building with height `n - 1`. Example 2 in the problem.\nSequence of building: 0, 1, 2, 3, 4, 5\n\nRestrictions have effect on buildings from the left and from the right:\nExample with height restrion 1 at 3:\n0, 1, **1**, **2,** **3**, **4** ..\nThis restriction has... | 10 | 0 | [] | 1 |
maximum-building-height | Python3. O(N*log(N)). Using stack. Explanation added. | python3-onlogn-using-stack-explanation-a-llbf | \n# Logic:\n# 1. Filter out all restrictions that don\'t change anything.\n# For example:\n# there are two conditions:\n# - building with inde | yaroslav-repeta | NORMAL | 2021-04-25T04:02:40.869999+00:00 | 2021-04-25T04:54:29.104787+00:00 | 653 | false | ```\n# Logic:\n# 1. Filter out all restrictions that don\'t change anything.\n# For example:\n# there are two conditions:\n# - building with index 5 has max height 1\n# - building with index 6 has max height 10\n# we don\'t care about the second condition, because the first one is stric... | 9 | 0 | [] | 1 |
maximum-building-height | [Python] rotate by 45 | python-rotate-by-45-by-zdu011-dk20 | We can rotate all restrictions clockwise by 45 degrees. The skyline of the buildings after this rotation will be rectangles with sides parallel to x or y-axis a | zdu011 | NORMAL | 2021-04-25T04:00:43.422009+00:00 | 2021-04-25T04:10:22.940654+00:00 | 832 | false | We can rotate all restrictions clockwise by 45 degrees. The skyline of the buildings after this rotation will be rectangles with sides parallel to x or y-axis and the highest buildings correspond to the corners of these rectangles.\n\n```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]... | 7 | 0 | [] | 1 |
maximum-building-height | [Python3] greedy | python3-greedy-by-ye15-lhja | \n\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n restrictions.extend([[1, 0], [n, n-1]])\n restrict | ye15 | NORMAL | 2021-04-25T04:02:06.522071+00:00 | 2021-04-25T16:15:09.447931+00:00 | 497 | false | \n```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n restrictions.extend([[1, 0], [n, n-1]])\n restrictions.sort()\n \n for i in reversed(range(len(restrictions)-1)): \n restrictions[i][1] = min(restrictions[i][1], restrictions[i+1][1]... | 6 | 2 | ['Python3'] | 0 |
maximum-building-height | C++ Filter Critical Restrictions | c-filter-critical-restrictions-by-lzl124-iaa1 | See my latest update in repo LeetCode\n## Solution 1. Filter Critical Restrictions\n\nWe should remove the useless restrictions and only keep the critical ones. | lzl124631x | NORMAL | 2021-04-25T04:00:35.550917+00:00 | 2021-04-25T05:12:00.183994+00:00 | 822 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1. Filter Critical Restrictions\n\nWe should remove the useless restrictions and only keep the critical ones.\n\n### Step 1. Remove Useless Restrictions\n\nPut all the restrictions into a `m` which is a map from the `x` value t... | 6 | 0 | [] | 0 |
maximum-building-height | Java DP O(mlogm) | java-dp-omlogm-by-mayank12559-kfvx | \npublic int maxBuilding(int n, int[][] restrictions) {\n int m = restrictions.length;\n if(m == 0){\n return n-1;\n }\n | mayank12559 | NORMAL | 2021-04-25T04:00:36.481490+00:00 | 2021-04-30T16:14:18.380715+00:00 | 440 | false | ```\npublic int maxBuilding(int n, int[][] restrictions) {\n int m = restrictions.length;\n if(m == 0){\n return n-1;\n }\n Arrays.sort(restrictions, (a,b) -> a[0]-b[0]);\n int []dp = new int[m]; // dp[i] => maximum allowed height at restriction[i][0]th building\n dp... | 5 | 1 | [] | 0 |
maximum-building-height | JAVA Solution | java-solution-by-himanshuchhikara-l5gv | EXPLANATION:\n\nyou can see in the given example first we need to reduce height of 11 from left i.e to 5 . then from right i.e to 4. So we need two iteration o | himanshuchhikara | NORMAL | 2021-04-25T09:55:57.732666+00:00 | 2021-04-29T04:42:42.485720+00:00 | 746 | false | **EXPLANATION:**\n\nyou can see in the given example first we need to reduce height of 11 from left i.e to 5 . then from right i.e to 4. So we need two iteration one from left and then one from right.\nAnd I h... | 4 | 0 | ['Java'] | 1 |
maximum-building-height | [Python] Math - McShane extension operator | python-math-mcshane-extension-operator-b-5cn8 | The solution to this problem can be viewed as mild generalization of McShane\'s extension theorem, which is an easy special case of Kirszbraun\'s theorem. McSha | kevinfederline | NORMAL | 2021-04-25T04:56:30.615841+00:00 | 2021-04-25T04:58:46.017966+00:00 | 325 | false | The solution to this problem can be viewed as mild generalization of McShane\'s extension theorem, which is an easy special case of [Kirszbraun\'s theorem](https://en.wikipedia.org/wiki/Kirszbraun_theorem). McShane\'s theorem concerns extension of functions satisfying a Lipschitz condition. Specifically, suppose E is a... | 4 | 0 | [] | 1 |
maximum-building-height | [Java] Greedy Clean Solution with explanation - O(mlogm) | java-greedy-clean-solution-with-explanat-1hix | Use Greedy idea\n\nlike leetcode 135, it\'s a two pass greedy problem\n\n time: O(mlogm)\n space: O(m)\n \n\n### step 0. clone a new array, add 2 more | timmybeeflin | NORMAL | 2021-08-27T14:35:48.254290+00:00 | 2021-10-07T13:46:52.218523+00:00 | 336 | false | ## Use Greedy idea\n\nlike leetcode 135, it\'s a two pass greedy problem\n\n time: O(mlogm)\n space: O(m)\n \n\n### step 0. clone a new array, add 2 more space\n\nr[r.length-2] = new int[]{1, 0}; // add first building\nr[r.length-1] = new int[]{n, 1_000_000_000}; // add n building\n\ndo sort, make position rig... | 3 | 0 | [] | 0 |
maximum-building-height | Runtime beats 92.00% [EXPLAINED] | runtime-beats-9200-explained-by-r9n-bkoc | Intuition\nFinding the tallest possible building height under specific constraints, where the height of buildings must not exceed given limits, and heights must | r9n | NORMAL | 2024-10-17T08:10:28.739485+00:00 | 2024-10-17T08:10:28.739516+00:00 | 61 | false | # Intuition\nFinding the tallest possible building height under specific constraints, where the height of buildings must not exceed given limits, and heights must gradually increase or decrease by at most one between adjacent buildings.\n\n# Approach\nStart by adding the first and last buildings to the restrictions, so... | 2 | 0 | ['Python3'] | 0 |
maximum-building-height | [C++] O(n log n) Greedy + Sorting | c-on-log-n-greedy-sorting-by-alexunxus-ldlx | Intuition and Approach\n Describe your first thoughts on how to solve this problem. \n\n## First step: Make restrictions achievable!\nFirstly, the restrictions | alexunxus | NORMAL | 2023-02-03T02:42:15.318436+00:00 | 2023-02-03T03:28:25.674017+00:00 | 144 | false | # Intuition and Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n## First step: Make restrictions achievable!\nFirstly, the restrictions may not hold true due to the constraint "the height differences between every two adjacent building should not exceed 1". For example:\n\n```\n0 2 ... | 2 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
maximum-building-height | (C++) 1840. Maximum Building Height | c-1840-maximum-building-height-by-qeetco-q1mr | \n\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n restrictions.pu | qeetcode | NORMAL | 2021-04-25T16:50:11.674877+00:00 | 2021-04-25T16:50:11.674915+00:00 | 355 | false | \n```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n restrictions.push_back({n, n-1}); \n sort(restrictions.begin(), restrictions.end()); \n for (int i = restrictions.size()-2; i >= 0; --i) {\n restri... | 2 | 0 | ['C'] | 0 |
maximum-building-height | C++ Solution | c-solution-by-6cdh-v70o | The restriction of a[i] affects the buildings after and before it. So I scan the array twice to spread the restricton of a[i].\n\nThe restriction array a splits | 6cdh | NORMAL | 2021-04-25T12:22:09.320975+00:00 | 2021-04-25T12:28:08.700766+00:00 | 230 | false | The restriction of `a[i]` affects the buildings after and before it. So I scan the array twice to spread the restricton of `a[i]`.\n\nThe restriction array `a` splits the `n` buildings into some segments. We can calculate the tallest building of each segments and get the tallest one of all buildings.\n\nTo maximize the... | 2 | 0 | ['C'] | 0 |
maximum-building-height | [C++] clean code and detailed explanation | c-clean-code-and-detailed-explanation-by-fz6w | At first , it\'s not difficult to work out the max height between two buildings.\n\nCase study\n\nconsidering the following restractions:\n\n1) Building #1 max- | haoel | NORMAL | 2021-04-25T08:29:27.406041+00:00 | 2021-04-25T08:43:03.009814+00:00 | 285 | false | At first , it\'s not difficult to work out the max height between two buildings.\n\n**Case study**\n\nconsidering the following restractions:\n\n1) Building #1 `max-height = 1`, Building #5 `max-height = 1`\n then we can have the building height list - `[1,2,3,2,1] `\n\n2) Building #1 `max-height = 3`, Building #5 ... | 2 | 0 | [] | 1 |
maximum-building-height | My solution with thinking progress | my-solution-with-thinking-progress-by-me-icgf | Intuition\n Describe your first thoughts on how to solve this problem. \n- We want to build the highest building, but there are restrictions. So, we want to "ut | mercedes | NORMAL | 2024-04-27T09:11:57.396594+00:00 | 2024-04-27T09:11:57.396620+00:00 | 49 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We want to build the highest building, but there are restrictions. So, we want to "utilize" each restriction to its maximum.\n- That is, for each restricted buildings, we try to make it as tall as possible.\n- We iterate from left. We o... | 1 | 0 | ['C++'] | 0 |
maximum-building-height | Beats 100% C++ 2 Passes | beats-100-c-2-passes-by-tangd6-bket | First, notice that starting from the back, there is a fixed limit. In between this value and the value in front of it, there is only a certain amount of space. | tangd6 | NORMAL | 2024-01-24T02:52:27.575933+00:00 | 2024-01-24T02:52:27.575960+00:00 | 308 | false | First, notice that starting from the back, there is a fixed limit. In between this value and the value in front of it, there is only a certain amount of space. Thus, the maximum the previous value can be is actually LIMIT + DISTANCE since any higher than that, it will not be able to \'come back down\'.\n\nSo, I created... | 1 | 0 | ['C++'] | 0 |
maximum-building-height | Sorting and Two Passes in Python | sorting-and-two-passes-in-python-by-meta-ru9n | Approach\n Describe your approach to solving the problem. \nThe first step is to sort the restrictions according to their positions. \nThe first pass begins fro | metaphysicalist | NORMAL | 2023-04-18T05:10:49.212506+00:00 | 2023-04-18T05:10:49.212547+00:00 | 151 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nThe first step is to sort the restrictions according to their positions. \nThe first pass begins from the rightmost to the leftmost for setting new height restriction of i according to the height restriction of its right parter (i+1).\nThe second pass... | 1 | 0 | ['Greedy', 'Sorting', 'Python3'] | 0 |
maximum-building-height | Clean solution with detailed explanation and comments | clean-solution-with-detailed-explanation-j4vv | Intuition\nYou cannot iterate on each step, because that will be too many. Need think of a solution that involves the restrictions only.\nThe height at each res | sujoychatts | NORMAL | 2023-03-14T17:51:14.149791+00:00 | 2023-03-14T17:51:14.149838+00:00 | 55 | false | # Intuition\nYou cannot iterate on each step, because that will be too many. Need think of a solution that involves the restrictions only.\nThe height at each restriction point is determined not only by its own restriction but also by the restrictions on its left and right. That is because you can increment / decrement... | 1 | 0 | ['JavaScript'] | 0 |
maximum-building-height | Simple Java Solution | simple-java-solution-by-aayushkumar20-s9ag | \n// Maximum Building Height\n// Leetcode: https://leetcode.com/problems/maximum-building-height/\n\nclass Solution {\n public int maxBuilding(int n, int[][] | aayushkumar20 | NORMAL | 2022-10-10T14:50:55.782876+00:00 | 2022-10-10T14:50:55.782969+00:00 | 232 | false | ```\n// Maximum Building Height\n// Leetcode: https://leetcode.com/problems/maximum-building-height/\n\nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) \n {\n int[][] arr = new int[restrictions.length + 2][2];\n arr[0][0] = 1;\n arr[0][1] = 0;\n arr[arr.length - ... | 1 | 0 | ['Java'] | 0 |
maximum-building-height | Prefix + suffix Array | prefix-suffix-array-by-diyora13-o5pg | \nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& a) \n {\n a.push_back({1,0});\n a.push_back({n,n-1});\n int | diyora13 | NORMAL | 2022-06-08T07:10:11.899414+00:00 | 2022-06-08T07:10:11.899454+00:00 | 405 | false | ```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& a) \n {\n a.push_back({1,0});\n a.push_back({n,n-1});\n int m=a.size();\n if(!m) return n-1;\n sort(a.begin(),a.end());\n int mn[m];\n for(int i=0;i<m;i++)\n mn[i]=INT_MAX;\n ... | 1 | 0 | ['Greedy', 'C', 'Sorting', 'C++'] | 0 |
maximum-building-height | Faster than 100% || C++ | faster-than-100-c-by-i_see_you-mvod | \nclass Solution {\npublic:\n /*\n Hint: \n 1. Dp\n 2. We know that the 1st building is of height 0, and some other buildings ha | i_see_you | NORMAL | 2022-05-05T11:47:33.633042+00:00 | 2022-05-05T11:47:53.113897+00:00 | 201 | false | ```\nclass Solution {\npublic:\n /*\n Hint: \n 1. Dp\n 2. We know that the 1st building is of height 0, and some other buildings have some restriction on their heights\n 3. If we go from left to right, we will notice every left restiction height can affect to it\'s just right ... | 1 | 0 | [] | 0 |
maximum-building-height | Javascript explained | javascript-explained-by-theesoteric-pd5n | \n/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n let maxHeight=0;\ | theesoteric | NORMAL | 2022-02-13T17:55:16.053560+00:00 | 2022-02-13T17:55:16.053604+00:00 | 150 | false | ```\n/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n let maxHeight=0;\n restrictions.push([1,0]);//Push extra restriction as 0 for 1\n restrictions.push([n,n-1]);//Push extra restrition as n-1 for n\n restrictions.sort... | 1 | 0 | ['JavaScript'] | 0 |
maximum-building-height | Python O(m log m) Solution with Clear Explanation and Analysis | python-om-log-m-solution-with-clear-expl-cgo4 | In the begining, the first solution we may think about is: \n* compute every buildings height and get the maximum of them\n\nBut this will give you TLE, so we m | taranthemonk | NORMAL | 2022-01-19T11:59:00.694001+00:00 | 2022-01-19T11:59:28.067056+00:00 | 167 | false | In the begining, the first solution we may think about is: \n* compute every buildings height and get the maximum of them\n\nBut this will give you TLE, so we must ask ourselves, do I really need to know the height for all buildings to know what is the maximum height I can get?\n\nLet me try to explain the analysis pro... | 1 | 0 | ['Sorting'] | 0 |
maximum-building-height | Simple Stack Solution, O(N) after sorting, O(1) space | simple-stack-solution-on-after-sorting-o-s91q | Each restriction at (x,y) means restrictions at (x\xB1i, y+i) for all buildings, that is, each origin restriction is a vertical V shape angle. We will find the | slo | NORMAL | 2021-05-04T09:44:31.474167+00:00 | 2021-05-04T09:56:13.250121+00:00 | 387 | false | Each restriction at `(x,y)` means restrictions at `(x\xB1i, y+i)` for all buildings, that is, each origin restriction is a vertical `V` shape angle. We will find the highest point on lower boundary of all `V`s.\nYou may reuse the `restrictions` argument for O(1) space.\n```c++\n/*\nn = 5, restrictions = [[2,1],[4,1]]\n... | 1 | 0 | [] | 0 |
maximum-building-height | 67% : Python | 67-python-by-tuhinnn_py-cwuf | We initially sort the restrictions array just to keep the building indices in ascending order. Now suppose, the restrictions array looks something like this\nA | tuhinnn_py | NORMAL | 2021-05-02T18:10:14.678263+00:00 | 2021-05-02T18:10:14.678320+00:00 | 202 | false | ***We initially sort the restrictions array just to keep the building indices in ascending order. Now suppose, the restrictions array looks something like this\nA = [...., [id1, h1], [id2, h2], ...] which suggests, you have two buildings restricted by heights h1 and h2 and spaced by id2 - id1\nHere\'s my claim, Buildin... | 1 | 0 | [] | 0 |
maximum-building-height | [Golang] Go two-pass solution | golang-go-two-pass-solution-by-grokus-zs4n | ```\nfunc maxBuilding(n int, a [][]int) int {\n\ta = append(a, [][]int{{1, 0}, {n, n - 1}}...)\n\tsort.Slice(a, func(i, j int) bool { return a[i][0] < a[j][0] } | grokus | NORMAL | 2021-04-25T18:56:19.044426+00:00 | 2021-04-25T18:56:36.702058+00:00 | 63 | false | ```\nfunc maxBuilding(n int, a [][]int) int {\n\ta = append(a, [][]int{{1, 0}, {n, n - 1}}...)\n\tsort.Slice(a, func(i, j int) bool { return a[i][0] < a[j][0] })\n\tres := 0\n\tfor i := len(a) - 2; i >= 0; i-- {\n\t\ta[i][1] = min(a[i][1], a[i+1][1]+a[i+1][0]-a[i][0])\n\t}\n\tfor i := 1; i < len(a); i++ {\n\t\ta[i][1] ... | 1 | 0 | [] | 0 |
maximum-building-height | Simple java solution with explanation comments - Time: O(k log k), Space: O(1) | simple-java-solution-with-explanation-co-iwgj | Same approach as this post by Janevans\n\n\nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n // If there are no restrictions | hss15 | NORMAL | 2021-04-25T10:56:55.636663+00:00 | 2021-04-25T11:00:21.195266+00:00 | 180 | false | Same approach as [this post](https://leetcode.com/problems/maximum-building-height/discuss/1175058/Java-O(1)-space-O(klogk)-time-with-comments) by [Janevans](https://leetcode.com/janevans/)\n\n```\nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n // If there are no restrictions, we w... | 1 | 0 | [] | 0 |
maximum-building-height | 1840. Maximum Building Height | 1840-maximum-building-height-by-g8xd0qpq-8f6q | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-15T13:50:46.649333+00:00 | 2025-01-15T13:50:46.649333+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
maximum-building-height | Simple 3 pass solutions, beats all | simple-3-pass-solutions-beats-all-by-sup-nyvc | 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 | supercmmetry | NORMAL | 2024-11-07T14:15:41.535479+00:00 | 2024-11-07T14:15:41.535505+00:00 | 1 | false | # 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 | 0 | ['Rust'] | 0 |
maximum-building-height | C++ beats 100% in 30ms | c-beats-100-in-30ms-by-ivangnilomedov-127o | Code\ncpp []\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n // Step 1: Prepare and sort restrictions\n | ivangnilomedov | NORMAL | 2024-10-20T16:31:05.266293+00:00 | 2024-10-20T16:31:05.266330+00:00 | 4 | false | # Code\n```cpp []\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n // Step 1: Prepare and sort restrictions\n vector<pair<int, int>> id_restr(restrictions.size() + 1);\n transform(restrictions.begin(), restrictions.end(), id_restr.begin() + 1,\n ... | 0 | 0 | ['C++'] | 0 |
maximum-building-height | 1840. Maximum Building Height.cpp | 1840-maximum-building-heightcpp-by-20202-9lpq | Code\n\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n restriction | 202021ganesh | NORMAL | 2024-10-17T10:07:19.077233+00:00 | 2024-10-17T10:07:19.077260+00:00 | 0 | false | **Code**\n```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n restrictions.push_back({n, n-1}); \n sort(restrictions.begin(), restrictions.end()); \n for (int i = restrictions.size()-2; i >= 0; --i) {\n ... | 0 | 0 | ['C'] | 0 |
maximum-building-height | optimized solution | optimized-solution-by-sbishnoi29-xpwu | 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 | sbishnoi29 | NORMAL | 2024-09-20T20:46:56.182835+00:00 | 2024-09-20T20:46:56.182859+00:00 | 3 | false | # 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 | 0 | ['C++'] | 0 |
maximum-building-height | C++ | c-by-tinachien-l6gg | \nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n int ret;\n restrictions.push_back({1,0});\n | TinaChien | NORMAL | 2024-09-15T02:10:51.373213+00:00 | 2024-09-15T02:10:51.373231+00:00 | 0 | false | ```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& restrictions) {\n int ret;\n restrictions.push_back({1,0});\n sort(restrictions.begin(), restrictions.end());\n int m = restrictions.size();\n vector<int>pos(m);\n vector<int>height(m);\n vec... | 0 | 0 | [] | 0 |
maximum-building-height | C++ 11 line | c-11-line-by-sanzenin_aria-crkv | 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 | sanzenin_aria | NORMAL | 2024-08-27T22:42:33.849594+00:00 | 2024-08-27T22:42:33.849618+00:00 | 0 | false | # 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:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int... | 0 | 0 | ['C++'] | 0 |
maximum-building-height | Python 3: TC O(N log(N)), SC O(N): Sort plus Three Passes. Two Passes and SC O(log(N)) Possible | python-3-tc-on-logn-sc-on-sort-plus-thre-26k4 | Intuition\n\nThis is a hard problem to get the insight for.\n\n## Array-of-Limits Pattern in General\n\nThe usual pattern for this, trapping rain water, distrib | biggestchungus | NORMAL | 2024-07-08T20:47:06.566224+00:00 | 2024-07-08T20:47:06.566244+00:00 | 13 | false | # Intuition\n\nThis is a hard problem to get the insight for.\n\n## Array-of-Limits Pattern in General\n\nThe usual pattern for this, trapping rain water, distributing candies, etc. is to look at some index `i`\n* usually the value for `i` (this case height) has some limits\n* there\'s a left limit, from a restriction ... | 0 | 0 | ['Python3'] | 0 |
maximum-building-height | Sorting || C++ | sorting-c-by-scraper_nerd-g9yn | \n\n# Code\n\nclass Solution {\npublic:\n int nerd(vector<int>&v1,vector<int>&v2){\n int x1=v1[0];\n int y1=v1[1];\n int x2=v2[0];\n | Scraper_Nerd | NORMAL | 2024-06-13T17:42:25.191310+00:00 | 2024-06-13T17:42:25.191339+00:00 | 22 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int nerd(vector<int>&v1,vector<int>&v2){\n int x1=v1[0];\n int y1=v1[1];\n int x2=v2[0];\n int y2=v2[1];\n int x=(x1-y1+x2+y2)/2.0;\n int y=x-x1+y1;\n return y;\n }\n int maxBuilding(int n, vector<vector<int>>& v) {\n... | 0 | 0 | ['C++'] | 0 |
maximum-building-height | Three passes O(len(restrictions)), beating 98.53% in python | three-passes-olenrestrictions-beating-98-fl5u | This is really not an easy \'hard\'.\n\nFirst, note n could be as much as 10e9, which is too much for a typical O(n) leetcode question. So definitely we should | MaxOrgus | NORMAL | 2023-12-27T02:56:43.511846+00:00 | 2023-12-27T02:56:43.511867+00:00 | 18 | false | This is really not an easy \'hard\'.\n\nFirst, note n could be as much as 10e9, which is too much for a typical O(n) leetcode question. So definitely we should not consider looping through n, which was I attempted at first, and resulted in TLE.\n\nIn stead, we focus only on the points where restrictions are casted, who... | 0 | 0 | ['Dynamic Programming', 'Python3'] | 1 |
maximum-building-height | [RUNTIME 100%] | runtime-100-by-gztyss-mib1 | Intuition\n Describe your first thoughts on how to solve this problem. \n- Each restriction point can create line by:\ny = x + (x_1-y_1) #for slope 1 and point | GzTyss | NORMAL | 2023-12-26T17:02:51.857127+00:00 | 2023-12-26T17:02:51.857163+00:00 | 153 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Each restriction point can create line by:\n$$y = x + (x_1-y_1) $$ #for slope 1 and point [x1,y1]\n$$y = -x + (x_2+y_2) $$ #for slope -1 and point [x2,y2]\n- for Increment line, if (x1-y1)==(x2-y2) -> both point is same line \n- for Dec... | 0 | 0 | ['Python3'] | 1 |
maximum-building-height | Unique approach,Explanation added | unique-approachexplanation-added-by-rish-xvzg | \n//dry run for better understanding \nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& arr) {\n arr.push_back({1,0}); //always | rishabhprasanna | NORMAL | 2023-08-02T13:21:42.179183+00:00 | 2023-08-02T13:21:42.179223+00:00 | 28 | false | ```\n//dry run for better understanding \nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& arr) {\n arr.push_back({1,0}); //always a constraint \n sort(arr.begin(),arr.end());\n //sorting ids of buildings \n int m=arr.size();\n vector<int>mark(m,arr[m-1][1]);... | 0 | 0 | ['Sorting', 'Binary Tree'] | 0 |
maximum-building-height | Simple and fast C++ SOLUTION | simple-and-fast-c-solution-by-kevinjoyth-c54x | 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 | kevinjoythomas7 | NORMAL | 2023-06-14T17:41:46.119703+00:00 | 2023-06-14T17:41:46.119720+00:00 | 124 | false | # 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 | 0 | ['C++'] | 0 |
maximum-building-height | Python || sort, greedy || O(m log m) | python-sort-greedy-om-log-m-by-hanna9221-ea3l | Add [1,0] to restrictions, then sort restrictions by index in ascending order.\n2. We will do the same procedure twice, forward and backward. The procedure is a | hanna9221 | NORMAL | 2023-04-15T12:16:14.955239+00:00 | 2023-04-15T12:44:15.382628+00:00 | 139 | false | 1. Add `[1,0]` to `restrictions`, then sort `restrictions` by index in ascending order.\n2. We will do the same procedure twice, forward and backward. The procedure is as following:\n2-1. Move to `(idx_2, res_2)` and check previous `(idx_1, res_1)`. \n2-2. Let `steps = abs(idx_1-idx_2)`. Starting from `idx_1`, the maxi... | 0 | 0 | ['Python3'] | 0 |
maximum-building-height | BS ON ANSWER | bs-on-answer-by-shivral-hwiq | \n\n# Code\n\nclass Solution:\n def maxBuilding(self, n: int, rt: List[List[int]]) -> int:\n rt.append([0,-1])\n rt.append([n,float("inf")])\n | shivral | NORMAL | 2023-03-23T09:04:01.157294+00:00 | 2023-03-23T09:04:01.157322+00:00 | 91 | false | \n\n# Code\n```\nclass Solution:\n def maxBuilding(self, n: int, rt: List[List[int]]) -> int:\n rt.append([0,-1])\n rt.append([n,float("inf")])\n rt.sort()\n n=len(rt)\n for i in range(1,n):\n rt[i][1]=min(rt[i][0]-rt[i-1][0]+rt[i-1][1],rt[i][1])\n for i in range(... | 0 | 0 | ['Python3'] | 0 |
maximum-building-height | Python (Simple Maths) | python-simple-maths-by-rnotappl-1dv8 | 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 | rnotappl | NORMAL | 2023-03-14T16:27:02.072483+00:00 | 2023-03-14T16:27:02.072509+00:00 | 85 | false | # 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 | 0 | ['Python3'] | 0 |
maximum-building-height | Just a runnable solution | just-a-runnable-solution-by-ssrlive-5h0p | Code\n\nimpl Solution {\n pub fn max_building(n: i32, restrictions: Vec<Vec<i32>>) -> i32 {\n fn pass(r: &mut Vec<Vec<i32>>) -> i32 {\n let | ssrlive | NORMAL | 2023-02-23T11:01:45.574942+00:00 | 2023-02-23T11:01:45.574974+00:00 | 26 | false | # Code\n```\nimpl Solution {\n pub fn max_building(n: i32, restrictions: Vec<Vec<i32>>) -> i32 {\n fn pass(r: &mut Vec<Vec<i32>>) -> i32 {\n let mut res = 0;\n for i in 0..r.len() - 1 {\n let h1 = r[i][1];\n let h2 = r[i + 1][1];\n let mut h =... | 0 | 0 | ['Rust'] | 0 |
maximum-building-height | C# Solution | c-solution-by-m67186636-a6by | 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 | m67186636 | NORMAL | 2023-02-04T14:08:04.188654+00:00 | 2023-02-04T14:08:04.188687+00:00 | 39 | false | # 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 | 0 | ['C#'] | 0 |
maximum-building-height | 91.43% Faster || Adjust Previous Tower height based on the ones next to it | 9143-faster-adjust-previous-tower-height-a9dh | 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 | recker2903 | NORMAL | 2023-01-29T19:27:58.653861+00:00 | 2023-01-29T19:28:33.538149+00:00 | 152 | false | # 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 | 0 | ['Sorting', 'C++'] | 0 |
maximum-building-height | Python 6-lines | python-6-lines-by-mfatihuslu-v92x | Intuition\n Describe your first thoughts on how to solve this problem. \n\nFirst, sort restrictions with respect to first limiting the height of buildings when | mfatihuslu | NORMAL | 2022-12-21T19:04:15.787794+00:00 | 2022-12-21T19:05:42.889168+00:00 | 121 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nFirst, sort restrictions with respect to first limiting the height of buildings when we traverse line from left to right.\n\nThen, traverse through array and store rightmost restriction in every point. In every comparison, leftmost and ... | 0 | 0 | ['Python3'] | 0 |
maximum-building-height | Presumably fast solution, nothing to compare to | presumably-fast-solution-nothing-to-comp-3kuu | Intuition\n Describe your first thoughts on how to solve this problem. \nIt is enough to look for maximum heights at each restricted buinding and at the maximum | mbeceanu | NORMAL | 2022-11-21T23:22:10.771416+00:00 | 2022-11-21T23:22:10.771453+00:00 | 87 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is enough to look for maximum heights at each restricted buinding and at the maximum points between each pair of consecutive restricted buildings.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI did it in thre... | 0 | 0 | ['Python'] | 0 |
maximum-building-height | TC: O(N) SC: O(1) Greedy Approach Explained Python | tc-on-sc-o1-greedy-approach-explained-py-5187 | For each building you want to find the most constraining height either on left or right\nm = len(restrictions) <= 10^5 so O(m^2) is too slow\nBut we can find bi | sarthakBhandari | NORMAL | 2022-10-08T14:36:38.031388+00:00 | 2022-10-08T14:40:27.218995+00:00 | 83 | false | For each building you want to find the most constraining height either on left or right\nm = len(restrictions) <= 10^5 so O(m^2) is too slow\nBut we can find biggest restriction on left for each element is one loop, and\nfind the biggest restriction on right for each element in one loop aswell\n\nlet curr biggest restr... | 0 | 0 | ['Python3'] | 0 |
maximum-building-height | simple c++ sol | simple-c-sol-by-adtyaofficial17-f79d | ```\nclass Solution {\npublic:\n int maxBuilding(int n, vector>& res) {\n \n if(res.size()==0)\n return n-1;\n \n vect | AdityaGupta-Official | NORMAL | 2022-08-26T18:51:17.295523+00:00 | 2022-08-26T18:51:17.295563+00:00 | 66 | false | ```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& res) {\n \n if(res.size()==0)\n return n-1;\n \n vector<int> mad={1,0};\n sort(res.begin(),res.end());\n res.insert(res.begin(),mad);\n /* for(auto it:res)\n {\n c... | 0 | 0 | [] | 0 |
maximum-building-height | Java | Trim Backward, then Count Forward | java-trim-backward-then-count-forward-by-qahn | First, make the restriction counts, that is, if we have a [10, 0], and [9,9] trim that [9,9] such that it becomes the actual limit, i.e. [9,1]. This will be imp | Student2091 | NORMAL | 2022-07-31T22:21:34.090141+00:00 | 2022-07-31T22:25:15.320783+00:00 | 154 | false | 1. First, make the restriction counts, that is, if we have a `[10, 0]`, and `[9,9]` trim that `[9,9]` such that it becomes the actual limit, i.e. `[9,1]`. This will be important for the math we need later. \n\n2. Then, we start from building 1, set `x = 1, y = 0`, meaning the current height is at 0 with `x` at 1. For e... | 0 | 0 | ['Math', 'Java'] | 0 |
maximum-building-height | 100% faster | O(nlogn) | Well commented | 100-faster-onlogn-well-commented-by-yezh-f30h | We process in 3 steps.\n\n1. Left->right. Update height restriction on (i + 1)-th building based on restriction on i-th build \n2. Right->left\n3. For adjacent | yezhizhen | NORMAL | 2022-04-15T07:41:48.411210+00:00 | 2022-04-15T07:49:06.037680+00:00 | 170 | false | We process in 3 steps.\n\n1. Left->right. Update height restriction on (i + 1)-th building based on restriction on i-th build \n2. Right->left\n3. For adjacent two restrictions, let h be the height restriction differences, x be the difference in x-axis. \nAssume you go up "a" steps and down by "x-a" steps,\nSolve equat... | 0 | 0 | ['C'] | 0 |
maximum-building-height | Python | 3 passes | O(nlogn) | python-3-passes-onlogn-by-aryonbe-xm4r | \nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n arr = restrictions\n arr.extend([[1,0],[n,n-1]])\n | aryonbe | NORMAL | 2022-03-24T01:37:19.965754+00:00 | 2022-04-22T12:58:28.006995+00:00 | 208 | false | ```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n arr = restrictions\n arr.extend([[1,0],[n,n-1]])\n arr.sort()\n n = len(arr)\n for i in range(1,n):\n arr[i][1] = min(arr[i][1], arr[i-1][1]+arr[i][0]-arr[i-1][0])\n for ... | 0 | 0 | ['Python'] | 1 |
maximum-building-height | C++ O(N * LogN) time and O(1) | Fast and easy to understand (N is the length of the array) | c-on-logn-time-and-o1-fast-and-easy-to-u-jzau | \nint maxBuilding(int k, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n int n = restrictions.size();\n sort(restr | dineshbs444 | NORMAL | 2022-02-19T19:38:18.307167+00:00 | 2022-02-19T19:38:18.307194+00:00 | 238 | false | ```\nint maxBuilding(int k, vector<vector<int>>& restrictions) {\n restrictions.push_back({1, 0});\n int n = restrictions.size();\n sort(restrictions.begin(), restrictions.end());\n for(int i = 0 ; i < n - 1; i++) {\n int distance = restrictions[i + 1][0] - restrictions[i][0];\n ... | 0 | 0 | ['C', 'C++'] | 0 |
maximum-building-height | Golang heap solution, beats 100% | golang-heap-solution-beats-100-by-tjucod-9tod | go\nfunc maxBuilding(n int, restrictions [][]int) int {\n\t// no restrictions, increase one by one\n\tif len(restrictions) == 0 {\n\t\treturn n-1\n\t}\n\t// sor | tjucoder | NORMAL | 2022-01-06T09:15:03.391284+00:00 | 2022-01-06T09:15:03.391329+00:00 | 100 | false | ```go\nfunc maxBuilding(n int, restrictions [][]int) int {\n\t// no restrictions, increase one by one\n\tif len(restrictions) == 0 {\n\t\treturn n-1\n\t}\n\t// sort by index\n\tsort.Slice(restrictions, func(i, j int) bool {\n\t\treturn restrictions[i][0] < restrictions[j][0]\n\t})\n\t// make height valid\n\tfor _, rest... | 0 | 0 | ['Heap (Priority Queue)', 'Go'] | 0 |
maximum-building-height | [Python] Beats 100%, sort + one pass solution, O(nlog(n)) | python-beats-100-sort-one-pass-solution-mdpys | I have I think a pretty unique solution, using a single-pass approach to find the max height.\n\nThe main idea of the solution is to "follow the path" of maximu | skasch | NORMAL | 2021-12-11T22:56:39.213429+00:00 | 2021-12-11T22:56:39.213466+00:00 | 263 | false | I have I think a pretty unique solution, using a single-pass approach to find the max height.\n\nThe main idea of the solution is to "follow the path" of maximum building heights by iterating over the most restrictive restrictions along the indexes.\n\nIf we are at a given restriction `i1, h1`, then we can look at all ... | 0 | 0 | ['Sorting', 'Python', 'Python3'] | 0 |
maximum-building-height | Will this solution work for N ~ 1e7 Passing 36/50 Cases | will-this-solution-work-for-n-1e7-passin-0qwr | I have tried to calculate the max_possible_height for all buildings based on the restrictions given .then using the cur_height variable which increments by 1 be | stunnareeb_09 | NORMAL | 2021-06-11T12:13:49.734083+00:00 | 2021-06-11T12:13:49.734125+00:00 | 138 | false | I have tried to calculate the max_possible_height for all buildings based on the restrictions given .then using the `cur_height` variable which increments by 1 between adjacent buildings have calculated the actual possible height `actual_height` which can be attained , then their are chances that the current possible h... | 0 | 0 | [] | 1 |
maximum-building-height | From O(n) to O(mlgm) Two Solutions | from-on-to-omlgm-two-solutions-by-xu_daf-lf3i | \nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n \'\'\'\n # O(n), TLE/MLE\n # Each buliding is | xu_dafang | NORMAL | 2021-05-25T23:58:59.731857+00:00 | 2021-05-25T23:58:59.731898+00:00 | 287 | false | ```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n \'\'\'\n # O(n), TLE/MLE\n # Each buliding is restricted from left and right. Thus, update the height of the building from left to right and then from right to left\n H = [float("inf") for _ in r... | 0 | 0 | [] | 0 |
maximum-building-height | Python3 easy to understand | python3-easy-to-understand-by-randomrock-2u3y | \nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n res = restrictions + [[1,0]] # for ease of processing, sett | RandomRock | NORMAL | 2021-05-17T22:12:27.097400+00:00 | 2021-05-17T22:15:11.831430+00:00 | 264 | false | ```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n res = restrictions + [[1,0]] # for ease of processing, setting a 0-height restraint for the first building\n res = sorted(res, key=lambda x:x[0])\n if res[-1][0] != n:\n res += [[n, float(\'i... | 0 | 0 | [] | 0 |
maximum-building-height | Python3 O(NlogN) | python3-onlogn-by-xy_nu-zu19 | \nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n if not restrictions:\n return n-1\n resi | xy_nu | NORMAL | 2021-05-17T05:51:02.722975+00:00 | 2021-05-17T05:51:02.723008+00:00 | 176 | false | ```\nclass Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:\n if not restrictions:\n return n-1\n resi = sorted(restrictions, key = lambda x:x[0])\n \n # update resi\n k = 0\n idx = 1\n for resii in resi:\n resii[1... | 0 | 0 | [] | 0 |
maximum-building-height | [ruby] O(n) solution | ruby-on-solution-by-tuang3142-d1pq | Idea\n\nThanks votrubac for the original idea\nGoing from left to right, let\'s find the maximum height h between two limits: h1 and h2 which are indexed i and | tuang3142 | NORMAL | 2021-05-15T03:31:51.856691+00:00 | 2021-05-15T03:39:58.143310+00:00 | 141 | false | **Idea**\n\n[Thanks votrubac for the original idea](https://leetcode.com/problems/maximum-building-height/discuss/1175269/C%2B%2B-with-picture-2-passes)\nGoing from left to right, let\'s find the maximum height `h` between two limits: `h1` and `h2` which are indexed `i` and `j`.\nTo get the highest result from `h1`, we... | 0 | 0 | [] | 1 |
maximum-building-height | Java O(NlogN) 42ms 100% solution: | java-onlogn-42ms-100-solution-by-jasonz2-aj3q | Sort the restricitons and then trim from the right side.\n2. Iterate the trimmed restrictions from left to right, and find out he maximum height.\n3. Make sure | jasonz2020 | NORMAL | 2021-05-04T14:59:54.030817+00:00 | 2021-05-04T15:03:17.730219+00:00 | 373 | false | 1. Sort the restricitons and then trim from the right side.\n2. Iterate the trimmed restrictions from left to right, and find out he maximum height.\n3. Make sure to check `id = n` at the end, it might also be a possible maximum height.\n\n```\nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) {... | 0 | 0 | ['Java'] | 0 |
maximum-building-height | C# 2 passes | c-2-passes-by-rade-radumilo-ha8l | This is a C# variation of votrubac\'s solution in C++ (LINK). I didn\'t want to hustle with sorting of jagged arrays and like, so I have created a small class B | rade-radumilo | NORMAL | 2021-04-29T18:32:21.083633+00:00 | 2021-04-29T18:32:21.083674+00:00 | 144 | false | This is a C# variation of votrubac\'s solution in C++ ([LINK](https://leetcode.com/problems/maximum-building-height/discuss/1175269/C%2B%2B-with-picture-2-passes)). I didn\'t want to hustle with sorting of jagged arrays and like, so I have created a small class `Building` and `List<Building>`.\n\n```\npublic class Buil... | 0 | 0 | [] | 0 |
maximum-building-height | Java Faster Than 97.97% O(NLogN) | java-faster-than-9797-onlogn-by-sunnydho-tz2t | ```\n\tpublic int maxBuilding(int n, int[][] res) {\n int size= res.length;\n if(size == 0) return n - 1;\n int[] realHeight= new int[size] | sunnydhotre | NORMAL | 2021-04-29T06:39:49.774675+00:00 | 2021-04-29T06:39:49.774703+00:00 | 197 | false | ```\n\tpublic int maxBuilding(int n, int[][] res) {\n int size= res.length;\n if(size == 0) return n - 1;\n int[] realHeight= new int[size];\n Arrays.sort(res,(a,b)->a[0]-b[0]);\n realHeight[0]= Math.min(res[0][0]-1,res[0][1]);\n for(int i=1; i<size; i++){\n realHeig... | 0 | 0 | [] | 0 |
maximum-building-height | C# 608ms solution, achieved by removing restrictions | c-608ms-solution-achieved-by-removing-re-xssx | The innovation here vs other posters is that if we find a restriction that isn\'t actually reachable, it\'s essentially a no-op.\n\nConsider the case:\n10\n[[3, | rollie42 | NORMAL | 2021-04-27T12:14:36.166179+00:00 | 2021-04-27T12:14:36.166205+00:00 | 106 | false | The innovation here vs other posters is that if we find a restriction that isn\'t actually reachable, it\'s essentially a no-op.\n\nConsider the case:\n10\n[[3,1],[4,5]]\n\nIf we know index 3 can\'t be above 1, we can tell that index 4 can\'t be above 2; having a rule saying it can\'t be above 5 is a no-op, and can be ... | 0 | 0 | [] | 0 |
maximum-building-height | simple method | simple-method-by-chandankr0699-w02b | class Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n int ans[]=new int[n+1];\n ans[0]=0;\n ans[1]=0;\n for( | chandankr0699 | NORMAL | 2021-04-27T10:41:23.547451+00:00 | 2021-04-27T10:41:23.547484+00:00 | 156 | false | class Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n int ans[]=new int[n+1];\n ans[0]=0;\n ans[1]=0;\n for(int i=2;i<=n;i++){\n ans[i]=i-1;\n }\n for(int i=0;i<restrictions.length;i++){\n ans[restrictions[i][0]]=Math.min(ans[restr... | 0 | 0 | [] | 1 |
maximum-building-height | C# | O(r log r) | with link to explanation | c-or-log-r-with-link-to-explanation-by-c-luu9 | I couldn\'t solve this during contest tried with dp approach and failed by considering only one pass, but this needs consideration from both sides. \n\nThis is | crackthebig | NORMAL | 2021-04-27T05:49:03.266621+00:00 | 2021-04-27T05:49:03.266655+00:00 | 101 | false | I couldn\'t solve this during contest tried with dp approach and failed by considering only one pass, but this needs consideration from both sides. \n\nThis is the C# implementation of solution given by @votrubac [here](https://leetcode.com/problems/maximum-building-height/discuss/1175269/C%2B%2B-with-picture-2-passes)... | 0 | 0 | [] | 0 |
maximum-building-height | O(nlog(n)) might be fastest Python solution(1856 ms) ( guess how will it be in C++)? | onlogn-might-be-fastest-python-solution1-c7b3 | \nThe restrictions might be too high, so we need cut it lower.\nTo do it, we go from left to right and then right to left.\nWhen do from left to right, [1,0] is | yjyjyj | NORMAL | 2021-04-26T16:54:03.688151+00:00 | 2021-04-26T16:58:15.076594+00:00 | 101 | false | \nThe restrictions might be too high, so we need cut it lower.\nTo do it, we go from left to right and then right to left.\nWhen do from left to right, [1,0] is added as the inital, that is a fact.\nWhen do from right to left, [n + 1, X] is added as the inital.\nThat X is the highestt possible of n building. Which is c... | 0 | 0 | [] | 0 |
maximum-building-height | [Rust] two-pass solution | rust-two-pass-solution-by-grokus-uy2l | ```\n pub fn max_building(n: i32, a: Vec>) -> i32 {\n let mut a = a;\n a.extend_from_slice(&vec![vec![1, 0], vec![n, n - 1]]);\n a.sort_ | grokus | NORMAL | 2021-04-25T19:11:24.269913+00:00 | 2021-04-25T19:11:24.269953+00:00 | 76 | false | ```\n pub fn max_building(n: i32, a: Vec<Vec<i32>>) -> i32 {\n let mut a = a;\n a.extend_from_slice(&vec![vec![1, 0], vec![n, n - 1]]);\n a.sort_by(|x, y| x[0].cmp(&y[0]));\n let mut res = 0;\n for i in (0..a.len() - 1).rev() {\n a[i][1] = a[i][1].min(a[i + 1][1] + a[i +... | 0 | 0 | [] | 0 |
maximum-building-height | [Kotlin] Greedy solution | O(n logn) | kotlin-greedy-solution-on-logn-by-trinha-gzy4 | \nclass Solution {\n fun maxBuilding(n: Int, restrictions: Array<IntArray>): Int {\n var sorted: MutableList<IntArray> = restrictions.toMutableList()\ | trinhan-nguyen | NORMAL | 2021-04-25T18:40:52.457151+00:00 | 2021-04-25T18:40:52.457197+00:00 | 50 | false | ```\nclass Solution {\n fun maxBuilding(n: Int, restrictions: Array<IntArray>): Int {\n var sorted: MutableList<IntArray> = restrictions.toMutableList()\n sorted.add(intArrayOf(1, 0))\n sorted.add(intArrayOf(n, n - 1))\n sorted.sortBy { it.first() }\n \n for (i in 1..sorted.... | 0 | 0 | [] | 0 |
maximum-building-height | Simple Javascript with 2 loops and O(NlogN) based on restrictions | simple-javascript-with-2-loops-and-onlog-abyc | javascript\n/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n if (restr | satanTime | NORMAL | 2021-04-25T17:25:08.465935+00:00 | 2021-04-25T18:07:00.002484+00:00 | 134 | false | ```javascript\n/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n if (restrictions.length === 0) {\n return n - 1;\n }\n \n // Let\'s sort restrictions by block positions.\n // Then we won\'t meet surprises in the middle of l... | 0 | 0 | ['JavaScript'] | 0 |
maximum-building-height | C++ O(mlogm) 2 passes greedy solution with comments | c-omlogm-2-passes-greedy-solution-with-c-4ex5 | \nint maxBuilding(int n, vector<vector<int>>& restrictions) \n{\n\tint result=0;\n\tsort(restrictions.begin(),restrictions.end()); // sort by location\n\tint m= | eminem18753 | NORMAL | 2021-04-25T16:30:10.448862+00:00 | 2021-04-25T16:33:26.215202+00:00 | 79 | false | ```\nint maxBuilding(int n, vector<vector<int>>& restrictions) \n{\n\tint result=0;\n\tsort(restrictions.begin(),restrictions.end()); // sort by location\n\tint m=restrictions.size();\n\tfor(int i=0;i<m;i++) // from left to right\n\t\tif(i==0) restrictions[i]={restrictions[i][0],min(restrictions[i][1],restrictions[i][0... | 0 | 0 | [] | 0 |
maximum-building-height | need help | need-help-by-krishnendra007-9epu | can anyone tell me why it is giving tle , its o(n) with two passes, using o(n) space\n\'\'\'\nclass Solution {\npublic:\n int maxBuilding(int n, vector>& res | krishnendra007 | NORMAL | 2021-04-25T16:05:43.146793+00:00 | 2021-04-26T10:59:56.093474+00:00 | 57 | false | can anyone tell me why it is giving tle , its o(n) with two passes, using o(n) space\n\'\'\'\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& res) {\n vector<int> v(n+1,0);\n \n \n unordered_map<int,int>mp;\n for(int i=0;i<res.size();i++){\n mp[re... | 0 | 1 | [] | 0 |
maximum-building-height | [Go] Time: O(m log m) / Space: O(1) with explanation | go-time-om-log-m-space-o1-with-explanati-l4it | Time complexity O(m log m) average bound by sort.Slice. Other ops are O(n)\nSpace O(1), various constants and temporary variables\n\nIntuition:\n\n n is too la | sebnyberg | NORMAL | 2021-04-25T13:29:11.485322+00:00 | 2021-04-25T13:34:41.936980+00:00 | 47 | false | Time complexity O(m log m) average bound by sort.Slice. Other ops are O(n)\nSpace O(1), various constants and temporary variables\n\nIntuition:\n\n* `n` is too large to create one element per building, so a list of only restricted buildings and their heights are needed\n* There is an implicit "restriction" that the fi... | 0 | 0 | [] | 0 |
maximum-building-height | java sort | java-sort-by-516527986-bxgf | sort the restrictions;\nloop the restrictions from left to right \u3001 right to left then we get the right restrictions;\nat last , we can get the ans\n\ncl | 516527986 | NORMAL | 2021-04-25T12:27:37.010890+00:00 | 2021-04-25T12:27:37.010932+00:00 | 55 | false | sort the restrictions;\nloop the restrictions from left to right \u3001 right to left then we get the right restrictions;\nat last , we can get the ans\n```\nclass Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n if(n == 0) return 0;\n if(restrictions == null || restrictions.leng... | 0 | 0 | [] | 0 |
maximum-building-height | No Math Just Binary Search Simple CPP solution. nlogn | no-math-just-binary-search-simple-cpp-so-5170 | \nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& re) {\n vector<vector<long long int>> restrictions;\n for(auto it | user7634ri | NORMAL | 2021-04-25T08:05:26.531795+00:00 | 2021-04-25T08:05:26.531841+00:00 | 126 | false | ```\nclass Solution {\npublic:\n int maxBuilding(int n, vector<vector<int>>& re) {\n vector<vector<long long int>> restrictions;\n for(auto it:re) {\n restrictions.push_back({it[0],it[1]});\n }\n restrictions.push_back({1,0});\n \n sort(restrictions.be... | 0 | 1 | [] | 0 |
maximum-building-height | [JavaScript] DP with explanation | javascript-dp-with-explanation-by-jialih-3qpt | Referenced solution from here: https://leetcode.com/problems/maximum-building-height/discuss/1175026/Java-DP-O(mlogm)\n\n- Step1: find the max at each restricte | jialihan | NORMAL | 2021-04-25T06:09:42.990761+00:00 | 2021-04-25T06:09:42.990790+00:00 | 145 | false | Referenced solution from here: https://leetcode.com/problems/maximum-building-height/discuss/1175026/Java-DP-O(mlogm)\n\n- Step1: find the max at each restricted index - `dp[m]`\n\t- left: `dp[i] = Min(dp[i-1] + (interval of building at index i & i-1 ), current_restricted_height)`\n\t- right: `dp[i] = Min(dp[i], dp[i+... | 0 | 1 | [] | 0 |
maximum-building-height | JAVA n*log(n) With explanation | java-nlogn-with-explanation-by-niranjvin-6nwh | It is pretty simple. the algorithm is self explanatory\n\n1) sort the restrictions with respect to index\n2) add restriction for 1st building as 0 and last buil | niranjvin | NORMAL | 2021-04-25T04:46:52.212011+00:00 | 2021-04-25T05:56:54.139332+00:00 | 270 | false | It is pretty simple. the algorithm is self explanatory\n\n1) sort the restrictions with respect to index\n2) add restriction for 1st building as 0 and last build(if it does not exist) as (number of buildings - 1)\n3) traverse left to right and check adjacent buildings with restrictions(not literally adjacent). if H(Lef... | 0 | 0 | ['Java'] | 0 |
maximum-building-height | [C#] O(M LogM) solution | c-om-logm-solution-by-micromax-foqj | Idea is first sort restrictions by bulding index, then compute maximum possible height in each restriction point walking from left and from right. And then at t | micromax | NORMAL | 2021-04-25T04:38:19.416522+00:00 | 2021-04-25T04:48:56.866949+00:00 | 84 | false | Idea is first sort restrictions by bulding index, then compute maximum possible height in each restriction point walking from left and from right. And then at the end compute max possible hight between two restricted buildings.\n\nCurrent execution is ~0.8sec so its a pass but not optimal.\n\n\n```\npublic class Soluti... | 0 | 0 | [] | 0 |
maximum-building-height | sorting + O(N) solution with explanation Python 3 | sorting-on-solution-with-explanation-pyt-w0ln | first comb from the left to right to make sure that the i th restriction is within range of the i-1 th restriction\nThen comb from the right to left to make sur | ljpsy | NORMAL | 2021-04-25T04:19:11.743578+00:00 | 2021-04-25T04:29:36.279206+00:00 | 103 | false | first comb from the left to right to make sure that the i th restriction is within range of the i-1 th restriction\nThen comb from the right to left to make sure that the i-1 th restriction is within range of the i th restriction\nFinally, compute the maximum height can be achieved between adjacent restrictions, using ... | 0 | 0 | [] | 0 |
maximum-building-height | preprocess and iterative simulation | preprocess-and-iterative-simulation-by-b-nkfx | \nfunc maxBuilding(n int, restrictions [][]int) (ans int) {\n sort.Slice(restrictions, func(i, j int)bool{return restrictions[i][0] < restrictions[j][0]})\n | bcb98801xx | NORMAL | 2021-04-25T04:15:00.613894+00:00 | 2021-04-25T04:15:00.613921+00:00 | 66 | false | ```\nfunc maxBuilding(n int, restrictions [][]int) (ans int) {\n sort.Slice(restrictions, func(i, j int)bool{return restrictions[i][0] < restrictions[j][0]})\n \n for i := len(restrictions) - 1; i > 0; i-- {\n\t\tif restrictions[i][1] > restrictions[i-1][1] {\n\t\t\trestrictions[i][1] = min(restrictions[i][1],... | 0 | 0 | [] | 0 |
maximum-building-height | [Python] greedy solution with brief explanation comments | python-greedy-solution-with-brief-explan-0r5s | The bottle neck is sort.\nAfter sorting you can see from 1 to N and then go back to find maximum height.\n\nINF = float(\'inf\')\nclass Solution:\n def maxBu | tada_24 | NORMAL | 2021-04-25T04:09:57.127752+00:00 | 2021-04-25T04:09:57.127788+00:00 | 105 | false | The bottle neck is sort.\nAfter sorting you can see from 1 to N and then go back to find maximum height.\n```\nINF = float(\'inf\')\nclass Solution:\n def maxBuilding(self, N: int, R: List[List[int]]) -> int:\n R = [[id-1,h] for id, h in R]\n R.append([0, 0])\n R.sort()\n if R[-1][0] != N... | 0 | 0 | [] | 0 |
longest-palindrome | Simple HashSet solution Java | simple-hashset-solution-java-by-charlieb-8z2c | \npublic int longestPalindrome(String s) {\n if(s==null || s.length()==0) return 0;\n HashSet<Character> hs = new HashSet<Character>();\n i | charliebob64 | NORMAL | 2016-10-02T06:18:20.299000+00:00 | 2018-10-12T03:34:24.980379+00:00 | 72,140 | false | ```\npublic int longestPalindrome(String s) {\n if(s==null || s.length()==0) return 0;\n HashSet<Character> hs = new HashSet<Character>();\n int count = 0;\n for(int i=0; i<s.length(); i++){\n if(hs.contains(s.charAt(i))){\n hs.remove(s.charAt(i));\n ... | 421 | 7 | [] | 61 |
longest-palindrome | C++ - Easiest Beginner Friendly Sol || O(n) time and O(128) = O(1) space | c-easiest-beginner-friendly-sol-on-time-9m3hu | Intuition of this Problem:\n Describe your first thoughts on how to solve this problem. \nNOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITE | singhabhinash | NORMAL | 2023-02-07T14:27:55.936990+00:00 | 2023-02-07T14:27:55.937033+00:00 | 40,608 | false | # 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 ... | 367 | 0 | ['Hash Table', 'C++', 'Java', 'Python3'] | 13 |
longest-palindrome | What are the odds? (Python & C++) | what-are-the-odds-python-c-by-stefanpoch-jo5m | I count how many letters appear an odd number of times. Because we can use all letters, except for each odd-count letter we must leave one, except one of them w | stefanpochmann | NORMAL | 2016-10-02T13:44:40.212000+00:00 | 2018-10-10T08:52:45.698003+00:00 | 48,310 | false | I count how many letters appear an odd number of times. Because we can use **all** letters, except for each odd-count letter we must leave one, except one of them we can use.\n\nPython:\n\n def longestPalindrome(self, s):\n odds = sum(v & 1 for v in collections.Counter(s).values())\n return len(s) - od... | 323 | 7 | [] | 31 |
longest-palindrome | 💯Faster✅💯Less Mem✅🧠Detailed Approach🎯Set Approach🔥Python🐍Java☕C++😎 | fasterless-memdetailed-approachset-appro-pbyp | \uD83D\uDE80 Hi, I\'m Mohammed Raziullah Ansari, and I\'m excited to share solution to this question with detailed explanation:\n\n# \uD83C\uDFAFProblem Explain | Mohammed_Raziullah_Ansari | NORMAL | 2024-06-04T00:07:07.489474+00:00 | 2024-06-04T01:17:43.199934+00:00 | 36,114 | false | # \uD83D\uDE80 Hi, I\'m [Mohammed Raziullah Ansari](https://leetcode.com/Mohammed_Raziullah_Ansari/), and I\'m excited to share solution to this question with detailed explanation:\n\n# \uD83C\uDFAFProblem Explaination: \nThe problem is to find the length of the longest palindrome that can be constructed using the char... | 157 | 6 | ['String', 'C++', 'Java', 'Python3'] | 26 |
longest-palindrome | python simple set solution | python-simple-set-solution-by-howezz-c863 | \nclass Solution(object):\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n hash = set()\n | howezz | NORMAL | 2017-06-25T19:41:54.244000+00:00 | 2018-08-19T19:11:06.949357+00:00 | 16,949 | false | ```\nclass Solution(object):\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n hash = set()\n for c in s:\n if c not in hash:\n hash.add(c)\n else:\n hash.remove(c)\n # len(hash) is the num... | 145 | 1 | [] | 17 |
longest-palindrome | Easy || 100% || Fully Explained || Java || Clean Solution || Using HashSet || O(n) | easy-100-fully-explained-java-clean-solu-zpz4 | Java Solution:\n\n// Runtime: 4 ms, faster than 79.44% of Java online submissions for Longest Palindrome.\n// Time Complexity : O(n)\nclass Solution {\n publ | PratikSen07 | NORMAL | 2022-08-27T14:38:33.871518+00:00 | 2022-08-28T06:53:23.930487+00:00 | 15,174 | false | # **Java Solution:**\n```\n// Runtime: 4 ms, faster than 79.44% of Java online submissions for Longest Palindrome.\n// Time Complexity : O(n)\nclass Solution {\n public int longestPalindrome(String s) {\n int length = 0;\n // Create a HashSet...\n HashSet<Character> hset = new HashSet<Character>... | 132 | 1 | ['Hash Table', 'String', 'Java'] | 7 |
longest-palindrome | Python 3 solution using Set() | python-3-solution-using-set-by-michaelka-j49e | 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 | michaelkareev | NORMAL | 2020-08-27T00:47:56.802376+00:00 | 2020-08-27T00:47:56.802428+00:00 | 13,925 | false | **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 ... | 129 | 0 | ['Ordered Set', 'Python', 'Python3'] | 10 |
longest-palindrome | JavaScript solution with a single for loop | javascript-solution-with-a-single-for-lo-ex8s | We don\'t have to make an additional loop through keys.\n\n\nvar longestPalindrome = function(s) {\n let ans = 0;\n let keys = {};\n \n for (let char of s) | gorkiy | NORMAL | 2019-09-26T15:50:18.382572+00:00 | 2019-09-26T15:50:18.382625+00:00 | 8,390 | false | We don\'t have to make an additional loop through keys.\n\n```\nvar longestPalindrome = function(s) {\n let ans = 0;\n let keys = {};\n \n for (let char of s) {\n keys[char] = (keys[char] || 0) + 1;\n if (keys[char] % 2 == 0) ans += 2;\n }\n return s.length > ans ? ans + 1 : ans;\n};\n``` | 105 | 1 | ['JavaScript'] | 11 |
longest-palindrome | [C++/Python/Java] It is only easy when you think really hard to spot the built-in nature | cpythonjava-it-is-only-easy-when-you-thi-0rga | idea\uFF1A count the frequency of each char, the chars appears even times can all be kept, however, the chars appears odd times must remove one char, then the r | codedayday | NORMAL | 2020-08-14T15:35:18.223474+00:00 | 2020-12-25T22:40:27.390121+00:00 | 19,658 | false | idea\uFF1A count the frequency of each char, the chars appears even times can all be kept, however, the chars appears odd times must remove one char, then the rest instances of that char can be collected for composition. Finally, the middle char can be from OddGroup\nExample: "abccccdd",\nstep 1: count freq of char b... | 100 | 1 | ['C', 'Python', 'Java'] | 11 |
longest-palindrome | ✅✅|| Easiest Solution || Approach || C++ || JAVA || PYTHON || JAVASCRIPT || Beginner Friendly🔥🔥🔥 | easiest-solution-approach-c-java-python-zj2e6 | Intuition\n Describe your first thoughts on how to solve this problem. \nTo form the longest palindrome from the given string, we need to understand the propert | _HeLL0____ | NORMAL | 2024-06-04T00:13:17.277241+00:00 | 2024-06-04T00:13:17.277269+00:00 | 12,938 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo form the longest palindrome from the given string, we need to understand the properties of a palindrome:\n\nA palindrome reads the same forwards and backwards.\nFor this to happen, each character must appear an even number of times so ... | 61 | 3 | ['String', 'Python', 'C++', 'Java', 'JavaScript'] | 21 |
longest-palindrome | [Python] 2 lines with counter + Oneliner, explained | python-2-lines-with-counter-oneliner-exp-3ccv | Note, that it every palindrome we need to use every letter even number of times, maybe except one letter in the middle. Note also, that this condition is also s | dbabichev | NORMAL | 2020-08-14T08:21:17.270140+00:00 | 2020-08-14T09:51:58.599274+00:00 | 4,522 | false | Note, that it every palindrome we need to use every letter `even` number of times, maybe except one letter in the middle. Note also, that this condition is also sufficient: if we have frequencies for each letter which are even and one frequence is odd, we can always create palindrome. For example let us have `aaaaaa`, ... | 59 | 1 | [] | 5 |
longest-palindrome | ~~Highly~~ || Extreme Visualise Solution || 2 Approaches 😱😱 | highly-extreme-visualise-solution-2-appr-7w8b | We will have a string, using that characters from the string. We have to tell that. How much longest length palindrome is possible. \nAnd we have to return that | hi-malik | NORMAL | 2024-06-04T01:06:10.348951+00:00 | 2024-06-04T01:34:54.508212+00:00 | 7,240 | false | We will have a string, using that characters from the string. We have to tell that. How much longest length palindrome is possible. \nAnd we have to return that longest length.\n\nWhat is **Palindrome**?\n> For example we have given a character, `a` if you read it from left to right or right to left. It going to meant ... | 54 | 0 | ['C', 'Python', 'Java'] | 13 |
longest-palindrome | JAVA Solution. Simple and Clear, Using int[26] | java-solution-simple-and-clear-using-int-ivue | \n public int longestPalindrome(String s) {\n int[] lowercase = new int[26];\n int[] uppercase = new int[26];\n int res = 0;\n fo | markieff | NORMAL | 2016-10-02T17:22:18.738000+00:00 | 2018-10-21T17:56:36.276958+00:00 | 19,002 | false | \n public int longestPalindrome(String s) {\n int[] lowercase = new int[26];\n int[] uppercase = new int[26];\n int res = 0;\n for (int i = 0; i < s.length(); i++){\n char temp = s.charAt(i);\n if (temp >= 97) lowercase[temp-'a']++;\n else uppercase[temp-'... | 46 | 2 | [] | 14 |
longest-palindrome | Python, C++,Java,||Faster than 100%||Short-Simple-Solution||BeginnerLevel | python-cjavafaster-than-100short-simple-oiwit | Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n___\n__\nQ | Anos | NORMAL | 2022-10-18T17:07:57.754458+00:00 | 2022-10-18T17:07:57.754506+00:00 | 10,367 | false | ***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome*.**\n___________________\n_________________\n***Q409. Longest Palindrome***\n____________________________________________________________________________________________... | 44 | 1 | ['C', 'Python', 'Java'] | 8 |
longest-palindrome | 409. Longest Palindrome: Java Solution | 409-longest-palindrome-java-solution-by-0ykkw | Input:\n\n\nExplaination:\n\n\n\n\nOutput:\n\n\n\n\n\n\nclass Solution {\n\tpublic int longestPalindrome(String s) {\n\t\tif (s == null || s.length() == 0){\n | isalonisharma | NORMAL | 2021-11-27T16:23:30.062906+00:00 | 2023-11-28T17:05:10.669113+00:00 | 4,084 | false | Input:\n\n\nExplaination:\n\n\n\n\nOutput:\n {\n unordered_map<char,int> map;\n for(int i=0;i<s.length();i++){\n ma | aravindasai | NORMAL | 2021-06-28T14:53:51.707101+00:00 | 2021-06-28T14:53:51.707149+00:00 | 3,030 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<char,int> map;\n for(int i=0;i<s.length();i++){\n map[s[i]]++;\n }\n int cnt=0;\n for(auto i:map){\n if(i.second%2!=0){\n cnt++;\n }\n }\n ... | 37 | 0 | ['C'] | 9 |
longest-palindrome | JavaScript Solution | javascript-solution-by-deadication-4xe4 | \nvar longestPalindrome = function(s) {\n const set = new Set();\n let count = 0;\n \n for (const char of s) {\n if (set.has(char)) {\n\t\t\t | Deadication | NORMAL | 2020-08-14T17:00:44.137052+00:00 | 2020-08-14T17:01:39.196609+00:00 | 3,776 | false | ```\nvar longestPalindrome = function(s) {\n const set = new Set();\n let count = 0;\n \n for (const char of s) {\n if (set.has(char)) {\n\t\t\tcount += 2;\n set.delete(char);\n } \n\t\telse {\n set.add(char);\n }\n }\n\n return count + (set.size > 0 ? 1 : 0)... | 34 | 0 | ['JavaScript'] | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.