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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
surface-area-of-3d-shapes | Ruby 100%/100% | ruby-100100-by-dnnx-w3wn | \n# @param {Integer[][]} grid\n# @return {Integer}\ndef surface_area(grid)\n f(grid) + f(grid.transpose) + grid.sum { |row| row.count(&:positive?) } * 2\nend\n | dnnx | NORMAL | 2021-04-13T20:22:58.117114+00:00 | 2021-04-13T20:22:58.117143+00:00 | 44 | false | ```\n# @param {Integer[][]} grid\n# @return {Integer}\ndef surface_area(grid)\n f(grid) + f(grid.transpose) + grid.sum { |row| row.count(&:positive?) } * 2\nend\n\ndef f(grid)\n grid.sum do |row|\n row.each_cons(2).sum { |x, y| (x - y).abs }\n end + grid[0].sum + grid[-1].sum\nend\n``` | 2 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python, time: O(N), space: O(1) | python-time-on-space-o1-by-blue_sky5-uzof | \nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int: \n m, n = len(grid), len(grid[0])\n \n area = 0\n | blue_sky5 | NORMAL | 2020-11-11T22:03:03.009917+00:00 | 2020-11-11T22:03:03.009959+00:00 | 277 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int: \n m, n = len(grid), len(grid[0])\n \n area = 0\n for r in range(m): \n for c in range(n):\n if grid[r][c] != 0:\n area += 2\n \n ... | 2 | 1 | ['Python', 'Python3'] | 0 |
surface-area-of-3d-shapes | O(N^2) time O(1) space Java solution | on2-time-o1-space-java-solution-by-edmat-1kzl | ```\n//O(n^2) time, O(1) space\n public int surfaceArea(int[][] grid) {\n int n = grid.length;\n int area = 0;\n \n for(int i =0;i0)\ | edmat7 | NORMAL | 2020-05-23T11:42:18.118157+00:00 | 2020-05-23T11:42:18.118207+00:00 | 200 | false | ```\n//O(n^2) time, O(1) space\n public int surfaceArea(int[][] grid) {\n int n = grid.length;\n int area = 0;\n \n for(int i =0;i<n;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]>0)\n area += grid[i][j]*4 + 2;\n \n if(... | 2 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | Python 3 - Simple solutions -- Beats 96.05% | python-3-simple-solutions-beats-9605-by-19z4y | \nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n area = 0\n n = len(grid)\n for i in range(n):\n fo | nbismoi | NORMAL | 2020-03-01T04:01:09.275199+00:00 | 2020-03-01T04:01:09.275249+00:00 | 400 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n area = 0\n n = len(grid)\n for i in range(n):\n for j in range(n):\n if grid[i][j]:\n area += grid[i][j] * 4 + 2\n if i:\n area -= min(grid... | 2 | 0 | ['Python', 'Python3'] | 0 |
surface-area-of-3d-shapes | Python 3 easy to understand, 90% 100%, O(mn) complexity | python-3-easy-to-understand-90-100-omn-c-v4lh | The algorithm is simply 2 steps:\n1, count surface on each independent grid: \nFor each grid, if there is a positive value(meaning cubes exist), there should be | er1k | NORMAL | 2020-01-18T16:34:31.387575+00:00 | 2020-01-18T21:11:27.126223+00:00 | 243 | false | The algorithm is simply 2 steps:\n1, count surface on each independent grid: \nFor each grid, if there is a positive value(meaning cubes exist), there should be 4n+2 surface (n: number of cubes)\n2, substract surface overlap:\nFor adjacent grids A and B, the overlap should be 2*min(n_A, n_B)\n\nImagine this grid map as... | 2 | 0 | ['Python', 'Python3'] | 0 |
surface-area-of-3d-shapes | java easy to understand. Faster than 99% | java-easy-to-understand-faster-than-99-b-g8sk | \nclass Solution {\n public int surfaceArea(int[][] grid) {\n return (computeSide(grid)\n + computeSide(transpose(grid))\n + c | kot_matroskin | NORMAL | 2019-04-15T20:22:34.865627+00:00 | 2019-04-15T20:22:34.865694+00:00 | 260 | false | ````\nclass Solution {\n public int surfaceArea(int[][] grid) {\n return (computeSide(grid)\n + computeSide(transpose(grid))\n + computeVertical(grid))*2;\n }\n \n private int[][] transpose(int[][] grid){\n int[][] result = new int[grid.length][grid.length];\n fo... | 2 | 0 | [] | 1 |
surface-area-of-3d-shapes | Python O(n), straight forward code | python-on-straight-forward-code-by-chaoi-viq9 | \nclass Solution(object):\n def surfaceArea(self, grid):\n """\n :type grid: List[List[int]]\n :rtype: int\n """\n row_cou | chaoize | NORMAL | 2018-08-26T05:44:06.510821+00:00 | 2018-08-26T05:44:06.510865+00:00 | 233 | false | ```\nclass Solution(object):\n def surfaceArea(self, grid):\n """\n :type grid: List[List[int]]\n :rtype: int\n """\n row_count, col_count = len(grid), len(grid[0])\n surface = 0\n for row in range(row_count):\n for col in range(col_count):\n ... | 2 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java Solution with Explanation | java-solution-with-explanation-by-seanms-o4bh | The bottom and top surface area is 2 the number of cubes.\nIf the current grid is taller than the grid to the left it means we take the area of this side 2 * he | seanmsha | NORMAL | 2018-08-26T03:25:27.064038+00:00 | 2018-09-11T01:13:49.773253+00:00 | 459 | false | The bottom and top surface area is 2* the number of cubes.\nIf the current grid is taller than the grid to the left it means we take the area of this side 2 * height, we *2 because there are two sides - the height of the grid to the left because we already added it.\nIf the current grid is taller than the grid above it... | 2 | 0 | [] | 0 |
surface-area-of-3d-shapes | Beats 💯 || c++ || Beginner friendly || simple Logic || very Easy | beats-c-beginner-friendly-simple-logic-v-s9xu | Intuitionadd the top area and the bottom area first and the visible area between the adjacent towers, which the absolute difference between the adjacent towers. | abirajp04 | NORMAL | 2025-04-05T13:09:02.207971+00:00 | 2025-04-05T13:09:02.207971+00:00 | 10 | false | # Intuition
add the top area and the bottom area first and the visible area between the adjacent towers, which the absolute difference between the adjacent towers. We need to add all the four directions area. But it leads to duplicate sum. So to overcome the i just added the Top and left difference height each tower.
... | 1 | 0 | ['Math', 'Matrix', 'C++'] | 0 |
surface-area-of-3d-shapes | Simple Solution | simple-solution-by-samuel3shin-4ot3 | Code | Samuel3Shin | NORMAL | 2025-03-21T15:03:35.376005+00:00 | 2025-03-21T15:03:35.376005+00:00 | 23 | false | # Code
```cpp []
class Solution {
public:
int surfaceArea(vector<vector<int>>& grid) {
int N = grid.size();
int topBottom = 0;
int sides = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
if(grid[i][j] == 0) continue;
topBottom += 2;
... | 1 | 0 | ['C++'] | 0 |
surface-area-of-3d-shapes | Easy | easy-by-danisdeveloper-qswn | Code | DanisDeveloper | NORMAL | 2025-01-08T15:05:26.019278+00:00 | 2025-01-08T15:05:26.019278+00:00 | 38 | false |
# Code
```kotlin []
class Solution {
fun surfaceArea(grid: Array<IntArray>): Int {
val floor = grid.sumOf { row ->
row.count { it != 0 }
}
var left = 0
for (i in grid.indices) {
var count = grid[i][0] + grid[i][grid[i].lastIndex];
for (j in 1..gr... | 1 | 0 | ['Kotlin'] | 0 |
surface-area-of-3d-shapes | Python Beats 99%, Really Simple | python-beats-99-really-simple-by-trashyt-azet | Intuition\nTop/Bottom surface area is 1 if there are blocks, 0 if not\nSurface area around sides is height of blocks in that stack\nSurface area between adjacen | trashytrash | NORMAL | 2024-09-25T04:29:16.292642+00:00 | 2024-09-25T04:29:16.292673+00:00 | 130 | false | # Intuition\nTop/Bottom surface area is 1 if there are blocks, 0 if not\nSurface area around sides is height of blocks in that stack\nSurface area between adjacent stacks is abs(h1-h2)\n\n# Approach\nOne loop through the grid, adding area to account for:\ntop/bottom\noutside edges (upper/left/right/lower)\narea between... | 1 | 0 | ['Python3'] | 0 |
surface-area-of-3d-shapes | JavaScript Solution | javascript-solution-by-hariprakashkhp-mhwa | 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 | HariprakashKhp | NORMAL | 2024-08-11T02:16:46.336320+00:00 | 2024-08-11T02:16:46.336337+00:00 | 22 | 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)$$ --... | 1 | 0 | ['JavaScript'] | 0 |
surface-area-of-3d-shapes | Super Clean Code, Super Easy Explanation | super-clean-code-super-easy-explanation-ye9yd | Intuition and Approach\n Describe your first thoughts on how to solve this problem. \n Consider any block of height h. What is its total surface area?\n I | SUVU01 | NORMAL | 2023-12-13T18:22:31.672049+00:00 | 2023-12-13T18:24:11.012175+00:00 | 23 | false | # Intuition and Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\n Consider any block of height h. What is its total surface area?\n It is an (h x 1 x 1) block. So, area = (2 x 1) + (4 x h). (0 if\n h == 0)\n\n Consider another block of height H in contact with it. What is the\n... | 1 | 0 | ['Math', 'Geometry', 'Matrix', 'C++'] | 0 |
surface-area-of-3d-shapes | Area of the Solid Figure || | area-of-the-solid-figure-by-shree_govind-ltpk | 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 | Shree_Govind_Jee | NORMAL | 2023-09-05T03:47:50.686558+00:00 | 2023-09-05T03:47:50.686588+00:00 | 65 | 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:O(3N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$... | 1 | 0 | ['Array', 'Math', 'Geometry', 'Matrix', 'Java'] | 0 |
surface-area-of-3d-shapes | Easy Python Solution | easy-python-solution-by-ap3x0034-y0mn | Approach\n Describe your approach to solving the problem. \nStep 1 : Find the area of each piller on the matrix(First Loop)\nStep 2 : Remove all the walls of tw | AP3X0034 | NORMAL | 2023-08-28T18:54:33.216733+00:00 | 2023-08-28T18:54:33.216751+00:00 | 38 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nStep 1 : Find the area of each piller on the matrix(First Loop)\nStep 2 : Remove all the walls of two adjence pillers(Second Loop)\nStep 3 : Get the transpose of the matrix\nStep 4 : Repet Step 2. \n# Complexity\n- Time complexity: O(n^2)\n<!-- Add yo... | 1 | 0 | ['Python3'] | 0 |
surface-area-of-3d-shapes | Solution | solution-by-deleted_user-elt4 | C++ []\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int area = 0, n = grid.size();\n for (int i = 0; i < n; i++ | deleted_user | NORMAL | 2023-05-11T08:45:25.191459+00:00 | 2023-05-11T10:00:52.038726+00:00 | 598 | false | ```C++ []\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int area = 0, n = grid.size();\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++) {\n int v = grid[i][j];\n if (v) {\n area += 2;\n ... | 1 | 0 | ['C++', 'Java', 'Python3'] | 0 |
surface-area-of-3d-shapes | Beatiful Python Solution | beatiful-python-solution-by-bouzid_kobch-crj1 | 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 | bouzid_kobchi | NORMAL | 2023-01-31T14:39:17.017916+00:00 | 2023-01-31T14:39:17.017973+00:00 | 478 | 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 : O(n^2) \n- => n is the length or grid[i].length\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : O(1)... | 1 | 0 | ['Python3'] | 0 |
surface-area-of-3d-shapes | Java || 2 ms || %98.75 beats || with explanation | java-2-ms-9875-beats-with-explanation-by-1dit | Approach\n Describe your approach to solving the problem. \nThe total surface area of cubves was calculated and then total kissing surface areas were subtracted | armadores | NORMAL | 2023-01-19T09:37:16.018663+00:00 | 2023-01-19T09:38:17.798569+00:00 | 89 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nThe total surface area of cubves was calculated and then total kissing surface areas were subtracted from that.\n# Complexity\n- Time complexity:\n2 ms (beats %98.75)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n42.2... | 1 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | Surface Area of 3D Shapes || Easy JAVA Solution || 99.57% faster | surface-area-of-3d-shapes-easy-java-solu-hjrt | class Solution {\n\npublic int surfaceArea(int[][] grid) {\n int total = 0;\n int n = grid.length;\n \n for(int i =0; i0)\n total += | shivani_99 | NORMAL | 2022-09-15T07:39:10.594813+00:00 | 2022-09-15T07:39:10.594847+00:00 | 579 | false | class Solution {\n\npublic int surfaceArea(int[][] grid) {\n int total = 0;\n int n = grid.length;\n \n for(int i =0; i<n; i++)\n {\n for(int j =0; j<n; j++)\n {\n if(grid[i][j]>0)\n total += 6*grid[i][j]-2*(grid[i][j]-1); //Surface Area of 1 cube: 6*grid[i][j]; Co... | 1 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | Python3 | python3-by-excellentprogrammer-e5ui | \nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n c=0\n for i in range(len(grid)):\n for j in range(len(gri | ExcellentProgrammer | NORMAL | 2022-07-30T13:22:41.483519+00:00 | 2022-07-30T13:23:26.344312+00:00 | 256 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n c=0\n for i in range(len(grid)):\n for j in range(len(grid)):\n if grid[i][j]:\n c+=(grid[i][j]*4)+2\n if i:\n c-=min(grid[i][j],grid[i-1][j])*2\n... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Beginner Friendly | beginner-friendly-by-coder481-p9xx | Traverse each cube in the grid:\n Add areas for top and left surfaces -> Simply the difference between the top or left cube and current cube\n Add extra surface | coder481 | NORMAL | 2022-07-21T04:59:47.282174+00:00 | 2022-07-21T04:59:47.282218+00:00 | 472 | false | Traverse each cube in the grid:\n* Add areas for top and left surfaces -> Simply the difference between the top or left cube and current cube\n* Add extra surfaces for cubes present at ending of grid (right-most and bottom-most)\n* Also add 2 surfaces for each cube if there\'s no hole in the grid\n\n```\nclass Solution... | 1 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | C++ Solution || Single-Pass || Short & Simple || O(m*n) | c-solution-single-pass-short-simple-omn-i4l4n | Code:\n\n\nclass Solution\n{\npublic:\n int surfaceArea(vector<vector<int>> &grid)\n {\n int m = grid.size(), n = grid[0].size();\n int tota | anis23 | NORMAL | 2022-05-31T16:37:54.600229+00:00 | 2022-05-31T16:37:54.600267+00:00 | 457 | false | **Code:**\n\n```\nclass Solution\n{\npublic:\n int surfaceArea(vector<vector<int>> &grid)\n {\n int m = grid.size(), n = grid[0].size();\n int total, overlap, non_zero;\n total = overlap = non_zero = 0;\n for (int i = 0; i < m; i++)\n {\n for (int j = 0; j < n; j++)\n... | 1 | 0 | ['Array', 'Math', 'C', 'C++'] | 0 |
surface-area-of-3d-shapes | C++ || One Scan | c-one-scan-by-yezhizhen-qt69 | We have the formula 4 * height + 2 for a single (i,j) coordinate, after observation.\nBut when there are adjacent cells, the overlap region should not be counte | yezhizhen | NORMAL | 2022-05-05T14:07:52.381628+00:00 | 2022-05-05T14:09:13.421404+00:00 | 85 | false | We have the formula 4 * height + 2 for a single (i,j) coordinate, after observation.\nBut when there are adjacent cells, the overlap region should not be counted.\n\n```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int total_cnt{... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | python 3 || clean and concise code || O(n)/O(1) | python-3-clean-and-concise-code-ono1-by-34us0 | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n n = len(grid)\n \n def area(i, j):\n v = grid[i | derek-y | NORMAL | 2022-04-20T17:43:48.613851+00:00 | 2022-04-20T17:43:48.613897+00:00 | 288 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n n = len(grid)\n \n def area(i, j):\n v = grid[i][j]\n if v == 0:\n return 0\n\n up = min(v, grid[i - 1][j]) if i else 0\n right = min(v, grid[i][j + 1]) if j <... | 1 | 0 | ['Array', 'Python', 'Python3'] | 0 |
surface-area-of-3d-shapes | Simple Python Solution | simple-python-solution-by-comprhys-88oc | python\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n n = len(grid)\n total_surface = 0\n \n for i in | CompRhys | NORMAL | 2022-04-04T02:56:32.218035+00:00 | 2022-04-04T02:56:32.218061+00:00 | 65 | false | ```python\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n n = len(grid)\n total_surface = 0\n \n for i in range(n):\n for j in range(n):\n \n height = grid[i][j]\n surface = 2 + 4 * height if height > 0 else... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | C++ w Explanation | c-w-explanation-by-adamm93-fa6s | \n// Tower of height n has 6n faces and 2(n-1) hidden faces = 4n + 2 visible faces\n// The number of hidden faces in adjacent towers is twice the smaller height | Adamm93 | NORMAL | 2022-03-17T03:06:03.011037+00:00 | 2022-03-17T03:06:03.011086+00:00 | 100 | false | ```\n// Tower of height n has 6n faces and 2(n-1) hidden faces = 4n + 2 visible faces\n// The number of hidden faces in adjacent towers is twice the smaller height\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int res = 0;\n int n = grid.size();\n for (int i = 0; i < n; i... | 1 | 0 | ['C'] | 0 |
surface-area-of-3d-shapes | Python Solution | python-solution-by-lazarus29-poj0 | \nclass Solution:\n def surfaceArea(self, a: List[List[int]]) -> int:\n answer = 0\n \n for i in range(len(a)):\n for j in ra | lazarus29 | NORMAL | 2022-02-20T08:51:00.864107+00:00 | 2022-02-20T08:51:00.864141+00:00 | 73 | false | ```\nclass Solution:\n def surfaceArea(self, a: List[List[int]]) -> int:\n answer = 0\n \n for i in range(len(a)):\n for j in range(len(a)):\n answer += self.helper(i, j , a)\n \n return answer\n \n def helper(self, i, j, a):\n area = 0\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python clean and straightforward | python-clean-and-straightforward-by-blue-7h0o | py\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n m, n, area = len(grid), len(grid[0]), 0\n\n for i in range(m):\n | blueblazin | NORMAL | 2022-01-24T09:40:36.524296+00:00 | 2022-01-24T09:40:36.524396+00:00 | 197 | false | ```py\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n m, n, area = len(grid), len(grid[0]), 0\n\n for i in range(m):\n for j in range(n):\n if (x := grid[i][j]) == 0:\n continue\n\n top = max(0, x - grid[i - 1][j]) if... | 1 | 0 | ['Python'] | 0 |
surface-area-of-3d-shapes | Easy Kotlin Solution | easy-kotlin-solution-by-sahil14_11-4i5m | ```\nclass Solution {\n fun surfaceArea(grid: Array): Int {\n var area=0\n for(i in 0 until grid.size){\n for(j in 0 until grid.size | Sahil14_11 | NORMAL | 2021-12-05T15:58:50.470605+00:00 | 2021-12-05T15:58:50.470630+00:00 | 49 | false | ```\nclass Solution {\n fun surfaceArea(grid: Array<IntArray>): Int {\n var area=0\n for(i in 0 until grid.size){\n for(j in 0 until grid.size){\n if(grid[i][j]!=0){\n area+=grid[i][j]*4+2\n }\n if(i<grid.size-1){\n ... | 1 | 0 | ['Array', 'Kotlin'] | 0 |
surface-area-of-3d-shapes | Rust solution | rust-solution-by-bigmih-dpjy | \nimpl Solution {\n pub fn surface_area(grid: Vec<Vec<i32>>) -> i32 {\n let dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)];\n let l = grid.len() as | BigMih | NORMAL | 2021-11-12T07:43:43.455392+00:00 | 2021-11-12T07:44:19.815833+00:00 | 50 | false | ```\nimpl Solution {\n pub fn surface_area(grid: Vec<Vec<i32>>) -> i32 {\n let dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)];\n let l = grid.len() as i32;\n let mut res = 0;\n\n for (row, i) in grid.iter().zip(0..) {\n for (&val, j) in row.iter().zip(0..).filter(|(val, _)| **val > ... | 1 | 0 | ['Rust'] | 0 |
surface-area-of-3d-shapes | C++ O(N^2) Solution | c-on2-solution-by-ahsan83-95ue | Runtime: 8 ms, faster than 78.50% of C++ online submissions for Surface Area of 3D Shapes.\nMemory Usage: 9.4 MB, less than 46.42% of C++ online submissions for | ahsan83 | NORMAL | 2021-08-27T15:51:41.911183+00:00 | 2021-08-27T15:51:41.911225+00:00 | 142 | false | Runtime: 8 ms, faster than 78.50% of C++ online submissions for Surface Area of 3D Shapes.\nMemory Usage: 9.4 MB, less than 46.42% of C++ online submissions for Surface Area of 3D Shapes.\n\n\nLoop through grid and calculate surface area of the each cell. Also we deduct the common area betwen \n2 consicuitive cells. We... | 1 | 0 | ['Array', 'C'] | 0 |
surface-area-of-3d-shapes | O(n*n) time and O(1) space. Readable, concise. | onn-time-and-o1-space-readable-concise-b-nbtz | \npublic class Solution {\n public int SurfaceArea(int[][] grid) {\n int res = 0;\n for(int i = 0; i < grid.Length; ++i) {\n for(int | yayarokya | NORMAL | 2021-08-22T06:39:48.956228+00:00 | 2021-08-22T06:39:48.956270+00:00 | 63 | false | ```\npublic class Solution {\n public int SurfaceArea(int[][] grid) {\n int res = 0;\n for(int i = 0; i < grid.Length; ++i) {\n for(int j = 0; j < grid[i].Length; ++j) {\n res += column(i, j, grid);\n }\n }\n return res;\n }\n \n static int co... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | [Java] | TC : O(N^2) | SC : O(1) | More in-depth explanation about calculation | java-tc-on2-sc-o1-more-in-depth-explanat-tr2x | \n/*\n Explanation about calculation\n -----------------------------\n\n Total Area contributed by a cube -> 6 * 1 (according to discription [1 * 1 * 1 | _LearnToCode_ | NORMAL | 2021-07-26T06:45:52.340451+00:00 | 2021-07-26T06:45:52.340930+00:00 | 90 | false | ```\n/*\n Explanation about calculation\n -----------------------------\n\n Total Area contributed by a cube -> 6 * 1 (according to discription [1 * 1 * 1])\n \n Common area when the cubes are placed on the top of each other (vertically) : \n 2 * (number_of_cubes - 1) -> 2 * (grid[i][j] - 1)\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | C# O(mn) Solution, faster than 84.21% | c-omn-solution-faster-than-8421-by-ruste-di9e | \n\n\npublic class Solution {\n public int SurfaceArea(int[][] grid) {\n var res = 0;\n for(var i =0; i<grid.Length; i++){\n for(var | rustedwizard | NORMAL | 2021-07-20T00:53:26.079211+00:00 | 2021-07-20T00:53:26.079243+00:00 | 49 | false | \n\n```\npublic class Solution {\n public int SurfaceArea(int[][] grid) {\n var res = 0;\n for(var i =0; i<grid.Length; i++){\n for(var j=0; j<grid[i].Length; j++){\n\t\t\t\t//at top... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Not Efficient but easy to understand, C++, with comments | not-efficient-but-easy-to-understand-c-w-x4y3 | \nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int ans =0, n = grid.size();\n for(int i=0; i<n;i++)\n {\n | gyanendrasingh | NORMAL | 2021-06-07T07:03:55.196944+00:00 | 2021-06-07T07:03:55.196989+00:00 | 102 | false | ```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int ans =0, n = grid.size();\n for(int i=0; i<n;i++)\n {\n for(int j =0;j<n;j++)\n { \n \n if(grid[i][j] > 0)\n {\n ans +=2; ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Golang solution 100%, 100%, with explanation and images | golang-solution-100-100-with-explanation-ovzx | 892. Surface Area of 3D Shapes\n\nThe Idea Of This Solution:\n\nThis solution uses the fact that each stack of cubes surface area is the equation 2 + 4 * v. Thi | nathannaveen | NORMAL | 2021-04-08T18:15:04.536130+00:00 | 2021-04-08T18:15:04.536174+00:00 | 136 | false | [892. Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes/)\n\n**The Idea Of This Solution:**\n\nThis solution uses the fact that each stack of cubes surface area is the equation `2 + 4 * v`. This works because each cube has `6` sides. This can be shown using some images:\n\n {\n int n = grid.size();\n int m = grid[0].size();\n int res = | hacker_vikas_hatori | NORMAL | 2021-03-29T11:31:49.142849+00:00 | 2021-03-29T11:31:49.142882+00:00 | 76 | false | ```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int res = 0;\n int dr[] = {-1, 1, 0, 0};\n int dc[] = {0, 0, -1, 1};\n for(int i = 0;i<n;i++){\n for(int j= 0;j<m;j++){\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | C++|| fast and simple | c-fast-and-simple-by-know_go-3jhe | \nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int cube = 0, sf = 0;\n for(int i = 0; i < grid.size(); ++i) {\n | know_go | NORMAL | 2021-02-09T09:03:06.758827+00:00 | 2021-02-09T09:03:06.758867+00:00 | 115 | false | ```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int cube = 0, sf = 0;\n for(int i = 0; i < grid.size(); ++i) {\n for(int j = 0; j < grid[0].size(); ++j) {\n if(grid[i][j]==0) {\n continue;\n }\n c... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python, count sides | python-count-sides-by-vivians1103-81li | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n \n col, row=len(grid[0]), len(grid[0])\n out=sum([sum(row) | vivians1103 | NORMAL | 2021-01-06T04:50:00.259204+00:00 | 2021-01-06T04:50:00.259306+00:00 | 89 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n \n col, row=len(grid[0]), len(grid[0])\n out=sum([sum(row) for row in grid])*4 # count all unique cubes then *4\n out+= 2*sum([sum([i!=0 for i in row]) for row in grid]) # every non-zero cube, add up and down (... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | python - count and reduce adjacent | python-count-and-reduce-adjacent-by-wave-4mfa | \n def surfaceArea(self, grid: List[List[int]]) -> int:\n res = 0\n \n for i in range(len(grid)):\n for j in range(len(grid[0 | waveletus | NORMAL | 2020-12-21T01:16:14.621189+00:00 | 2020-12-21T01:16:14.621222+00:00 | 72 | false | ```\n def surfaceArea(self, grid: List[List[int]]) -> int:\n res = 0\n \n for i in range(len(grid)):\n for j in range(len(grid[0])):\n v = grid[i][j]\n if v:\n res += 2 #top/bottom\n res += v * 4 # side\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | C++ & Python solutions | c-python-solutions-by-woziji-xdbk | C++ solution,\n\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int res = 0;\n\n for (int i = 0; i < grid.size(); + | woziji | NORMAL | 2020-09-20T01:59:59.957977+00:00 | 2020-09-20T01:59:59.958022+00:00 | 141 | false | C++ solution,\n```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int res = 0;\n\n for (int i = 0; i < grid.size(); ++i)\n for (int j = 0; j < grid[0].size(); ++j) {\n if (grid[i][j])\n res += 4*grid[i][j] + 2;\n\n ... | 1 | 0 | ['C', 'Python'] | 1 |
surface-area-of-3d-shapes | Easy C++ Solution (98% fast) | easy-c-solution-98-fast-by-primacyeffect-4v8g | // loop 1 formula \n// 6 * num of stacked cubes - the top/bottom surface areas that "disappear" - the side surface areas that "disappear"\n// 6 * grid[i][j] - 2 | primacyeffect | NORMAL | 2020-09-13T06:20:21.024405+00:00 | 2020-09-13T06:32:29.248860+00:00 | 158 | false | // loop 1 formula \n// 6 * num of stacked cubes - the top/bottom surface areas that "disappear" - the side surface areas that "disappear"\n// 6 * grid[i][j] - 2 * min(grid[i][j], grid[i][j + 1]) - 2 * (grid[i][j] - 1) \n\n// loop 2 formula (need to account for the other "disappeared" sides between columns in the gri... | 1 | 0 | ['C'] | 1 |
surface-area-of-3d-shapes | Python: | python-by-splorgdar-r8vd | \nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n \n l, w, t = len(grid), len(grid[0]), 0\n for i in range(l):\ | splorgdar | NORMAL | 2020-08-19T21:18:12.746253+00:00 | 2020-08-19T21:18:12.746286+00:00 | 68 | false | ```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n \n l, w, t = len(grid), len(grid[0]), 0\n for i in range(l):\n for j in range(w):\n x = grid[i][j]\n if x: t += 2\n if i == 0: t += x\n t += x if i... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | simple cpp solution | simple-cpp-solution-by-bitrish-gtk1 | \nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int ans=0;\n for(int i=0;i<grid.size();i++)\n {\n | bitrish | NORMAL | 2020-08-17T09:04:09.281118+00:00 | 2020-08-17T09:04:09.281163+00:00 | 132 | false | ```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int ans=0;\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[i].size();j++)\n {\n if(grid[i][j]!=0)\n ans=ans+grid[i][j]*4+2;\n if(i!=0)\... | 1 | 0 | ['C', 'C++'] | 0 |
surface-area-of-3d-shapes | [Vague Description] Why the expected values are different ? | vague-description-why-the-expected-value-0nbn | As far as I have understood this question based on the given description the output for [4,2] and [2,4] must be same... But here it is giving:\n\nOutput of [4,2 | im3000 | NORMAL | 2020-04-24T18:52:50.442852+00:00 | 2020-04-24T18:52:50.442902+00:00 | 94 | false | As far as I have understood this question based on the given description the output for [4,2] and [2,4] must be same... But here it is giving:\n```\nOutput of [4,2] -> 18\nwhile, Output of [2,4] -> 10\n```\nAccording to me the output for both should be 24 ..\nCan anyone throw some light on it ? | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python 3, elegant one-liner | python-3-elegant-one-liner-by-l1ne-npr7 | Explanation\n\nCount up all the 1x1 squares on each axis:\n1. For above and below (z-axis), add 2 for every item in the grid that is not equal to 0 (1 for above | l1ne | NORMAL | 2020-04-03T19:46:28.569600+00:00 | 2020-04-03T19:46:49.832026+00:00 | 132 | false | # Explanation\n\nCount up all the 1x1 squares on each axis:\n1. For above and below (z-axis), add 2 for every item in the grid that is not equal to 0 (1 for above, 1 for below)\n2. For left and right (x-axis), for each row, add the leftmost and the rightmost, and the absolute value difference of each adjascent pair\n3.... | 1 | 0 | [] | 2 |
surface-area-of-3d-shapes | Simplest intutuive sol : 8s and 7.2M | simplest-intutuive-sol-8s-and-72m-by-pri-fu6s | \nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int sum=0,a;\n for(int i=0;i<grid.size();i++){\n for(in | Prinzu | NORMAL | 2020-03-28T21:15:14.223275+00:00 | 2020-03-28T21:15:14.223330+00:00 | 63 | false | ```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int sum=0,a;\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid.size();j++){\n a=(grid[i][j]>1)? grid[i][j]-1:0;\n sum+=grid[i][j]*6-2*a;\n }\n }\n for(i... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python3, 80ms, 96%, 100%, O(n^2) | python3-80ms-96-100-on2-by-love0991839-lfcd | \'\'\'\n\n\tclass Solution:\n\t\tdef surfaceArea(self, grid: List[List[int]]) -> int:\n\t\t\tres = 0\n\t\t\ttemp = float(\'inf\')\n\t\t\tfor i,r in enumerate(gr | love0991839 | NORMAL | 2020-03-05T06:05:47.388247+00:00 | 2020-03-05T06:05:47.388285+00:00 | 84 | false | \'\'\'\n\n\tclass Solution:\n\t\tdef surfaceArea(self, grid: List[List[int]]) -> int:\n\t\t\tres = 0\n\t\t\ttemp = float(\'inf\')\n\t\t\tfor i,r in enumerate(grid):\n\t\t\t\tif i > 0:\n\t\t\t\t\tres -= self.TwoRow(grid[i-1], grid[i])\n\t\t\t\tfor j,num in enumerate(r):\n\t\t\t\t\tif num != 0:\n\t\t\t\t\t\tres += (num*4... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python3: Faster than 90.64%, less than 100.00%. A little wordy but easy to understand | python3-faster-than-9064-less-than-10000-cpe2 | The idea here is to focus on each kind of surface individually. There are 6 kinds:\n\n1. bottom\n2. top\n3. corner\n4. edge\n5. row-top-edge\n6. column-top-edg | jcravener | NORMAL | 2020-02-13T23:03:46.996382+00:00 | 2020-02-13T23:03:46.996428+00:00 | 70 | false | The idea here is to focus on each kind of surface individually. There are 6 kinds:\n\n1. bottom\n2. top\n3. corner\n4. edge\n5. row-top-edge\n6. column-top-edge\n\n```\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n r = []\n N = len(grid)\n bottom = 0\n top = 0\... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Python 3 solution (beats 98.87%) | python-3-solution-beats-9887-by-ye15-4x2e | Algo: \n1) xy projection - twice of number of non-zero entries \n2) yz projection - sum of absolute difference of continuous elements in a row \n3) zx projectio | ye15 | NORMAL | 2019-10-03T14:40:12.547381+00:00 | 2019-10-03T14:40:12.547429+00:00 | 149 | false | Algo: \n1) xy projection - twice of number of non-zero entries \n2) yz projection - sum of absolute difference of continuous elements in a row \n3) zx projection - sum of absolute difference of continuous elements in a column\n\nDefine a (lambda) function which computes sum of absolute difference of adjacent element in... | 1 | 0 | ['Python3'] | 0 |
surface-area-of-3d-shapes | Java, foolproof, 16 lines solution with simple explanation | java-foolproof-16-lines-solution-with-si-l48p | Every tower with height greater than 1 will contribute 6 faces for the first cube; every cube after the first will add 4 more faces because there is one face th | canadianczar | NORMAL | 2019-07-25T00:37:19.006747+00:00 | 2019-07-25T00:47:00.880973+00:00 | 157 | false | Every tower with height greater than 1 will contribute 6 faces for the first cube; every cube after the first will add 4 more faces because there is one face that touches every two adjacent cubes that will not contribute to surface area.\nEvery tower that borders with adjacent towers in each direction, up, down left, r... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java explainable solution | java-explainable-solution-by-zheyuan_fu-cui4 | cubes counts cubes in the case;\nupdown counts the number of surfaces needed to be excluded for vertically placed cubes; each two cubes should merge two surface | zheyuan_fu | NORMAL | 2019-04-29T10:28:08.096576+00:00 | 2019-04-29T10:28:08.096605+00:00 | 77 | false | cubes counts cubes in the case;\nupdown counts the number of surfaces needed to be excluded for vertically placed cubes; each two cubes should merge two surfaces;\nneighbors counts the number of surfaces need to be excluded for horizontally placed cubes;\n```\n\tpublic int surfaceArea(int[][] grid) {\n if(grid =... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java easy to understand with explaination. faster than 99% | java-easy-to-understand-with-explainatio-jkq5 | If only 1 cube is present at 1 index, surface area =6\nif 2 cubes are present, surface area = 12-2(overlapping area) = 10\nIf 3 cubes are present, surface area | viveklad_27 | NORMAL | 2019-02-24T17:52:49.534682+00:00 | 2019-02-24T17:52:49.534718+00:00 | 116 | false | If only 1 cube is present at 1 index, surface area =6\nif 2 cubes are present, surface area = 12-2(overlapping area) = 10\nIf 3 cubes are present, surface area = 18-4(overlapping area) = 14\n\nHence if n cubes are present, surface area= 4n+2 ... derived by looking at the above values.\n\nNow we have to remove common ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | rust 0ms 2.7MB | rust-0ms-27mb-by-michaelscofield-r0bc | \nimpl Solution {\n pub fn surface_area(grid: Vec<Vec<i32>>) -> i32 {\n let rows = grid.len();\n let cols = grid[0].len();\n let mut sur | michaelscofield | NORMAL | 2019-02-14T07:31:29.506364+00:00 | 2019-02-14T07:31:29.506404+00:00 | 69 | false | ```\nimpl Solution {\n pub fn surface_area(grid: Vec<Vec<i32>>) -> i32 {\n let rows = grid.len();\n let cols = grid[0].len();\n let mut surfaces = 0;\n for (i, row) in grid.iter().enumerate() {\n for (j, h) in row.iter().enumerate() {\n let h = *h;\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | JS, One-Pass solution, O(1) Space complexity solution | js-one-pass-solution-o1-space-complexity-bqi1 | \nconst surfaceArea = grid => {\n let total = 0, n = grid.length;\n \n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n | ivschukin | NORMAL | 2019-01-28T17:48:10.059449+00:00 | 2019-01-28T17:48:10.059493+00:00 | 106 | false | ```\nconst surfaceArea = grid => {\n let total = 0, n = grid.length;\n \n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n let v = grid[i][j];\n let area = v === 0 ? 0 : 2;\n \n if (i === 0) { area += v; }\n else { area += Math.max(0,... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java concise solution with explanation | java-concise-solution-with-explanation-b-phzr | The trick is we always compute the net difference between current stack with stack in next row and next col if possible, never recompute previous stacks.\n\ncla | kinsapoon | NORMAL | 2018-12-03T18:49:17.744025+00:00 | 2018-12-03T18:49:17.744069+00:00 | 173 | false | The trick is we always compute the net difference between current stack with stack in next row and next col if possible, never recompute previous stacks.\n```\nclass Solution {\n public int surfaceArea(int[][] grid) {\n int res = 0;\n for (int i = 0;i < grid.length;i++)\n for (int j = 0;j < ... | 1 | 0 | [] | 1 |
surface-area-of-3d-shapes | C++ Solution easy understand | c-solution-easy-understand-by-jokerlovea-vg9j | All areas = surface + combined area\nso we have surface = 6 * total_count - 2 * combined_count\n\nclass Solution {\npublic:\n int surfaceArea(vector<vector<i | jokerloveallen | NORMAL | 2018-11-13T03:55:05.360830+00:00 | 2018-11-13T03:55:05.360875+00:00 | 276 | false | All areas = surface + combined area\nso we have surface = 6 * total_count - 2 * combined_count\n```\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n int total{0}, combined{0}, len{grid.size()};\n for(int i = 0; i< len; i++)\n for(int j = 0; j< len; j++)\n ... | 1 | 0 | [] | 1 |
surface-area-of-3d-shapes | Javascript level traversal, easy to understand - 56-60 ms | javascript-level-traversal-easy-to-under-2p4p | Not fastest solution (60ms), but all you need is to check neighbours left/right/up/down + (top or bottom) * 2.\n\nvar surfaceArea = function(grid) {\n var co | eforce | NORMAL | 2018-10-02T08:46:13.472913+00:00 | 2018-10-02T08:46:13.472958+00:00 | 125 | false | Not fastest solution (60ms), but all you need is to check neighbours left/right/up/down + (top or bottom) * 2.\n```\nvar surfaceArea = function(grid) {\n var count = 0;\n var lastIndex = grid.length - 1;\n\n for (var i = 0; i <= lastIndex; i++) {\n for (var j = 0; j <= lastIndex; j++) {\n if ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java 2 Solutions & Comparison with 2D version of this problem | java-2-solutions-comparison-with-2d-vers-19np | ----------------------- Let\'s first look at the 2D version of this problem 463. Island Perimeter -----------------------\nSoution 1 brute force\n * for each | meganlee | NORMAL | 2018-09-08T05:28:33.440143+00:00 | 2018-09-08T05:28:33.440187+00:00 | 209 | false | **----------------------- Let\'s first look at the `2D version` of this problem [463. Island Perimeter](https://leetcode.com/problems/island-perimeter/description/) -----------------------**\n**Soution 1 brute force**\n * for `each cell with non zero value:` \n * for each `direction:` if the next cell is `out bound... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Incredibly simple python solution | incredibly-simple-python-solution-by-col-4sks | \nsum = 0;\n for x in range(len(grid)):\n for y in range(len(grid)):\n if(grid[x][y]):\n sum = sum + 2 + (4* | coletyl | NORMAL | 2018-08-27T23:14:58.108377+00:00 | 2018-09-01T13:13:46.174958+00:00 | 268 | false | ```\nsum = 0;\n for x in range(len(grid)):\n for y in range(len(grid)):\n if(grid[x][y]):\n sum = sum + 2 + (4*grid[x][y])\n if(x>0):\n sum = sum - (grid[x-1][y] if grid[x][y]>=grid[x-1][y] else grid[x][y]);\n if(y>0):\... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Concise Java Solution | concise-java-solution-by-shreyansh94-ayae | \nclass Solution {\n public int surfaceArea(int[][] grid) {\n int row = grid.length, col = grid[0].length ;\n int top = 0, l=0;\n for(in | shreyansh94 | NORMAL | 2018-08-27T17:51:48.013321+00:00 | 2018-08-27T17:52:58.924814+00:00 | 108 | false | ```\nclass Solution {\n public int surfaceArea(int[][] grid) {\n int row = grid.length, col = grid[0].length ;\n int top = 0, l=0;\n for(int i = 0; i < row ; ++i){\n for(int j = 0; j < col ; ++j) {\n l += i==0 ? grid[i][j] : (int) Math.abs(grid[i][j] - grid[i-1][j]);\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Easy to understand Intuitive Approach C++ | easy-to-understand-intuitive-approach-c-txq8q | \n int surfaceArea(vector>& grid) {\n \n int ans=0;\n int m=grid.size();\n int n=grid[0].size();\n \n if(m==0 || n= | genesis99 | NORMAL | 2018-08-26T21:30:53.449330+00:00 | 2018-08-26T21:30:53.449375+00:00 | 133 | false | \n int surfaceArea(vector<vector<int>>& grid) {\n \n int ans=0;\n int m=grid.size();\n int n=grid[0].size();\n \n if(m==0 || n==0)\n return 0;\n \n if(m==1 && n==1)\n return grid[0][0]*4+2;\n \n int dx[]={-1,0,1,0};\n ... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Java straightforward solution | java-straightforward-solution-by-wangzi6-zij0 | \nclass Solution {\n public int surfaceArea(int[][] grid) {\n int result = 0, n = grid.length;\n for (int i = 0; i < n; i++) {\n for | wangzi6147 | NORMAL | 2018-08-26T03:12:53.695056+00:00 | 2018-08-26T03:12:53.695107+00:00 | 200 | false | ```\nclass Solution {\n public int surfaceArea(int[][] grid) {\n int result = 0, n = grid.length;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid[i][j] == 0) {\n continue;\n }\n int preI = i == 0 ? 0 :... | 1 | 0 | [] | 0 |
surface-area-of-3d-shapes | Swift💯 FP | swift-fp-by-upvotethispls-aegs | FP (accepted answer)
Needed an inline function to avoid compilation TLE | UpvoteThisPls | NORMAL | 2025-04-10T23:42:30.412148+00:00 | 2025-04-10T23:42:30.412148+00:00 | 1 | false | **FP (accepted answer)**
Needed an inline function to avoid compilation TLE
```
class Solution {
func surfaceArea(_ grid: [[Int]]) -> Int {
product(grid.indices, grid[0].indices)
.map { r, c in
grid[r][c] == 0 ? 0 : {
var v = grid[r][c] * 4 + 2
v -= min(grid[r][c... | 0 | 0 | ['Swift'] | 0 |
surface-area-of-3d-shapes | ans += max(0, grid[i][j] - grid[nx][ny]) ... | ans-max0-gridij-gridnxny-by-victor-smk-iuqn | null | Victor-SMK | NORMAL | 2025-04-03T18:18:02.936558+00:00 | 2025-04-03T18:18:02.936558+00:00 | 2 | false |
```swift []
class Solution {
func surfaceArea(_ grid: [[Int]]) -> Int {
var ans = 0
let sm = [(-1,0),(1,0),(0,-1),(0,1)]
for i in 0..<grid.count{
for j in 0..<grid[0].count where grid[i][j] != 0 {
for (dx,dy) in sm {
let nx = i + dx
... | 0 | 0 | ['Array', 'Math', 'Swift', 'Python', 'Python3'] | 0 |
surface-area-of-3d-shapes | Java solution | java-solution-by-java_developer-o4pa | null | Java_Developer | NORMAL | 2025-02-13T09:30:25.092668+00:00 | 2025-02-13T09:30:25.092668+00:00 | 14 | false | ```java []
class Solution {
public int surfaceArea(int[][] grid) {
int area = 0;
for (int r = 0; r < grid.length; r++) {
for (int c = 0; c < grid.length; c++) {
if (grid[r][c] == 0) {
continue;
}
area += 2;
... | 0 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | Surface Area of 3D Shapes (C++) | surface-area-of-3d-shapes-c-by-sarwar-93-j9ex | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Sarwar-93395_Leetcode | NORMAL | 2025-01-31T03:32:08.244286+00:00 | 2025-01-31T03:32:08.244286+00:00 | 11 | 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 |
surface-area-of-3d-shapes | Easy solution in java | easy-solution-in-java-by-shaileshlodhi56-ck5q | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | shaileshlodhi56 | NORMAL | 2025-01-24T19:30:57.452757+00:00 | 2025-01-24T19:30:57.452757+00:00 | 11 | 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 | ['Java'] | 0 |
surface-area-of-3d-shapes | Easy | Intuitive | Elegant Python solution | easy-intuitive-elegant-python-solution-b-yl6h | IntuitionThe idea is to calculate the number of faces exposed in each direction N, E, W, S.ApproachComplexity
Time complexity: O(n^2)
Space complexity: O(1)
Co | lunaaashi | NORMAL | 2025-01-12T20:29:18.405990+00:00 | 2025-01-12T20:32:26.126121+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The idea is to calculate the number of faces exposed in each direction N, E, W, S.
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(n^2)
<!-- Add your time complexity here, e.g. $$O(n)$... | 0 | 0 | ['Array', 'Math', 'Geometry', 'Matrix', 'Python3'] | 0 |
surface-area-of-3d-shapes | Easiest if-Else solution (beats 80%). | easiest-if-else-solution-beats-80-by-pra-spjb | IntuitionThe key to solving this problem is understanding how the cubes overlap with each other and how their faces contribute to the total surface area. For ea | prav06 | NORMAL | 2025-01-12T16:08:34.318675+00:00 | 2025-01-12T16:08:34.318675+00:00 | 9 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The key to solving this problem is understanding how the cubes overlap with each other and how their faces contribute to the total surface area. For each cube at position (i, j) in the grid, we can initially assume that it contributes a sur... | 0 | 0 | ['Java'] | 0 |
surface-area-of-3d-shapes | 892. Surface Area of 3D Shapes | 892-surface-area-of-3d-shapes-by-g8xd0qp-7gps | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-01T10:17:25.401958+00:00 | 2025-01-01T10:17:25.401958+00:00 | 3 | 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 | ['Python'] | 0 |
maximum-energy-boost-from-two-drinks | [Java/C++/Python] DP, O(1) Space | javacpython-dp-o1-space-by-lee215-nxgn | Explanation\nDP equations:\na[i] = max(A[i] + a[i - 1], b[i - 1])\nb[i] = max(B[i] + b[i - 1], a[i - 1])\n\na[i] means max energy in i + 1 hours ending with A\ | lee215 | NORMAL | 2024-08-18T04:09:48.929171+00:00 | 2024-08-18T13:56:08.311083+00:00 | 1,325 | false | # **Explanation**\nDP equations:\n`a[i] = max(A[i] + a[i - 1], b[i - 1])`\n`b[i] = max(B[i] + b[i - 1], a[i - 1])`\n\n`a[i]` means max energy in `i + 1` hours ending with `A`\n`b[i]` means max energy in `i + 1` hours ending with `B`\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n p... | 26 | 6 | [] | 7 |
maximum-energy-boost-from-two-drinks | Recursion->Top Down-> Bottom UP | DP | Easy to understand | recursion-top-down-bottom-up-dp-easy-to-5hvse | RECURSION\n\nclass Solution {\n //Considering 0 indexed hours\n //drinkType = 0 ===> drink1\n //drinkType = 1 ===> drink2\n long solve(int[] drink1, | sudher | NORMAL | 2024-08-18T04:02:24.377061+00:00 | 2024-08-18T04:10:01.406887+00:00 | 2,334 | false | ## RECURSION\n```\nclass Solution {\n //Considering 0 indexed hours\n //drinkType = 0 ===> drink1\n //drinkType = 1 ===> drink2\n long solve(int[] drink1, int[] drink2, int currHour, int currDrinkType)\n {\n if (currHour >= drink1.length)\n return 0;\n \n long drinkBoost =... | 24 | 4 | ['Dynamic Programming', 'Java'] | 6 |
maximum-energy-boost-from-two-drinks | DP || O(1) space | dp-o1-space-by-fahad06-3nc3 | Intution\n1. State Definition: Define the state of DP with two parameters:\n \n - Current Index: represents the position in the arrays where the decision | fahad_Mubeen | NORMAL | 2024-08-18T04:11:21.244133+00:00 | 2024-08-18T04:15:59.968738+00:00 | 2,543 | false | # Intution\n1. **State Definition:** Define the state of DP with two parameters:\n \n - **Current Index:** represents the position in the arrays where the decision is being made.\n - **Last Choice:** indicates whether the last chosen energy boost was from array A or array B.\n\n2. **State Representation:** Use... | 19 | 6 | ['C++', 'Java', 'Python3'] | 3 |
maximum-energy-boost-from-two-drinks | Easy Video Solution 🔥 || How to 🤔 in Interview || Top Down (Memo) + Bottom Up 🔥 | easy-video-solution-how-to-in-interview-ot1lo | If you like the solution Please Upvote and subscribe to my youtube channel\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nDry Run | ayushnemmaniwar12 | NORMAL | 2024-08-18T04:11:12.526471+00:00 | 2024-08-18T07:48:22.758176+00:00 | 799 | false | ***If you like the solution Please Upvote and subscribe to my youtube channel***\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDry Run few examples and observe how you can choose the drinks to get the maximum value\n\n\n\n***Easy Video Explanation***\n\nhttps://youtu.be/g_C4eNzUQy... | 13 | 5 | ['Dynamic Programming', 'Memoization', 'C++', 'Java', 'Python3'] | 2 |
maximum-energy-boost-from-two-drinks | Dp - Memoization | dp-memoization-by-flexsloth-0cb7 | \n# Code\n\nclass Solution {\npublic:\n long long helper(vector<int>& a, vector<int>& b, int i, int k, vector<vector<long long>>&dp){\n if(i == a.size | flexsloth | NORMAL | 2024-08-18T04:01:34.602757+00:00 | 2024-08-18T04:01:34.602795+00:00 | 1,263 | false | \n# Code\n```\nclass Solution {\npublic:\n long long helper(vector<int>& a, vector<int>& b, int i, int k, vector<vector<long long>>&dp){\n if(i == a.size()){\n return 0;\n }\n if(dp[k][i] != -1) return dp[k][i];\n long long take = 0, nottake = 0;\n if(k == 1){\n ... | 12 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 5 |
maximum-energy-boost-from-two-drinks | Java Clean Simple Solution Without DP | java-clean-simple-solution-without-dp-by-fcph | Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code | Shree_Govind_Jee | NORMAL | 2024-08-18T04:02:34.358741+00:00 | 2024-08-18T04:02:34.358767+00:00 | 564 | false | # Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {\n int n = energyDrinkA.... | 11 | 5 | ['Array', 'Math', 'Java'] | 6 |
maximum-energy-boost-from-two-drinks | Recursion+ Memo-> iterative DP with O(1) space||99ms Beats 100% | recursion-memo-iterative-dp-with-o1-spac-q4q4 | Intuition\n Describe your first thoughts on how to solve this problem. \nDP is good.\nTry Recursion+Memo\n2nd approach is the iterative version with optimized s | anwendeng | NORMAL | 2024-08-18T04:53:58.536957+00:00 | 2024-08-18T14:00:41.505355+00:00 | 752 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDP is good.\nTry Recursion+Memo\n2nd approach is the iterative version with optimized space O(1)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Set up dp state matrix dp where (i, j) ith hour drinking `j=(dinking... | 10 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 2 |
maximum-energy-boost-from-two-drinks | 💯Faster✅💯Less Mem✅🧠Detailed Approach🎯Greedy🔥C++😎 | fasterless-memdetailed-approachgreedyc-b-tgjs | 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 | swarajkr | NORMAL | 2024-08-18T04:01:52.808388+00:00 | 2024-08-18T04:01:52.808421+00:00 | 736 | 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)$$ --... | 10 | 2 | ['C++'] | 1 |
maximum-energy-boost-from-two-drinks | Python 3 || 6 lines, Iterative linear transformation || | python-3-6-lines-iterative-linear-transf-nooa | \nclass Solution:\n def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:\n \n prev_A = curr_A = prev_B = curr_B = | Spaulding_ | NORMAL | 2024-08-18T07:22:10.357416+00:00 | 2024-08-18T07:22:10.357447+00:00 | 68 | false | ```\nclass Solution:\n def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:\n \n prev_A = curr_A = prev_B = curr_B = 0\n\n for a, b in zip(energyDrinkA, energyDrinkB):\n add_A = a + max(curr_A, prev_B)\n add_B = b + max(curr_B, prev_A)\n\n ... | 8 | 0 | ['Python3'] | 0 |
maximum-energy-boost-from-two-drinks | ✅ Detailed Easy Java ,Python3 ,C++ Solution|| 0ms||100% | detailed-easy-java-python3-c-solution-0m-0fqc | OBSERVATION\n Yep! Dp is quite intutive here! and that\'s should be the first approach but, can we do it without it! The answer is yes! and if yes? then how?... | pankajpatwal1224 | NORMAL | 2024-08-18T13:35:28.862339+00:00 | 2024-08-18T13:35:28.862372+00:00 | 55 | false | # OBSERVATION\n Yep! Dp is quite intutive here! and that\'s should be the first approach but, can we do it without it! The answer is yes! and if yes? then how?...\n\n---\n\n```\nCode block\n```\n# Read this!\n\nAt each hour, I have two choices:\n\nStick with the same energy drink I used in the previous hour.\n Switc... | 5 | 0 | ['Java'] | 0 |
maximum-energy-boost-from-two-drinks | ✨🚀 Effortlessly 💯 Dominate 100% with Beginner C++ , Java and Python Solution! 🚀✨ | effortlessly-dominate-100-with-beginner-bwim4 | 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 | Ravi_Prakash_Maurya | NORMAL | 2024-08-18T04:00:44.854188+00:00 | 2024-08-18T04:00:44.854216+00:00 | 495 | 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)$$ --... | 5 | 0 | ['C++'] | 3 |
maximum-energy-boost-from-two-drinks | Linear DP | O(1) Space | linear-dp-o1-space-by-jay_1410-lyy5 | Code\nC++ []\nclass Solution {\npublic:\n using ll = long long;\n long long maxEnergyBoost(vector<int> &A, vector<int> &B){\n ll A1 = 0 , B1 = 0 , | Jay_1410 | NORMAL | 2024-08-18T04:01:41.573206+00:00 | 2024-08-18T04:31:32.480617+00:00 | 431 | false | # Code\n```C++ []\nclass Solution {\npublic:\n using ll = long long;\n long long maxEnergyBoost(vector<int> &A, vector<int> &B){\n ll A1 = 0 , B1 = 0 , A2 = 0 , B2 = 0;\n for(int i = 0 ; i < A.size() ; i++){\n ll currA = A[i] + max(A1 , B2);\n ll currB = B[i] + max(B1 , A2);\n ... | 4 | 0 | ['Dynamic Programming', 'C++', 'Java', 'Python3'] | 0 |
maximum-energy-boost-from-two-drinks | DP. One pass. Space O(1) | dp-one-pass-space-o1-by-xxxxkav-duhk | Time $O(n)$, space $O(n)$\n\nclass Solution:\n def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:\n n = len(energyDrin | xxxxkav | NORMAL | 2024-08-19T18:52:09.891839+00:00 | 2024-08-19T19:02:35.386249+00:00 | 66 | false | Time $O(n)$, space $O(n)$\n```\nclass Solution:\n def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:\n n = len(energyDrinkA)\n dp = [[0, 0] for _ in range(n)]\n dp[0][0] = energyDrinkA[0]\n dp[0][1] = energyDrinkB[0]\n for i in range(1, n):\n ... | 3 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
maximum-energy-boost-from-two-drinks | DP | dp-by-votrubac-uwg2 | This problem belongs to the 198. House Robber group of DP problems.\n\nlastA is the maximum total boost so far if the last drink was A, and lastB is the same fo | votrubac | NORMAL | 2024-08-18T17:15:50.575840+00:00 | 2024-08-19T18:03:55.162815+00:00 | 41 | false | This problem belongs to the [198. House Robber](https://leetcode.com/problems/house-robber/) group of DP problems.\n\n`lastA` is the maximum total boost so far if the last drink was `A`, and `lastB` is the same for `B`.\n\nFor hour `i`, we can continue driking `A`, or switch from `B`:\n- `lastA = drinkA[i] + max(lastA,... | 3 | 0 | ['C'] | 0 |
maximum-energy-boost-from-two-drinks | Intuitive Solution (with and without DP) || Beats 100% | intuitive-solution-with-and-without-dp-b-gibl | Two-dimensional Dynamic Programming\n# Intuition\nMaximizing energy boosts requires considering the best choices from two arrays at each step, making dynamic pr | divyamshah04 | NORMAL | 2024-08-18T09:44:49.390819+00:00 | 2024-08-18T09:44:49.390853+00:00 | 209 | false | # Two-dimensional Dynamic Programming\n# Intuition\nMaximizing energy boosts requires considering the best choices from two arrays at each step, making dynamic programming a suitable approach.\n\n# Approach\nWe use a DP table where dp[i][0] and dp[i][1] store the maximum boost achievable up to the i-th drink by choosin... | 3 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-energy-boost-from-two-drinks | simple recursive solution. | simple-recursive-solution-by-romaishawaq-s0ze | 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 | romaishawaqar | NORMAL | 2024-08-18T09:03:56.079825+00:00 | 2024-08-18T09:03:56.079844+00:00 | 75 | 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)$$ --... | 3 | 0 | ['Recursion', 'C++'] | 1 |
maximum-energy-boost-from-two-drinks | Beginner Iterative Dp Solution | beginner-iterative-dp-solution-by-kvivek-rdjn | 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 | kvivekcodes | NORMAL | 2024-08-18T05:29:56.692093+00:00 | 2024-08-18T05:29:56.692113+00:00 | 51 | 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)$$ --... | 3 | 0 | ['C++'] | 1 |
maximum-energy-boost-from-two-drinks | recursion + memo | recursion-memo-by-raviteja_29-nx7v | Intuition\n Describe your first thoughts on how to solve this problem. \nTo maximize the energy boost over n hours:\n\nDecision at Each Hour: Choose to either c | raviteja_29 | NORMAL | 2024-08-18T04:52:15.308371+00:00 | 2024-08-18T04:52:15.308422+00:00 | 285 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo maximize the energy boost over n hours:\n\nDecision at Each Hour: Choose to either continue with the current drink or switch to the other drink, considering the switch penalty.\n\nRecursive Approach: Use recursion to explore the best o... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Python3'] | 2 |
maximum-energy-boost-from-two-drinks | Beats 100 % - Best solution using Java | beats-100-best-solution-using-java-by-_d-iyes | Even I am surprised \uD83D\uDE02\n\n# Code\n\nclass Solution {\n public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {\n long maxA = 0; | _deepaktiwari | NORMAL | 2024-08-18T04:31:19.233793+00:00 | 2024-08-18T04:31:19.233820+00:00 | 226 | false | Even I am surprised \uD83D\uDE02\n\n# Code\n```\nclass Solution {\n public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {\n long maxA = 0;\n long maxB = 0;\n for(int i = 0; i < energyDrinkA.length; i++){\n long tempA = Math.max(maxA + energyDrinkA[i], maxB);\n ... | 3 | 0 | ['Java'] | 1 |
maximum-energy-boost-from-two-drinks | Easy to understand C++ solution with explaination. | easy-to-understand-c-solution-with-expla-ghe4 | Intuition\nThe goal is to maximize the total energy boost over the next n hours by choosing between two energy drinks. The catch is that switching from one drin | AyushPandey152 | NORMAL | 2024-08-18T04:15:34.861244+00:00 | 2024-08-18T04:15:34.861267+00:00 | 138 | false | # Intuition\nThe goal is to maximize the total energy boost over the next n hours by choosing between two energy drinks. The catch is that switching from one drink to another incurs a 1-hour penalty with no energy boost. This penalty makes it essential to carefully decide when to switch drinks to avoid losing too much ... | 3 | 0 | ['Array', 'Dynamic Programming', 'C++'] | 2 |
maximum-energy-boost-from-two-drinks | C++ || Super Easy || Recursion + Memo | c-super-easy-recursion-memo-by-shobhit_s-64oe | Intuition\nWe can start choosing the elements from either of the array so take the maximum starting from both.\n\n# Approach\n1) If we switch the arrar we get 0 | Shobhit_Singh_47 | NORMAL | 2024-08-18T04:12:58.861594+00:00 | 2024-08-18T04:12:58.861632+00:00 | 901 | false | # Intuition\nWe can start choosing the elements from either of the array so take the maximum starting from both.\n\n# Approach\n1) If we switch the arrar we get 0 boost.\n2) If we do not switch we get the boost , the array we are in. \n3) So we need to keep track which arry we are in , index.\n\n# Complexity\n- Time co... | 3 | 0 | ['C++'] | 2 |
maximum-energy-boost-from-two-drinks | Simple JAVA DP ✅ | simple-java-dp-by-harshsharma08-d3i0 | 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 | Harshsharma08 | NORMAL | 2024-08-18T04:07:21.309805+00:00 | 2024-08-18T04:07:21.309839+00:00 | 269 | 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)$$ --... | 3 | 0 | ['Dynamic Programming', 'Greedy', 'Memoization', 'C++', 'Java'] | 1 |
maximum-energy-boost-from-two-drinks | C++ Dp solution | c-dp-solution-by-sachin_kumar_sharma-kjgz | Intuition\nJust apply the concept of take A and notTake B and vice versa.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe | Sachin_Kumar_Sharma | NORMAL | 2024-08-18T04:06:22.931294+00:00 | 2024-08-18T04:06:22.931325+00:00 | 11 | false | # Intuition\nJust apply the concept of take A and notTake B and vice versa.\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- Spa... | 3 | 0 | ['C++'] | 0 |
maximum-energy-boost-from-two-drinks | ✅100% Fastest✅Easy and Simple Solution ✅Clean Code | 100-fastesteasy-and-simple-solution-clea-nanb | Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\nFoll | ayushluthra62 | NORMAL | 2024-08-18T04:02:14.095366+00:00 | 2024-08-18T04:02:14.095391+00:00 | 162 | false | ***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N... | 3 | 0 | ['C++'] | 0 |
maximum-energy-boost-from-two-drinks | Must Watch✅💯Easiest Approach With Beginner Friendly Explanation💯✅ | must-watcheasiest-approach-with-beginner-xa8o | Intuition\nThe problem involves two energy drink lists, energyDrinkA and energyDrinkB, where we can choose drinks from either list with certain constraints:\n\n | Ajay_Kartheek | NORMAL | 2024-09-11T16:33:30.595631+00:00 | 2024-09-11T16:33:30.595661+00:00 | 107 | false | # Intuition\nThe problem involves two energy drink lists, energyDrinkA and energyDrinkB, where we can choose drinks from either list with certain constraints:\n\n- You can either take an energy drink from list A or list B.\nOnce you take an energy drink from one list, you can\u2019t take an adjacent drink from the same... | 2 | 0 | ['Array', 'Dynamic Programming', 'C++', 'Java', 'Python3'] | 0 |
maximum-energy-boost-from-two-drinks | very Easy Solution | very-easy-solution-by-vansh0123-led9 | \n\n# Code\njava []\nclass Solution {\n public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {\n \n int n = energyDrinkA.length ;\ | vansh0123 | NORMAL | 2024-08-22T05:29:00.940752+00:00 | 2024-08-22T05:29:00.940786+00:00 | 138 | false | \n\n# Code\n```java []\nclass Solution {\n public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {\n \n int n = energyDrinkA.length ;\n \n if (n == 0) return 0;\n \n long[] dpA = new long[n];\n long[] dpB = new long[n];\n\n \n dpA[0] = energyDrinkA[0];\n ... | 2 | 0 | ['Java'] | 1 |
maximum-energy-boost-from-two-drinks | Recursion || C++ || 10 Lines of Code with Comments | recursion-c-10-lines-of-code-with-commen-hfp7 | Intuition\nWe want to find out for every hour what the next energy drink choice is best while considering which energy drink we last consumed. This sounds like | SlienCode | NORMAL | 2024-08-20T17:21:20.568268+00:00 | 2024-08-20T23:40:45.643484+00:00 | 140 | false | # Intuition\nWe want to find out for every hour what the next energy drink choice is best while considering which energy drink we last consumed. This sounds like a typical dynamic programming problem.\n\n# Approach\nWe build a function that handles the choice we made. There are only two choices we can make: we either c... | 2 | 0 | ['C++'] | 2 |
maximum-energy-boost-from-two-drinks | C++ | T.c & S.c : O(N) | Easy Solution :) | c-tc-sc-on-easy-solution-by-mammarqaisar-ol6k | \nclass Solution {\npublic:\n long long maxEnergyBoost(vector<int>& energyDrinkA, vector<int>& energyDrinkB) { \n int n = energyDrinkA.size();\n | mammarqaisar11a55 | NORMAL | 2024-08-18T04:37:26.336072+00:00 | 2024-08-18T04:37:26.336094+00:00 | 92 | false | ```\nclass Solution {\npublic:\n long long maxEnergyBoost(vector<int>& energyDrinkA, vector<int>& energyDrinkB) { \n int n = energyDrinkA.size();\n \n if (n == 0) return 0;\n \n vector<long long> dpA(n, 0), dpB(n, 0);\n \n dpA[0] = energyDrinkA[0];\n dpB[0] = energyDrinkB[0];\n \n ... | 2 | 0 | ['Dynamic Programming', 'C++'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.