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-difference-score-in-a-grid | [Python] Simple DP without math, O(MN) | python-simple-dp-without-math-omn-by-arv-zkf1 | Key Ideas\n- Fill DP array up from bottom right to top left.\n- When we iterate over cell (i, j), we compute the highest scoring path starting from (i, j) with | arvganesh | NORMAL | 2024-05-12T16:51:59.762620+00:00 | 2024-05-12T16:53:40.162415+00:00 | 63 | false | ### Key Ideas\n- Fill DP array up from bottom right to top left.\n- When we iterate over cell `(i, j)`, we compute the highest scoring path starting from `(i, j)` with **at least 1 move**.\n- The requirement of paths being at least 1 move long make this problem tricky.\n\nIgnoring any bounds checks, the recurrence + ca... | 2 | 0 | ['Python'] | 0 |
maximum-difference-score-in-a-grid | C++ | Basic DP approach | Tabulation | c-basic-dp-approach-tabulation-by-mitali-ozk0 | Intuition\nMy intuition was that the problem can be solved using DP since to calculate cost at each cell we will require the previous moves costs.\n\nIf the mov | mitalidxt | NORMAL | 2024-05-12T15:48:31.774915+00:00 | 2024-05-12T15:48:31.774935+00:00 | 144 | false | # Intuition\nMy intuition was that the problem can be solved using DP since to calculate cost at each cell we will require the previous moves costs.\n\nIf the move can start and end at any cell, I created a 2D dp matrix where each cell represented the maximum cost that can be achieved if it was the destination cell. \n... | 2 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Easy DP | Memoization | Trying all below and right cells | Solution in c++ | easy-dp-memoization-trying-all-below-and-9ejc | Intuition\nAs you can see option that you can move at any right cell or below cell and to try all possible ways use Dynamic Programming.\n\n# Approach\nThe key | shekhar125 | NORMAL | 2024-05-12T07:16:00.170784+00:00 | 2024-05-12T07:16:00.170818+00:00 | 312 | false | # Intuition\nAs you can see option that you can move at any right cell or below cell and to try all possible ways use Dynamic Programming.\n\n# Approach\nThe key part is to understand that in you main function you are trying for all below cells and right cells but only you consider further values from function that rig... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'Matrix', 'C++'] | 2 |
maximum-difference-score-in-a-grid | ✅Accepted Java Code || O(n^2) | accepted-java-code-on2-by-thilaknv-izlx | Complexity\n- Time complexity : O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity : O(n^2)\n Add your space complexity here, e.g. O(n) \n | thilaknv | NORMAL | 2024-05-12T04:59:34.249011+00:00 | 2024-05-12T04:59:34.249031+00:00 | 15 | false | # Complexity\n- Time complexity : $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public int maxScore(List<List<Integer>> grid) {\n int res = 0;\n \n ... | 2 | 0 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | Easy to understand Step by Step Solution | C++ | DP | easy-to-understand-step-by-step-solution-tcjk | Intuition\n Describe your first thoughts on how to solve this problem. \nDynamic Programming to reduce repetation in code flow.\n\n# Approach\n Describe your ap | yashugshejwal | NORMAL | 2024-05-12T04:45:42.584555+00:00 | 2024-05-12T04:45:42.584575+00:00 | 378 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDynamic Programming to reduce repetation in code flow.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSolve the problem by storing maximum possible score at each square in grid, starting from the bottom-rightmost ... | 2 | 0 | ['Dynamic Programming', 'C++'] | 3 |
maximum-difference-score-in-a-grid | Java DP matrix | java-dp-matrix-by-deleted_user-40sq | Intuition\nThe approach is to utilize dynamic programming to compute the maximum score that can be achieved by reaching each cell of the grid.\n# Approach\nInit | deleted_user | NORMAL | 2024-05-12T04:41:32.261995+00:00 | 2024-05-12T04:41:32.262014+00:00 | 107 | false | # Intuition\nThe approach is to utilize dynamic programming to compute the maximum score that can be achieved by reaching each cell of the grid.\n# Approach\nInitialize a 2D array dp to store the maximum score that can be achieved at each cell.\nStart from the bottom-right corner of the grid and iteratively fill the dp... | 2 | 0 | ['Java'] | 1 |
maximum-difference-score-in-a-grid | 😎Simplest CPP implementation....just DP things✅ | simplest-cpp-implementationjust-dp-thing-9gf7 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe will be starting from the bottom right element, becoz we know that for that element | Engg_Ayush | NORMAL | 2024-05-12T04:15:16.536053+00:00 | 2024-05-12T04:15:16.536088+00:00 | 240 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will be starting from the bottom right element, becoz we know that for that element the value is 0.\n\nand than the simple traversal and from the bottom right to top left element and some calculation.\n\n# Approach\n<!-- Describe your ... | 2 | 2 | ['Array', 'Dynamic Programming', 'Python', 'C++', 'Java', 'Python3', 'C#'] | 2 |
maximum-difference-score-in-a-grid | DP || JAVA || Memoization | dp-java-memoization-by-pavan_d_naik-o933 | Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n# | PAVAN_D_NAIK | NORMAL | 2024-05-12T04:05:22.312310+00:00 | 2024-05-12T04:05:22.312344+00:00 | 363 | false | # Complexity\n- Time complexity: $$O(m*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n int[][] dp;\n int m,n;\n int min=-(int)1e7;\n int max=min;\n private int helper(i... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 2 |
maximum-difference-score-in-a-grid | ✅ Java Solution | java-solution-by-harsh__005-06yv | CODE\nJava []\npublic int maxScore(List<List<Integer>> grid) {\n\tint r = grid.size(), c = grid.get(0).size();\n\tint res = Integer.MIN_VALUE;\n\n\tint[][] arr | Harsh__005 | NORMAL | 2024-05-12T04:02:32.790643+00:00 | 2024-05-12T04:02:32.790667+00:00 | 386 | false | ## **CODE**\n```Java []\npublic int maxScore(List<List<Integer>> grid) {\n\tint r = grid.size(), c = grid.get(0).size();\n\tint res = Integer.MIN_VALUE;\n\n\tint[][] arr = new int[r][c];\n\tfor(int i=r-1; i>=0; i--) {\n\t\tint max = grid.get(i).get(c-1);\n\t\tarr[i][c-1] = max;\n\t\tfor(int j=c-2; j>=0; j--) {\n\t\t\ti... | 2 | 0 | ['Java'] | 1 |
maximum-difference-score-in-a-grid | Rectangle approach O(m*n) | rectangle-approach-omn-by-tq9iyziust-kiik | Intuition\nThe largest jump with cell (a,b) is to find the smallest value of rectangle (0,0) -> (a,b) except the point at (a,b)\n Describe your first thoughts o | tunt6 | NORMAL | 2024-11-15T07:53:02.419788+00:00 | 2024-11-15T07:53:02.419850+00:00 | 8 | false | # Intuition\nThe largest jump with cell (a,b) is to find the smallest value of rectangle (0,0) -> (a,b) except the point at (a,b)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Create an O(n) array that stores the smallest value before reaching cell (x,y) of row x.\n\n- When brows... | 1 | 0 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | c++ solution | c-solution-by-dilipsuthar60-a74r | \nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int ans=-1e8;\n | dilipsuthar17 | NORMAL | 2024-10-27T12:22:36.554159+00:00 | 2024-10-27T12:22:36.554192+00:00 | 2 | false | ```\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int ans=-1e8;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n int prevMin=1e9;\n if(i==0&&j==0) continue;\n i... | 1 | 0 | ['C', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Smallest and Easiest one (Beats 100% of Users) | smallest-and-easiest-one-beats-100-of-us-2gl0 | 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 | cookie_33 | NORMAL | 2024-07-30T04:52:24.935087+00:00 | 2024-07-30T04:52:24.935105+00:00 | 94 | 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*M)\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 | ['Dynamic Programming'] | 0 |
maximum-difference-score-in-a-grid | DP Solution | Easy Approach | O(n^2) | Space Optimised | dp-solution-easy-approach-on2-space-opti-aw5d | Intuition\nIt can be observed that for every index except last one, we have two options to traverse: Rightwards and Downwards. We can avoid many computations by | HariBhakt | NORMAL | 2024-05-28T18:44:04.197500+00:00 | 2024-05-28T18:44:04.197520+00:00 | 36 | false | # Intuition\nIt can be observed that for every index except last one, we have two options to traverse: Rightwards and Downwards. We can avoid many computations by traversing bottom-right to top-left.\n\nDry Run:\n------------\n \nArray: \n\n[[ 9 5 7 3 ],\n[ 8 9 6 1 ],\n[ 6 7 14 3 ],\n[ 2 5 3 1 ]]\n\nDP Array:\n\n[[ ... | 1 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | 4 Solutions | 3D-DP, 2D-DP | 4-solutions-3d-dp-2d-dp-by-shahsb-8n3r | Solution 1 to 3 (3D-DP Recursion->memoization->tabulation):\n Idea is simple - Simulate taking & not taking behavior at each cell.\n\n# Solution-4: (2D-DP):\n A | shahsb | NORMAL | 2024-05-18T07:06:17.610859+00:00 | 2024-05-18T07:06:17.610893+00:00 | 24 | false | # Solution 1 to 3 (3D-DP Recursion->memoization->tabulation):\n* Idea is simple - Simulate taking & not taking behavior at each cell.\n\n# Solution-4: (2D-DP):\n* At each cell, you should be able to figure out the smallest possible number till that point (i.e from it\'s left and top side).\n* Consider the current cell ... | 1 | 0 | ['Dynamic Programming'] | 0 |
maximum-difference-score-in-a-grid | Very Easy Solution in Python with clear approach -> time o(n*n), space(o(1)) | very-easy-solution-in-python-with-clear-kodhd | Intuition\n Describe your first thoughts on how to solve this problem. \nIf you observe, you will notice that the answer will be path independent.\nyou just nee | nketu06 | NORMAL | 2024-05-16T01:03:30.744350+00:00 | 2024-05-16T01:03:30.744373+00:00 | 166 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf you observe, you will notice that the answer will be path independent.\nyou just need to find that max difference of grid[i][j] with the smallest value till i,j \n\nin other word if suppose current point is 2,3 then you need the samall... | 1 | 0 | ['Array', 'Dynamic Programming', 'Python3'] | 2 |
maximum-difference-score-in-a-grid | Maximum Difference Score in a Grid 🚦 Optimal Dynamic Programming Approach | maximum-difference-score-in-a-grid-optim-asd2 | \n## Intuition\nThe goal is to find the maximum difference between the value of a cell and the minimum value of its adjacent upper or left cell in a given grid. | lebon | NORMAL | 2024-05-14T23:24:35.011806+00:00 | 2024-05-14T23:24:35.011828+00:00 | 12 | false | \n## Intuition\nThe **goal** is to find the maximum difference between the value of a cell and the minimum value of its adjacent upper or left cell in a given grid. \n\nThe **challenge** is to efficiently calculate this maximum difference while updating the grid in place to keep track of the minimum values encountered ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Swift'] | 0 |
maximum-difference-score-in-a-grid | Easy DP Solution :) | easy-dp-solution-by-user20222-ggdy | Code\n\nclass Solution {\npublic:\nvector<vector<vector<int>>>dp;\n int f(vector<vector<int>>&grid,int i,int j,int s){\n if(i>=grid.size()||j>=grid[0] | user20222 | NORMAL | 2024-05-14T04:52:51.119035+00:00 | 2024-05-14T04:52:51.119057+00:00 | 88 | false | # Code\n```\nclass Solution {\npublic:\nvector<vector<vector<int>>>dp;\n int f(vector<vector<int>>&grid,int i,int j,int s){\n if(i>=grid.size()||j>=grid[0].size()){\n if(s==2)return 0;\n return -1e6;\n }\n if(dp[i][j][s]!=-1e9)return dp[i][j][s];\n int val = 0;\n ... | 1 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | Easy Java Solution || Dynamic Programing | easy-java-solution-dynamic-programing-by-qr2b | 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 | ravikumar50 | NORMAL | 2024-05-13T06:47:40.563337+00:00 | 2024-05-13T06:47:40.563369+00:00 | 101 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | 100% Fast Code | Simple Approach | 100-fast-code-simple-approach-by-ronak_r-25dk | Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea is to store the minimum element encountered in the top and left portion for ea | Ronak_Ramuka | NORMAL | 2024-05-12T21:26:40.469440+00:00 | 2024-05-12T21:26:40.469457+00:00 | 110 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea is to store the minimum element encountered in the top and left portion for each position in the grid. Then, we calculate the final answer as the maximum difference between the stored minimum and the element at that position.\n\n... | 1 | 0 | ['Array', 'Dynamic Programming', 'Java'] | 0 |
maximum-difference-score-in-a-grid | c++ Solution || easy to understand || using memoization ✅✅ | c-solution-easy-to-understand-using-memo-1cpw | \n\n# Code\n\nclass Solution {\npublic:\n int dp[1002][1002];\n int func(int n, int m, int i, int j, vector<vector<int>>&grid){\n if(i>=n || j>=m) | Arzoo_singh | NORMAL | 2024-05-12T11:55:53.964236+00:00 | 2024-05-12T11:55:53.964275+00:00 | 147 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int dp[1002][1002];\n int func(int n, int m, int i, int j, vector<vector<int>>&grid){\n if(i>=n || j>=m) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int right = INT_MIN, down = INT_MIN;\n if(i+1<n){\n down = grid[i+1][j]-grid[... | 1 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Recursion || DP || Memoization | recursion-dp-memoization-by-birenamanta-dsvl | 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 | birenamanta | NORMAL | 2024-05-12T06:56:12.533425+00:00 | 2024-05-12T06:56:12.533462+00:00 | 136 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | beats 100 % percent of users || weekly contest 397 | beats-100-percent-of-users-weekly-contes-sko6 | 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 | Saksham_chaudhary_2002 | NORMAL | 2024-05-12T04:36:16.128565+00:00 | 2024-05-12T04:36:16.128588+00:00 | 239 | 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 | ['Python3'] | 0 |
maximum-difference-score-in-a-grid | Solved in c using dynamic programming, Bottom up approach | solved-in-c-using-dynamic-programming-bo-1fbh | \n\n# Complexity\n- Time complexity:\n O(n^2)\n\n- Space complexity:\n O(n^2) \n\n# Code\n\nint max(int a,int b){\n return a>b?a:b;\n}\n\nint maxScore(int** | yeshwanth_123 | NORMAL | 2024-05-12T04:28:31.749861+00:00 | 2024-05-12T04:28:31.749879+00:00 | 65 | false | \n\n# Complexity\n- Time complexity:\n $$O(n^2)$$\n\n- Space complexity:\n $$O(n^2)$$ \n\n# Code\n```\nint max(int a,int b){\n return a>b?a:b;\n}\n\nint maxScore(int** grid, int gridSize, int* gridColSize) {\n int res=-1e9;\n int col=*gridColSize;\n int row=gridSize;\n int** dp=malloc(sizeof(int*)*gridSi... | 1 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
maximum-difference-score-in-a-grid | 🔥💯| Full Java Solution | Explanation | ✅🎯 | full-java-solution-explanation-by-anushd-l2ai | Intuition\nThe problem seems to be about finding the maximum score that can be obtained from a grid of integers. The intuition is to use dynamic programming to | Chandrikasharma16 | NORMAL | 2024-05-12T04:20:44.689553+00:00 | 2024-05-12T04:20:44.689569+00:00 | 57 | false | # Intuition\nThe problem seems to be about finding the maximum score that can be obtained from a grid of integers. The intuition is to use dynamic programming to keep track of the maximum future value that can be obtained from each cell in the grid.\n\n# Approach\n1. Initialize a 2D array `maxFutureValue` of the same s... | 1 | 0 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | C++ soln || using DP | c-soln-using-dp-by-anjali234-plj5 | \n\n# Code\n\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n \n int n = grid.size(), m = grid[0].size();\n vect | anjali234 | NORMAL | 2024-05-12T04:14:32.631267+00:00 | 2024-05-12T04:14:32.631287+00:00 | 46 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n \n int n = grid.size(), m = grid[0].size();\n vector<vector<int>>dp(n,vector<int>(m,INT_MIN));\n int res = INT_MIN;\n \n dp[0][0] = 0;\n \n int mi = grid[0][0];\n f... | 1 | 0 | ['Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Simple | Minimum top-left | DP | simple-minimum-top-left-dp-by-lovung-fpwv | Intuition\nDynamic Programming\n\n# Approach\ndp[i][j] will help to save value of minimum value of the top-left rectangle.\n\nMax score of jumping to have the d | lovung | NORMAL | 2024-05-12T04:11:16.157336+00:00 | 2024-05-12T04:20:39.420469+00:00 | 36 | false | # Intuition\nDynamic Programming\n\n# Approach\n`dp[i][j]` will help to save value of minimum value of the top-left rectangle.\n\nMax score of jumping to have the destination at a cell (i, j) is the different between `grid[i][j]` and minimum number in the top-left rectangle (except (i, j) because requirement `you have ... | 1 | 0 | ['Go'] | 0 |
maximum-difference-score-in-a-grid | ✅C++ Accepted | Suffix Maxima | Easy⛳ | c-accepted-suffix-maxima-easy-by-manii15-nfm0 | Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size(), | manii15 | NORMAL | 2024-05-12T04:06:22.851820+00:00 | 2024-05-12T04:06:22.851849+00:00 | 26 | false | <!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> large(n,vector<int>(m));\n large[n-1][m-1] = grid[n-1][m-1];\n \n for(int i=... | 1 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | Using Maximum element || Esay || Understandable | using-maximum-element-esay-understandabl-g1a7 | 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 | jimish6600 | NORMAL | 2024-05-12T04:04:10.105243+00:00 | 2024-05-12T04:04:10.105276+00:00 | 176 | 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 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | Java Clean Solution | java-clean-solution-by-shree_govind_jee-sl5f | Complexity\n- Time complexity:O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n*m)\n Add your space complexity here, e.g. O(n) \n\n# | Shree_Govind_Jee | NORMAL | 2024-05-12T04:03:20.705958+00:00 | 2024-05-12T04:03:20.705991+00:00 | 298 | false | # Complexity\n- Time complexity:$$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n*m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int maxScore(List<List<Integer>> grid) {\n int row = grid.size();\n int co... | 1 | 0 | ['Array', 'Math', 'Dynamic Programming', 'Recursion', 'Matrix', 'Java'] | 1 |
maximum-difference-score-in-a-grid | Matrix DP | matrix-dp-by-rajesh_sv-05n6 | Code\n\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n # DP\n # Time Complexity: O(mn)\n # Space Complexity: O(mn | rajesh_sv | NORMAL | 2024-05-12T04:01:56.154783+00:00 | 2024-05-12T17:50:17.462303+00:00 | 38 | false | # Code\n```\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n # DP\n # Time Complexity: O(mn)\n # Space Complexity: O(mn)\n m, n = len(grid), len(grid[0])\n dp = [[-inf] * (n+1) for _ in range(m+1)]\n ans = -inf\n for i in range(1, m+1):\n ... | 1 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
maximum-difference-score-in-a-grid | Easy Solution using DP C++ | easy-solution-using-dp-c-by-visheshjinda-klpk | Intuition\n The problem involves traversing a grid to find the maximum score attainable by following certain rules. Initially, we might consider a brute-force a | visheshjindal368 | NORMAL | 2024-05-12T04:01:42.222696+00:00 | 2024-05-12T04:01:42.222731+00:00 | 429 | false | # Intuition\n The problem involves traversing a grid to find the maximum score attainable by following certain rules. Initially, we might consider a brute-force approach of exploring all possible paths from the starting point to the ending point, but this would be inefficient. Instead, we can leverage dynamic programmi... | 1 | 0 | ['C++'] | 2 |
maximum-difference-score-in-a-grid | [C++] Intuition - Consider only a single step | c-intuition-consider-only-a-single-step-12vv3 | Intuition - \nLet\'s consider a series a->b, b->c, c->d, d->e. The total sum then would be b-a + c-b + d-c + e-d , which is finally same as e-a. So the differe | saiteja_balla0413 | NORMAL | 2024-05-12T04:01:03.003287+00:00 | 2024-05-12T04:03:57.105022+00:00 | 367 | false | **Intuition** - \nLet\'s consider a series a->b, b->c, c->d, d->e. The total sum then would be b-a + c-b + d-c + e-d , which is finally same as e-a. So the difference of ending and starting points would add to the result and the ending point should be the maximum value in the subgrid ` grid[i...m][j...n]`. \n\n**App... | 1 | 0 | [] | 2 |
maximum-difference-score-in-a-grid | [C++] Beats 100% runtime single dimension DP array | c-beats-100-runtime-single-dimension-dp-36s9w | IntuitionVerify that going from a cell 1 to 5 to 9 is the same as going from a cell 1 to 9:
5 - 1 + 9 - 5 = 9 - 1Therefore we only need to find the maximum diff | DuarteBarbosaRibeiro | NORMAL | 2025-04-02T15:23:45.177988+00:00 | 2025-04-02T15:23:45.177988+00:00 | 2 | false | # Intuition
Verify that going from a cell 1 to 5 to 9 is the same as going from a cell 1 to 9:
5 - 1 + 9 - 5 = 9 - 1
Therefore we only need to find the maximum difference between any cell and a cell to the bottom or right of it.
# Approach
We can use an array maximum with size of cols to keep track of the maximum ele... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | C++ | beats 66% | DP - Tabulation | c-beats-66-dp-tabulation-by-aryan-ki-cod-0wye | Approachuse recurrence
dp[i][j] = max(max(grid[i + 1][j], grid[i][j + 1]) -
grid[i][j] // 1 move
,
max(dp[i + 1][j] + grid[i + 1][j] - grid[i][j],
dp[i][j + 1] | Aryan-ki-codepanti | NORMAL | 2025-03-14T04:44:02.903503+00:00 | 2025-03-14T04:44:02.903503+00:00 | 3 | false | # Approach
<!-- Describe your approach to solving the problem. -->
use recurrence
dp[i][j] = max(max(grid[i + 1][j], grid[i][j + 1]) -
grid[i][j] // 1 move
,
max(dp[i + 1][j] + grid[i + 1][j] - grid[i][j],
... | 0 | 0 | ['Array', 'Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | scala solution | scala-solution-by-lyk4411-i1ho | IntuitionApproachComplexity
Time complexity:
Space complexity:
Codeor | lyk4411 | NORMAL | 2025-02-11T03:41:29.271230+00:00 | 2025-02-11T03:41:29.271230+00:00 | 1 | 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 | ['Scala'] | 0 |
maximum-difference-score-in-a-grid | Maximum Difference Score in a Grid | maximum-difference-score-in-a-grid-by-na-4k67 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Naeem_ABD | NORMAL | 2025-01-13T18:47:22.332925+00:00 | 2025-01-13T18:47:22.332925+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 | ['Python3'] | 0 |
maximum-difference-score-in-a-grid | [C++] Dynamic Programming | c-dynamic-programming-by-amanmehara-9pus | Code | amanmehara | NORMAL | 2025-01-11T06:08:25.568116+00:00 | 2025-01-11T06:08:25.568116+00:00 | 8 | false | # Code
```cpp []
class Solution {
public:
int maxScore(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
int max_score = INT_MIN;
vector<vector<int>> dp(m + 1, vector<int>(n + 1, INT_MAX));
for (int i = 0; i < m; i++) {
for (int j = 0; j < ... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Clever problem... Its DP but required paperwork first | clever-problem-its-dp-but-required-paper-o6au | IntuitionAt first, substraction might be hard. I think about jump game first, as I need to try each cell in that cell/column that could move to the current cell | minhtud04 | NORMAL | 2025-01-09T23:39:23.244383+00:00 | 2025-01-09T23:39:23.244383+00:00 | 8 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
At first, substraction might be hard. I think about jump game first, as I need to try each cell in that cell/column that could move to the current cell.
However, if we write the equation out:
- we jump our path as c1,c2,c3 --> all valu... | 0 | 0 | ['Python3'] | 0 |
maximum-difference-score-in-a-grid | SIMPLE RECURSION + MEMO C++ SOLUTION | simple-recursion-memo-c-solution-by-jeff-co0l | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Jeffrin2005 | NORMAL | 2025-01-05T03:50:40.973904+00:00 | 2025-01-05T03:50:40.973904+00:00 | 8 | 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-difference-score-in-a-grid | DP | dp-by-linda2024-xu46 | 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 | linda2024 | NORMAL | 2024-12-04T23:52:43.248194+00:00 | 2024-12-04T23:52:43.248251+00:00 | 4 | 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-difference-score-in-a-grid | Kotlin O(nm) time O(m) Space | kotlin-onm-time-om-space-by-bylazy-1iwr | Intuition\nThe maximum score for each cell is the difference between the cell\'s value and the minimum of the part of the matrix that is above and to the left o | bylazy | NORMAL | 2024-12-04T10:01:06.240196+00:00 | 2024-12-04T10:01:06.240231+00:00 | 2 | false | # Intuition\nThe maximum score for each cell is the difference between the cell\'s value and the minimum of the part of the matrix that is above and to the left of that cell.\n\n# Approach\nIn the array `m` we will store and maintain the minimum of the matrix up to and including the corresponding column.\n\n# Complexit... | 0 | 0 | ['Kotlin'] | 0 |
maximum-difference-score-in-a-grid | Easy Memoization Solution | easy-memoization-solution-by-roy_b-nmao | Intuition\n Describe your first thoughts on how to solve this problem. \nI know it\'s a weird way, but it still works.\n# Approach\n Describe your approach to s | roy_b | NORMAL | 2024-11-22T04:55:46.316271+00:00 | 2024-11-22T04:55:46.316303+00:00 | 32 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI know it\'s a weird way, but it still works.\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... | 0 | 0 | ['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'Matrix', 'C++', 'Java', 'Python3'] | 0 |
maximum-difference-score-in-a-grid | C++ Tabulation Easy solution | c-tabulation-easy-solution-by-user0374wc-t4xw | 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 | user0374Wc | NORMAL | 2024-11-15T14:54:37.326242+00:00 | 2024-11-15T14:54:37.326280+00:00 | 2 | 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-difference-score-in-a-grid | SIMPLE 5 LINE SOLUTION EVER ON INTERNET check out once if you don't believe me. | simple-5-line-solution-ever-on-internet-t8euj | Intuition\nwe just have to take record of initial and final position of each move and rest of the intermediate cells will always cancles each other \n\n# Approa | aniket_kumar_ | NORMAL | 2024-10-31T18:05:03.373850+00:00 | 2024-10-31T18:05:03.373877+00:00 | 6 | false | # Intuition\nwe just have to take record of initial and final position of each move and rest of the intermediate cells will always cancles each other \n\n# Approach\nfor each cell just look for the minimum value in it\'s to left part because max score can be made by min initial point and maximum end point\n\n# Complexi... | 0 | 0 | ['Array', 'Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Recursion + memoization || standard approach | recursion-memoization-standard-approach-3u16v | 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 | chanderveersinghchauhan08 | NORMAL | 2024-10-30T23:05:55.942021+00:00 | 2024-10-30T23:05:55.942043+00:00 | 4 | 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-difference-score-in-a-grid | Grid DP🎯 | Top Down➡️Bottom Up | ✔️Multi Tabulation✔️ | 🔥Unique DP Approach | Clean Code🔥 | grid-dp-top-downbottom-up-multi-tabulati-mbpd | \uD83D\uDE0A ~ \uD835\uDE52\uD835\uDE5E\uD835\uDE69\uD835\uDE5D \u2764\uFE0F \uD835\uDE57\uD835\uDE6E \uD835\uDE43\uD835\uDE5E\uD835\uDE67\uD835\uDE5A\uD835\uDE | hirenjoshi | NORMAL | 2024-10-19T10:31:18.284102+00:00 | 2024-10-19T19:53:43.749767+00:00 | 7 | false | \uD83D\uDE0A ~ \uD835\uDE52\uD835\uDE5E\uD835\uDE69\uD835\uDE5D \u2764\uFE0F \uD835\uDE57\uD835\uDE6E \uD835\uDE43\uD835\uDE5E\uD835\uDE67\uD835\uDE5A\uD835\uDE63\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n***Hello there! Take a look at the code and comments within it you\'ll g... | 0 | 0 | ['Array', 'Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Iterative DP. Time: O(rowsxcols), Space: O(cols) | iterative-dp-time-orowsxcols-space-ocols-mzh5 | Approach\n Describe your approach to solving the problem. \nTraverse matrix from bottom right exploring both options for each cells - bottom or to the right. St | iitjsagar | NORMAL | 2024-10-02T07:01:15.602535+00:00 | 2024-10-02T07:01:15.602572+00:00 | 0 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nTraverse matrix from bottom right exploring both options for each cells - bottom or to the right. Store the values in a 1-d array which will be updated as we move up the rows.\n\n# Complexity\n- Time complexity: $$O(ROWSxCOLS)$$\n<!-- Add your time co... | 0 | 0 | ['Python'] | 0 |
maximum-difference-score-in-a-grid | Basics DP in Matrix || O(N^2) | basics-dp-in-matrix-on2-by-dnanper-v0ie | 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 | dnanper | NORMAL | 2024-09-25T05:20:58.860114+00:00 | 2024-09-25T05:20:58.860148+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-difference-score-in-a-grid | Memo dp | memo-dp-by-code7you-vb39 | 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 | code7you | NORMAL | 2024-09-09T14:52:08.647813+00:00 | 2024-09-09T14:52:08.647836+00:00 | 5 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | 🔥Easy Explanation | |✅ Simple Solution | | 🧠Beginner friendly | easy-explanation-simple-solution-beginne-rg02 | \n# Approach\n1. Since we are allowed to start from any index initiate recursion call from all the indices\n2. For Every Index (i,j) There are 4 Choices.\n- Cho | Rahul_Hebbare | NORMAL | 2024-09-02T06:30:35.271892+00:00 | 2024-09-02T06:30:35.271925+00:00 | 6 | false | \n# Approach\n**1**. Since we are allowed to start from any index initiate recursion call from all the indices\n**2**. For Every Index (i,j) There are 4 Choices.\n- **Choice 1**:Move to right index `(i,j+1)` stop the further indices consideration\n- **Choice 2**:Move to right index `(i,j+1)` ,make recursive `(eg. funct... | 0 | 0 | ['Dynamic Programming', 'Backtracking', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Simple C++ solution | simple-c-solution-by-cyphermain-vt02 | Intuition\n Describe your first thoughts on how to solve this problem. \nTry to find the highest range in every possible sub-matrix / sub-problem.\n# Approach\n | cyphermain | NORMAL | 2024-08-22T11:17:36.267807+00:00 | 2024-08-22T11:17:36.267839+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to find the highest range in every possible sub-matrix / sub-problem.\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-... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | python beats 22.58 percent | python-beats-2258-percent-by-snah0902-k6lb | Code\npython3 []\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n \n rows = len(grid)\n cols = len(grid[0])\n | snah0902 | NORMAL | 2024-08-20T06:52:06.165534+00:00 | 2024-08-20T06:52:06.165558+00:00 | 12 | false | # Code\n```python3 []\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n \n rows = len(grid)\n cols = len(grid[0])\n largestMax = [[0 for _ in range(cols)] for _ in range(rows)]\n\n @cache\n def findMax(row, col):\n if row >= rows or col >= col... | 0 | 0 | ['Python3'] | 0 |
maximum-difference-score-in-a-grid | ✅Easy and Simple Solution ✅Clean Code | easy-and-simple-solution-clean-code-by-a-9r15 | 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-15T15:34:36.050953+00:00 | 2024-08-15T15:34:36.051011+00:00 | 6 | 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 * M)\n\n- Space complexity:... | 0 | 0 | ['Array', 'Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Easy to Understand || Dynamic Programming || Two - Approaches || C++ | easy-to-understand-dynamic-programming-t-d8vf | 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 | ksohelkhan064 | NORMAL | 2024-08-10T20:48:36.716292+00:00 | 2024-08-10T20:48:36.716318+00:00 | 16 | 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 | ['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Java || Memoization || O(N*N) | java-memoization-onn-by-gar1266doda-ah2x | 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 | gar1266doda | NORMAL | 2024-08-02T18:07:00.463208+00:00 | 2024-08-02T18:07:00.463238+00:00 | 2 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | ugly mutable scala solution to avoid MLE | ugly-mutable-scala-solution-to-avoid-mle-cjor | \nobject Solution {\n val arr = Array.fill(1001,1001)(0)\n def maxScore(grid: List[List[Int]]): Int =\n var i: Int = 0; var j: Int = 0\n arr(0)(0) = gri | vititov | NORMAL | 2024-07-15T22:27:10.946851+00:00 | 2024-07-15T22:27:10.946882+00:00 | 4 | false | ```\nobject Solution {\n val arr = Array.fill(1001,1001)(0)\n def maxScore(grid: List[List[Int]]): Int =\n var i: Int = 0; var j: Int = 0\n arr(0)(0) = grid(0)(0)\n var ans = Int.MinValue\n i = 1; while (i<grid.length) {\n arr(i)(0) = arr(i-1)(0) min grid(i)(0); ans = ans max (grid(i)(0) - arr(i-1)(0... | 0 | 0 | ['Matrix', 'Scala'] | 0 |
maximum-difference-score-in-a-grid | Easy Iterative Dp Solution | easy-iterative-dp-solution-by-kvivekcode-vxia | 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-07-09T06:26:44.002895+00:00 | 2024-07-09T06:26:44.002930+00:00 | 6 | 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 | ['Array', 'Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Beats 99.85% C++ Solution | beats-9985-c-solution-by-su47-vk0n | Intuition\nFinfing min upto index i,j and reducing it from grid[i][j] and iterating to find max out of all such differences \n\n# Approach\nIterate from 0,0 to | su47 | NORMAL | 2024-07-02T18:00:40.841722+00:00 | 2024-07-02T18:00:40.841745+00:00 | 1 | false | # Intuition\nFinfing min upto index i,j and reducing it from grid[i][j] and iterating to find max out of all such differences \n\n# Approach\nIterate from 0,0 to i,j notice upto this point all i-1,j and i,j-1 had been already calculated so can esily use them\nso\n minval(i,j) = min( minval( i-1 , j ), minval( i, j-1 ))... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | c++ || tabular dp || O(m*n) | c-tabular-dp-omn-by-sarthakrautelanew-91fq | 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 | sarthakrautelanew | NORMAL | 2024-06-30T09:19:38.481433+00:00 | 2024-06-30T09:19:38.481458+00:00 | 8 | 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)$$ -->\nO(n*m)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Explained the approach || DP solution | explained-the-approach-dp-solution-by-ar-fp6j | Intuition\nmax(c2-c1)=>c2 should be maximum and c1 should be minimum\n# Approach\nApproach written in the code in form of comments:)\n# Complexity\n- Time comp | arsalan21 | NORMAL | 2024-06-28T13:29:41.244831+00:00 | 2024-06-28T13:30:32.664925+00:00 | 10 | false | # Intuition\nmax(c2-c1)=>c2 should be maximum and c1 should be minimum\n# Approach\nApproach written in the code in form of comments:)\n# Complexity\n- Time complexity:\nO(n*m)\n- Space complexity:\nO(n*m)\n# Code\n```\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n=grid.size(),m... | 0 | 0 | ['Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Submatrix max minus current corner | submatrix-max-minus-current-corner-by-su-v72b | Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n# | Sukhvansh2004 | NORMAL | 2024-06-26T16:07:45.465012+00:00 | 2024-06-26T16:07:45.465055+00:00 | 1 | false | # Complexity\n- Time complexity: $$O(mn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(mn)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int m;\n int n;\n\n void recurse(vector<vector<int>>& dp, vector<vector<int>>& ... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | DP | dp-by-karandumdumguy-yfbw | 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 | karandumdumguy | NORMAL | 2024-06-22T14:21:54.688800+00:00 | 2024-06-22T14:21:54.688827+00:00 | 5 | 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(mxn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(mxn)\n<!-- Add your space complexity here, e.... | 0 | 0 | ['Dynamic Programming', 'Matrix', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Brute Force DP with optimised solution with comments and Intution | brute-force-dp-with-optimised-solution-w-kq7q | Brute Force Solution(TLE)\nHere dp[i][j]-> It tells we have maximum score we can get if we consider from (i,j) to (n-1,m-1)\n\nclass Solution {\npublic:\n us | vaibhav2304 | NORMAL | 2024-06-22T05:10:44.171921+00:00 | 2024-06-22T05:11:46.490178+00:00 | 3 | false | * Brute Force Solution(TLE)\nHere dp[i][j]-> It tells we have maximum score we can get if we consider from (i,j) to (n-1,m-1)\n```\nclass Solution {\npublic:\n using v1d = vector<int>;\n using v2d = vector<v1d>;\n int maxScore(vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n v... | 0 | 0 | ['Dynamic Programming', 'C'] | 0 |
maximum-difference-score-in-a-grid | Dynamic Programming --- C++ | dynamic-programming-c-by-treerecursion-t5yl | Intuition\nOptimal Substructure - Dynamic Programming (DP)\n\n# Approach\nDP (bottom up)\n\nGiven grid[i][j] as a matrix, starting from any cell at $(i, j)$, le | treerecursion | NORMAL | 2024-06-20T13:41:25.319427+00:00 | 2024-06-20T13:41:25.319461+00:00 | 1 | false | # Intuition\nOptimal Substructure - Dynamic Programming (DP)\n\n# Approach\nDP (bottom up)\n\nGiven `grid[i][j]` as a matrix, starting from any cell at $(i, j)$, let `dp[i][j]` cache the maximum score attainable. We need to consider all other cells $(i\', j\')$ if any, with $i\'> i, j\'=j$ (downwards) and $i\'=i, j\'>... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | [C++] DP | c-dp-by-ericyxing-xmp4 | Intuition\nFor each element $grid[i][j]$, find the smallest element on the top-left of it.\n\n# Code\n\nclass Solution {\npublic:\n int maxScore(vector<vecto | EricYXing | NORMAL | 2024-06-17T19:42:23.967194+00:00 | 2024-06-17T19:45:12.981588+00:00 | 6 | false | # Intuition\nFor each element $grid[i][j]$, find the smallest element on the top-left of it.\n\n# Code\n```\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size(), ans = INT_MIN;\n vector<int> dp(n, INT_MAX);\n dp[0] = grid[0][0];\n ... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-difference-score-in-a-grid | Swift | Dynamic Programming | swift-dynamic-programming-by-pagafan7as-jexd | The main idea is that the score depends only on the starting and ending cells and not on the specific path.\n\nThis observation allows us to compute the max sco | pagafan7as | NORMAL | 2024-06-16T01:18:16.282520+00:00 | 2024-06-16T01:18:16.282539+00:00 | 1 | false | The main idea is that the score depends only on the starting and ending cells and not on the specific path.\n\nThis observation allows us to compute the max score in linear time using dynamic programming.\n\n# Code\n```\nclass Solution {\n func maxScore(_ grid: [[Int]]) -> Int {\n let (m, n) = (grid.count, gr... | 0 | 0 | ['Swift'] | 0 |
maximum-difference-score-in-a-grid | C++ solution #intution_simpleAF | c-solution-intution_simpleaf-by-chen_ayr-ret0 | Intuition\nWe can see that we can only move down and right, and taking as many jumps in between, for a certain start and certain end, it doesn\'t matter what pa | Chen_ayr | NORMAL | 2024-06-06T03:34:00.967402+00:00 | 2024-06-06T03:34:00.967434+00:00 | 3 | false | # Intuition\nWe can see that we can only move down and right, and taking as many jumps in between, for a certain start and certain end, it doesn\'t matter what path we take, the final score will be the same.\n\n# Approach\nI make another grid named matrix where we store at any index(i,j), the maximum in the sub-grid(n,... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | C++ Simple Solution | Track previous minimum. | c-simple-solution-track-previous-minimum-w23m | Intuition\nFind the minimum element from indices (0,0) to (i, j) where index (i, j)is not included. Then, take the difference of current cell with the current m | deepakchaurasiya | NORMAL | 2024-06-01T17:04:05.678867+00:00 | 2024-06-01T17:04:05.678895+00:00 | 11 | false | # Intuition\nFind the minimum element from indices (0,0) to (i, j) where index (i, j)is not included. Then, take the difference of current cell with the current minimum value.\n i.e. ans = max(ans, grid[i][j] - prev_min[i][j]);\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity: \nO(m*n)\n\n# Code\n``... | 0 | 0 | ['C++'] | 0 |
maximum-difference-score-in-a-grid | DP SOLUTION(tabulation) | dp-solutiontabulation-by-nithi_0805-o89n | 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 | Nithi_0805 | NORMAL | 2024-05-31T14:43:55.155294+00:00 | 2024-05-31T14:43:55.155317+00:00 | 8 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | DP 10ms - Java O(M*N) | O(M*N) | dp-10ms-java-omn-omn-by-wangcai20-qj2e | Intuition\n Describe your first thoughts on how to solve this problem. \nDP 2D matrix to track max score of every cell can get from top and left. Along the way, | wangcai20 | NORMAL | 2024-05-30T20:31:22.418624+00:00 | 2024-05-30T20:31:22.418649+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDP 2D matrix to track max score of every cell can get from top and left. Along the way, collect the global max and min for return.\n```\ndp[i][j] = max(0, dp[i - 1][j] + (mat[i][j] - mat[i - 1][j]), dp[i][j - 1] + (mat[i][j] - mat[i][j - ... | 0 | 0 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | Java solution || Using 2D array to store max till that point from bottom end|| | java-solution-using-2d-array-to-store-ma-dn3x | 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 | user7683C | NORMAL | 2024-05-30T11:35:53.248702+00:00 | 2024-05-30T11:35:53.248719+00:00 | 4 | 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 | ['Java'] | 0 |
maximum-difference-score-in-a-grid | EASY DP RECURSIVE DP JAVA | easy-dp-recursive-dp-java-by-divyanshuag-vel0 | 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 | Divyanshuagarwal23 | NORMAL | 2024-05-22T13:20:43.035903+00:00 | 2024-05-22T13:20:43.035947+00:00 | 14 | 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 | ['Array', 'Dynamic Programming', 'Matrix', 'Java'] | 0 |
maximum-difference-score-in-a-grid | Intuitive DP solution | intuitive-dp-solution-by-tanshik-b639 | Intuition\nBy looking at the equation for finding the max difference, we can see that the result is equal to the max destination - origin.\n\nfor example, for t | tanshik | NORMAL | 2024-05-22T01:18:15.020379+00:00 | 2024-05-22T01:18:15.020411+00:00 | 20 | false | # Intuition\nBy looking at the equation for finding the max difference, we can see that the result is equal to the max destination - origin.\n\nfor example, for the path c1 -> c4, (c2 - c1) + (c3 - c2) + (c4 - c3) = c4 - c1. The intermediary steps cancel out.\n\nThen, the problem becomes finding the maximum difference ... | 0 | 0 | ['Python3'] | 0 |
maximum-difference-score-in-a-grid | DP | dp-by-angle-e1s5 | 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 | angle_ | NORMAL | 2024-05-21T21:12:32.212905+00:00 | 2024-05-21T21:12:32.212925+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: o(m*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(m*n)\n<!-- Add your space complexity here, e.g... | 0 | 0 | ['Python'] | 0 |
print-foobar-alternately | 5 Python threading solutions (Barrier, Event, Condition, Lock, Semaphore) with explanation | 5-python-threading-solutions-barrier-eve-jmla | Raise a barrier which makes both threads wait for each other before they are allowed to continue. foo prints before reaching the barrier. bar prints after reach | mereck | NORMAL | 2019-07-16T16:25:36.561824+00:00 | 2019-07-16T16:28:41.448921+00:00 | 12,052 | false | Raise a barrier which makes both threads wait for each other before they are allowed to continue. `foo` prints before reaching the barrier. `bar` prints after reaching the barrier. \n\n```\nfrom threading import Barrier\n\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.barrier = Barrier(2)\... | 178 | 1 | [] | 15 |
print-foobar-alternately | [Java] Semaphore solution | java-semaphore-solution-by-yujd13-v85z | \nimport java.util.concurrent.Semaphore;\nclass FooBar {\n private int n;\n Semaphore s = new Semaphore(0);\n Semaphore s2 = new Semaphore(1);\n\n p | yujd13 | NORMAL | 2019-07-12T20:11:34.159056+00:00 | 2019-07-12T20:11:34.159098+00:00 | 11,550 | false | ```\nimport java.util.concurrent.Semaphore;\nclass FooBar {\n private int n;\n Semaphore s = new Semaphore(0);\n Semaphore s2 = new Semaphore(1);\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n\n for (int i = 0; i < n; i... | 66 | 3 | [] | 13 |
print-foobar-alternately | [Java] 4 Java threading solutions (Synchronized,Lock,Volatile,CAS) | java-4-java-threading-solutions-synchron-l5it | Overall,solution 2(lock+condition) performs better:\n comparing to solution 1,solution 2 using more waiting queues to avoid unnecessary notify, reduce lock comp | supertizzy | NORMAL | 2019-08-01T06:57:11.200241+00:00 | 2019-08-26T03:37:22.700001+00:00 | 7,175 | false | Overall,solution 2(lock+condition) performs better:\n* comparing to solution 1,solution 2 using more waiting queues to avoid unnecessary notify, reduce lock competition.\n* comparing to solution 3 and solution 4,solution 2 using synchronization queue to avoid unnecessary cpu execution.\n\n## 1.Synchronized(monitor exit... | 45 | 1 | [] | 16 |
print-foobar-alternately | C++ solution using mutex + CV (w/ explanation) | c-solution-using-mutex-cv-w-explanation-ld8ao | This is basically a semaphore. We use the flag fooTurn in the predicate of wait() to determine if the lock should be freed.\n\nBecause there are only two states | sdk__ | NORMAL | 2020-11-26T08:08:36.072014+00:00 | 2020-11-27T06:28:03.018659+00:00 | 4,031 | false | This is basically a semaphore. We use the flag `fooTurn` in the predicate of `wait()` to determine if the lock should be freed.\n\nBecause there are only two states (foo and bar), we can get away with using a boolean for the flag and `notify_one()`. If there were more states, we could scale this using an int flag and `... | 22 | 1 | ['C'] | 5 |
print-foobar-alternately | an easy c++ solution using two mutex | an-easy-c-solution-using-two-mutex-by-ti-brgu | \nclass FooBar {\nprivate:\n int n;\n mutex m1, m2;\n\npublic:\n FooBar(int n) {\n this->n = n;\n m2.lock();\n }\n\n void foo(funct | tinyalpha | NORMAL | 2019-07-22T12:52:23.990342+00:00 | 2019-07-22T12:52:23.990420+00:00 | 2,977 | false | ```\nclass FooBar {\nprivate:\n int n;\n mutex m1, m2;\n\npublic:\n FooBar(int n) {\n this->n = n;\n m2.lock();\n }\n\n void foo(function<void()> printFoo) {\n for (int i = 0; i < n; i++) {\n m1.lock();\n \t// printFoo() outputs "foo". Do not change or remove this l... | 19 | 11 | [] | 7 |
print-foobar-alternately | Java Semaphore with explaination | java-semaphore-with-explaination-by-flor-6zxz | The argument to the Semaphore instance is the number of "permits" that are available. It can be any integer, not just 0 or 1.\nFor runb all acquire() calls will | flora1155665 | NORMAL | 2019-07-14T04:02:36.525571+00:00 | 2019-07-14T04:03:13.704946+00:00 | 3,446 | false | The argument to the Semaphore instance is the number of "permits" that are available. It can be any integer, not just 0 or 1.\nFor `runb` all acquire() calls will block and tryAcquire() calls will return false, until you do a release().\nFor `runf` the first acquire() calls will succeed and the rest will block until th... | 18 | 0 | ['Java'] | 3 |
print-foobar-alternately | C/C++ | 3 ways to solve: atomic; mutex; semaphore | cc-3-ways-to-solve-atomic-mutex-semaphor-sqhw | 1st way in C++: atomic\nExplanation: \n\natomic variables atomic<T> have mutex locks embedded in them. \n\nThe idea is that, if a thread acquires the lock, no o | nuoxoxo | NORMAL | 2022-08-07T09:52:53.025312+00:00 | 2022-08-07T09:52:53.025356+00:00 | 3,217 | false | # 1st way in C++: atomic\nExplanation: \n\natomic variables `atomic<T>` have `mutex locks` embedded in them. \n\nThe idea is that, if a thread acquires the lock, no other thread can acquire it (ie. modify it) until it is released.\n\nWell just how to tell the program to lock/unlock? \nUse `this_thread::yield()`, which,... | 17 | 0 | ['C', 'C++'] | 3 |
print-foobar-alternately | C++ Super-Simple Solution Using 2 Semaphores | c-super-simple-solution-using-2-semaphor-03ag | \n#include <semaphore.h>\n\nclass FooBar {\nprivate:\n int n;\n sem_t foo_sem;\n sem_t bar_sem;\n \npublic:\n FooBar(int n) {\n this->n = | yehudisk | NORMAL | 2020-11-19T17:38:06.272539+00:00 | 2020-11-19T17:40:33.640481+00:00 | 2,131 | false | ```\n#include <semaphore.h>\n\nclass FooBar {\nprivate:\n int n;\n sem_t foo_sem;\n sem_t bar_sem;\n \npublic:\n FooBar(int n) {\n this->n = n;\n sem_init(&foo_sem, 0, 1);\n sem_init(&bar_sem, 0, 0);\n }\n \n ~FooBar() {\n sem_destroy(&foo_sem);\n sem_destroy(&... | 15 | 0 | ['C'] | 6 |
print-foobar-alternately | python3: 40ms 86.64% Faster 100% Less memory, using threading.Lock | python3-40ms-8664-faster-100-less-memory-1osz | \nfrom threading import Lock\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.foo_lock = Lock()\n self.bar_lock = Lock()\n | sreejeet | NORMAL | 2020-04-29T18:13:02.948367+00:00 | 2020-04-29T18:13:02.948403+00:00 | 2,624 | false | ```\nfrom threading import Lock\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.foo_lock = Lock()\n self.bar_lock = Lock()\n self.bar_lock.acquire()\n\n\n def foo(self, printFoo: \'Callable[[], None]\') -> None:\n for i in range(self.n):\n self.foo_lock.ac... | 14 | 0 | ['Python', 'Python3'] | 4 |
print-foobar-alternately | JAVA Boolean Volatile solution | java-boolean-volatile-solution-by-poorva-jfeq | \nclass FooBar {\n private int n;\n\n volatile boolean callFoo;\n volatile boolean callBar;\n\n public FooBar(int n) {\n | poorvank | NORMAL | 2019-07-13T12:13:55.029543+00:00 | 2019-07-13T12:13:55.029578+00:00 | 2,289 | false | ```\nclass FooBar {\n private int n;\n\n volatile boolean callFoo;\n volatile boolean callBar;\n\n public FooBar(int n) {\n this.n = n;\n callFoo = true;\n callBar = false;\n }\n\n public synchronized void foo(Runnable printFoo) throws Interrupt... | 12 | 0 | [] | 5 |
print-foobar-alternately | C++, 104 ms, 10.5 MB | c-104-ms-105-mb-by-drus-pyl8 | Please, note : solution with mutex+condition_variable is 2-3x slower comparing with atomic.\n\n\nclass FooBar {\nprivate:\n int n;\n std::atomic<bool> b{t | drus | NORMAL | 2020-02-11T14:49:43.207774+00:00 | 2020-02-11T14:52:55.251883+00:00 | 1,703 | false | Please, note : solution with mutex+condition_variable is 2-3x slower comparing with atomic.\n\n```\nclass FooBar {\nprivate:\n int n;\n std::atomic<bool> b{true};\n\npublic:\n FooBar(int n) {\n this->n = n;\n }\n\n void foo(std::function<void()> printFoo)\n {\n for (int i = 0; i < n; i++... | 9 | 0 | [] | 3 |
print-foobar-alternately | Fast Java solution with good explanation. | fast-java-solution-with-good-explanation-eqpt | This is a standart "producer-consumer" problem. Read this article:\nhttps://www.baeldung.com/java-wait-notify\n\nI hope this helps :)\n\n\nclass FooBar {\n p | slav40 | NORMAL | 2019-07-19T07:07:34.167214+00:00 | 2019-07-19T07:13:34.253012+00:00 | 1,400 | false | This is a standart "producer-consumer" problem. Read this article:\nhttps://www.baeldung.com/java-wait-notify\n\nI hope this helps :)\n\n```\nclass FooBar {\n private int n;\n private boolean printfoo = true; // set value to true so we can assure that foo() will be called first\n\n public FooBar(int n) {\n ... | 9 | 0 | [] | 2 |
print-foobar-alternately | Can anyone help me understand why am I getting TLE? | can-anyone-help-me-understand-why-am-i-g-cig5 | This seems to be failing for n=4. When running the code in Intellij it seems to work fine:\n\n\nclass FooBar {\n private final int n;\n private volatile i | abc132 | NORMAL | 2019-07-16T22:17:50.680314+00:00 | 2019-07-16T22:17:50.680356+00:00 | 850 | false | This seems to be failing for n=4. When running the code in Intellij it seems to work fine:\n\n```\nclass FooBar {\n private final int n;\n private volatile int k = 0;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException { \n ... | 9 | 0 | [] | 4 |
print-foobar-alternately | Python 3 | 6 Approaches | Explanation | python-3-6-approaches-explanation-by-ido-tlv2 | Before you proceed\n- Intuition: Make sure the executing order using Lock or similar mechanism.\n- Technically 8 approaches since the first two can be rewrote u | idontknoooo | NORMAL | 2022-12-26T21:08:19.354262+00:00 | 2022-12-26T21:21:08.916317+00:00 | 1,243 | false | ## Before you proceed\n- **Intuition**: Make sure the executing order using `Lock` or similar mechanism.\n- Technically 8 approaches since the first two can be rewrote using `Semaphore`. \n\n## Approach \\#1. Lock/Semaphore only\n```python\nfrom threading import Lock\nclass FooBar:\n def __init__(self, n):\n ... | 8 | 0 | ['Concurrency', 'Python3'] | 2 |
print-foobar-alternately | C Solution using 2 semaphores | c-solution-using-2-semaphores-by-debbiea-r7p7 | \ntypedef struct \n{\n int n;\n sem_t foo_;\n sem_t bar_;\n \n}FooBar;\n\n\n\nFooBar* fooBarCreate(int n) \n{\n \n\n FooBar* obj = (FooBar*) m | debbiealter | NORMAL | 2020-08-11T10:23:00.889739+00:00 | 2020-08-11T10:26:56.583968+00:00 | 700 | false | ```\ntypedef struct \n{\n int n;\n sem_t foo_;\n sem_t bar_;\n \n}FooBar;\n\n\n\nFooBar* fooBarCreate(int n) \n{\n \n\n FooBar* obj = (FooBar*) malloc(sizeof(FooBar));\n obj->n = n;\n\t//initialize the semaphores\n sem_init(&obj->foo_, 0, 1);\n sem_init(&obj->bar_, 0, 0);\n return obj;\n}\... | 8 | 0 | [] | 0 |
print-foobar-alternately | [Java] Simple solution using two semaphores | java-simple-solution-using-two-semaphore-ha2e | The solution uses two semaphores which correspond to the foo and bar methods. \n- We initialize the foo semaphore with a single permit to permit the thread to i | michaeltruong | NORMAL | 2020-04-09T00:06:45.939875+00:00 | 2020-04-09T00:08:42.017860+00:00 | 847 | false | The solution uses two semaphores which correspond to the foo and bar methods. \n- We initialize the foo semaphore with a single permit to permit the thread to immediately acquire it and print foo. \n- The bar semaphore is initialized without a permit and requires something to increment the number of permits to be consu... | 8 | 0 | ['Java'] | 3 |
print-foobar-alternately | Simple solution with channels | Golang | simple-solution-with-channels-golang-by-klsjf | Approach\nAfter printing foo wait while bar is printed and the other way around. For this purpose we use a channel with zero capacity. Bar and Foo send a value | ivanterekh | NORMAL | 2024-02-29T14:53:10.988702+00:00 | 2024-02-29T14:53:10.988730+00:00 | 464 | false | # Approach\nAfter printing `foo` wait while `bar` is printed and the other way around. For this purpose we use a channel with zero capacity. `Bar` and `Foo` send a value to the channel, than wait for a feedback from each other.\n\n# Code\n```\ntype FooBar struct {\n\tn int\n ch chan int\n}\n\nfunc NewFooBar(n int) *... | 6 | 0 | ['Go'] | 0 |
print-foobar-alternately | [Java] Semaphore in Details Explanation With Brute Force Example | java-semaphore-in-details-explanation-wi-6rf7 | Brute Force Approach\n\n\nclass FooBar {\n private int n;\n int c = 0;\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runn | hridoy100 | NORMAL | 2023-01-24T05:41:58.048256+00:00 | 2023-01-24T05:41:58.048301+00:00 | 2,101 | false | # Brute Force Approach\n\n```\nclass FooBar {\n private int n;\n int c = 0;\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n while(c>0){\n continue;\n ... | 6 | 0 | ['Java'] | 2 |
print-foobar-alternately | Java | Beat 85% | Simple wait and notify solution | java-beat-85-simple-wait-and-notify-solu-0uxr | Simple Wait and Notify logic. Please upvote \n\n~~~\nclass FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n \n vol | rougef4ak | NORMAL | 2022-09-05T16:51:10.036198+00:00 | 2022-09-05T16:52:00.842089+00:00 | 1,736 | false | Simple Wait and Notify logic. Please upvote \n\n~~~\nclass FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n \n volatile boolean printF = true;\n\n public void foo(Runnable printFoo) throws InterruptedException {\n for (int i = 0; i < n; i++) {\n ... | 6 | 0 | ['Java'] | 2 |
print-foobar-alternately | c++ efficient & clean solution using 2 semaphore | c-efficient-clean-solution-using-2-semap-uawi | // we have to include the semaphore header file ,as c++ 20 is not available in our LC editor currently\n\n\n#include <semaphore.h>\nclass FooBar {\nprivate:\n | NextThread | NORMAL | 2022-01-17T13:49:59.600331+00:00 | 2022-01-17T13:49:59.600375+00:00 | 406 | false | // we have to include the semaphore header file ,as c++ 20 is not available in our LC editor currently\n\n```\n#include <semaphore.h>\nclass FooBar {\nprivate:\n int n;\n sem_t foo_sem;\n sem_t bar_sem;\n \npublic:\n FooBar(int n) {\n this->n = n;\n sem_init(&foo_sem, 0, 1);\n sem_in... | 5 | 0 | ['C'] | 1 |
print-foobar-alternately | [JAVA] Very Simple Synchronized Solution | java-very-simple-synchronized-solution-b-ni1k | \nclass FooBar {\n private int n;\n boolean runFoo; // boolean to check if Thread A (the one calling foo()) is in execution\n \n public FooBar(int n | aarjavsheth | NORMAL | 2021-03-20T06:27:08.264545+00:00 | 2021-03-20T06:27:08.264572+00:00 | 1,083 | false | ``` \nclass FooBar {\n private int n;\n boolean runFoo; // boolean to check if Thread A (the one calling foo()) is in execution\n \n public FooBar(int n) {\n this.n = n;\n runFoo = true;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n \n for (int ... | 5 | 0 | ['Java'] | 1 |
print-foobar-alternately | C++ std::atomic<bool> solution with yielding | c-stdatomicbool-solution-with-yielding-b-ga3g | This solution uses no mutexes/locks, and it is somewhat faster than locking/conditionals on LeetCode\'s OJ. That being said, if you take this code and run it on | aboulmagd | NORMAL | 2019-12-05T00:23:46.439919+00:00 | 2019-12-05T00:24:35.783199+00:00 | 568 | false | This solution uses no mutexes/locks, and it is somewhat faster than locking/conditionals on LeetCode\'s OJ. That being said, if you take this code and run it on your own machine, it may be a LOT slower than the one that uses locks/conditionals and has to wait/notify...So take this solution with a grain of salt, please.... | 5 | 0 | ['C'] | 2 |
print-foobar-alternately | Python solution using Lock | python-solution-using-lock-by-nightybear-5etu | Hi, below is my python solution using Lock, feel free to give idea.\n\n\nfrom threading import Lock\nclass FooBar:\n def __init__(self, n):\n self.n = | nightybear | NORMAL | 2019-08-16T03:46:37.095209+00:00 | 2019-08-16T03:46:37.095247+00:00 | 1,017 | false | Hi, below is my python solution using Lock, feel free to give idea.\n\n```\nfrom threading import Lock\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.lock1 = Lock()\n self.lock2 = Lock()\n \n self.lock1.acquire()\n\n\n def foo(self, printFoo: \'Callable[[], None]\')... | 5 | 1 | ['Python', 'Python3'] | 1 |
print-foobar-alternately | C# using AutoResetEvent | c-using-autoresetevent-by-alphasierra-y7ts | ```class FooBar\n {\n\t\t// initialized to true to indicate the first time there is no need to wait i.e. "foo" gets printed rightaway\n private AutoRe | alphasierra | NORMAL | 2019-07-13T17:56:37.438784+00:00 | 2019-07-13T17:57:02.356676+00:00 | 328 | false | ```class FooBar\n {\n\t\t// initialized to true to indicate the first time there is no need to wait i.e. "foo" gets printed rightaway\n private AutoResetEvent evt1 = new AutoResetEvent(true);\n\t\t\n\t\t// initialize to false to indicate that first time there is a need to wait i.e. "bar" won\'t get printed un... | 5 | 0 | [] | 0 |
print-foobar-alternately | Python 3 - Semaphore | python-3-semaphore-by-awice-o5wz | \nfrom threading import Semaphore\n\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.foosema = Semaphore(1)\n self.barsema = | awice | NORMAL | 2019-07-12T21:04:41.329113+00:00 | 2019-07-12T21:04:52.359779+00:00 | 1,168 | false | ```\nfrom threading import Semaphore\n\nclass FooBar:\n def __init__(self, n):\n self.n = n\n self.foosema = Semaphore(1)\n self.barsema = Semaphore(0)\n\n def foo(self, printFoo):\n for i in range(self.n):\n self.foosema.acquire()\n printFoo()\n self.b... | 5 | 1 | [] | 1 |
print-foobar-alternately | Simple Solution using await & notify | java | simple-solution-using-await-notify-java-iajke | Intuition\nHere i am using boolean flag and concept of bussy wait to check on condition and print something.\n\ni wait till the condition is not in desired stat | gaurav-x5 | NORMAL | 2023-08-27T20:14:17.198418+00:00 | 2023-08-27T20:21:49.877861+00:00 | 1,137 | false | # Intuition\nHere i am using boolean flag and concept of bussy wait to check on condition and print something.\n\ni wait till the condition is not in desired state and once someOther thread notifies me the values has changed i check the condition again and proceed if the condition succeeds.\n\n# Code\n```\nclass FooBar... | 4 | 0 | ['Java'] | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.