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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
longest-subarray-of-1s-after-deleting-one-element | Sliding Window approach | Python / JS Solution | sliding-window-approach-python-js-soluti-cxxy | Hello Tenno Leetcoders, \n\nFor this problem, we are given a binary array nums, you should delete one element from it.\n\nReturn the size of the longest non-emp | TFDLeeter | NORMAL | 2023-07-05T01:43:30.575362+00:00 | 2023-07-05T01:43:30.575388+00:00 | 805 | false | Hello **Tenno Leetcoders**, \n\nFor this problem, we are given a binary array nums, you should delete one element from it.\n\nReturn the size of the longest non-empty subarray containing only 1\'s in the resulting array. Return 0 if there is no such subarray.\n\n#### Explanation\n\nThis problem, We are given a binary a... | 11 | 0 | ['Sliding Window', 'Python3', 'JavaScript'] | 3 |
longest-subarray-of-1s-after-deleting-one-element | Dynamic Programming Approach O(n) time, O(1) space with Explanation (C++) | dynamic-programming-approach-on-time-o1-v292z | Most of the solutions provided in discussion seems to be using sliding window approach.\nHere I povided a simple DP approach with same time/space complexity. Th | szzzwno123 | NORMAL | 2020-06-27T17:59:05.013013+00:00 | 2020-06-27T18:01:24.201427+00:00 | 876 | false | Most of the solutions provided in discussion seems to be using sliding window approach.\nHere I povided a simple DP approach with same time/space complexity. This is very close to LC 196 - House Robber\n\nDefine: \nD[i] := longest subarray ends at nums[i] with all ones, with one deletion used\nN[i] := longest subarray ... | 11 | 0 | [] | 4 |
longest-subarray-of-1s-after-deleting-one-element | ✅ C++ || Beginner [Easy To Understand] || Sliding Window | c-beginner-easy-to-understand-sliding-wi-tcmz | Logic Simplified\n\n while(window exists)\n {\n if(current is 1)\n Add 1 to window\n else // means current is 0[bcoz array is bin | 99NotOut_half_dead | NORMAL | 2021-09-17T15:15:24.216119+00:00 | 2021-09-17T15:21:17.754663+00:00 | 1,006 | false | # ***Logic Simplified***\n```\n while(window exists)\n {\n if(current is 1)\n Add 1 to window\n else // means current is 0[bcoz array is binary]\n {\n Making space for adding 0 element if required : \n this while loop may or may not run depending upon fre... | 10 | 0 | ['C'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | O(n) Solution | on-solution-by-malikdinar-30e9 | Complexity\n- Time complexity:\nO(n)\n\n\n# Code\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n let co | malikdinar | NORMAL | 2023-07-05T07:22:36.697868+00:00 | 2023-07-05T07:24:17.184582+00:00 | 948 | false | # Complexity\n- Time complexity:\nO(n)\n\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n let count = 0;\n let array = []\n for(let i = 0;i<nums.length;i++){\n if(nums[i]==1){\n count++\n }else {\n array.push(... | 9 | 0 | ['Array', 'JavaScript'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Sliding Window | Easy to understand | C++ | sliding-window-easy-to-understand-c-by-w-2zt1 | Intuition\nMaintain the longest subarray window with at most 1 "0" in it.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThis is a | warrior0331 | NORMAL | 2023-07-05T05:17:41.442937+00:00 | 2023-07-05T05:17:41.442970+00:00 | 1,840 | false | # Intuition\nMaintain the longest subarray window with at most 1 "0" in it.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThis is a variable sized sliding window problem in which the window size depends on the number of "0" in the window. If we find the maximum sized window with at... | 9 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | ✅ One Line Solution | one-line-solution-by-mikposp-xqkt | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)Code #1.1 - One LineTime complexity: O(n). Space com | MikPosp | NORMAL | 2025-02-17T17:02:55.175734+00:00 | 2025-02-17T17:02:55.175734+00:00 | 878 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)
# Code #1.1 - One Line
Time complexity: $$O(n)$$. Space complexity: $$O(n)$$.
```python3
class Solution:
def longestSubarray(self, a: List[int]) -> int:
return max(map(add,(f:=lambda a:[0,*accumulat... | 8 | 2 | ['Array', 'Prefix Sum', 'Python', 'Python3'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Beats 💯; Sliding Window Aproach ; ✅ Easy to Understand✅ | beats-sliding-window-aproach-easy-to-und-3m48 | Code | 20250409.hema260706 | NORMAL | 2025-01-09T07:34:38.024955+00:00 | 2025-01-09T07:34:38.024955+00:00 | 1,466 | false | 
# Code
```cpp []
class Solution {
public:
int longestSubarray(vector<int>& nums) {
int left = 0, maxLength = 0, zeroCount = 0;
for (int right = 0; right < nums.size(); ++right) {
... | 8 | 1 | ['Sliding Window', 'C++', 'Java', 'Python3'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | very simple easy implementation only 1 loop with no extra space, best solution | very-simple-easy-implementation-only-1-l-5e6l | Intuition\nThe problem requires finding the length of the longest subarray containing only 1s after flipping at most one 0 to 1. One approach could be to utiliz | Have-To-Do-Every-Thing | NORMAL | 2024-04-08T14:06:42.478836+00:00 | 2024-04-08T17:15:36.018942+00:00 | 1,440 | false | # Intuition\nThe problem requires finding the length of the longest subarray containing only 1s after flipping at most one 0 to 1. One approach could be to utilize a sliding window technique to keep track of the longest subarray with only one zero. Once the zero occur the track that we made till now we compare with pre... | 8 | 0 | ['Array', 'Math', 'Sliding Window', 'Counting', 'Prefix Sum', 'Python', 'C++', 'Java', 'JavaScript', 'C#'] | 3 |
longest-subarray-of-1s-after-deleting-one-element | Python 3 || 6 lines, w/ explanation || T/S: 99% / 72% | python-3-6-lines-w-explanation-ts-99-72-otfr6 | Here\'s how the code works:\n\n\n1. We check whether there are are either only 1s or only 0s innums. If either case is true, we are done.\n\n1. We use groupby | Spaulding_ | NORMAL | 2023-07-05T06:44:13.361835+00:00 | 2024-06-04T20:33:14.105650+00:00 | 610 | false | Here\'s how the code works:\n\n\n1. We check whether there are are either only 1s or only 0s in`nums`. If either case is true, we are done.\n\n1. We use `groupby` to parse `nums` into groups of like-digit groups. For example:\n```\n [1,1,0,0,1,1,1,0,1] --> [[1,1],[0,0],[1,1,1],[0],[1]]\n```\n 3. We eliminate all *... | 8 | 0 | ['Python3'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Easiest Java Solution with 2 pointers | easiest-java-solution-with-2-pointers-by-lmjy | \nclass Solution {\n public int longestSubarray(int[] nums) {\n int prev = 0;\n int curr = 0;\n int max = 0;\n for(int i = 0; i < | pulkit269 | NORMAL | 2020-10-11T07:00:24.506847+00:00 | 2020-10-11T07:00:24.506897+00:00 | 754 | false | ```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int prev = 0;\n int curr = 0;\n int max = 0;\n for(int i = 0; i < nums.length; ++i){\n if(nums[i] == 1){\n curr++;\n if(curr + prev > max) max = curr + prev;\n }\n ... | 8 | 1 | ['Java'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Clean Python 3, O(N)/O(1) time/space | clean-python-3-ono1-timespace-by-lenchen-nv7y | Use two states to maintain consecutive 1\'s after meeting a 0\nnew for a new consecutive 1s.\nold for making that 0 to be deleted.\nThen just find the maximum i | lenchen1112 | NORMAL | 2020-06-27T16:01:46.043742+00:00 | 2021-02-09T07:53:30.862293+00:00 | 659 | false | Use two states to maintain consecutive 1\'s after meeting a 0\n`new` for a new consecutive 1s.\n`old` for making that 0 to be deleted.\nThen just find the maximum in `old`.\nTime: `O(N)`\nSpace: `O(1)`\n```\n```python\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n new, old, m = 0, 0, ... | 8 | 1 | [] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Best Solution for Arrays, DP 🚀 in C++, Python and Java || 100% working | best-solution-for-arrays-dp-in-c-python-u1tqn | Intuition💡 The problem asks for the longest subarray where at most one zero is removed. My first thought is to use the sliding window technique to keep track of | BladeRunner150 | NORMAL | 2025-01-08T07:15:47.843287+00:00 | 2025-01-08T07:15:47.843287+00:00 | 640 | false | # Intuition
💡 The problem asks for the longest subarray where at most one zero is removed. My first thought is to use the **sliding window technique** to keep track of valid subarrays.
# Approach
1. 🪟 Use two pointers (`l` and `r`) to represent a sliding window.
2. 🧮 Keep a count of zeros in the current win... | 7 | 0 | ['Array', 'Dynamic Programming', 'Python', 'C++', 'Java', 'Python3'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Optimal solution without sliding window | optimal-solution-without-sliding-window-5z4ph | Complexity\n- Time complexity:\nO(n) time\n\n- Space complexity:\nO(1) space\n\n# Code\n\n// O(n) time\n// O(1) space\nfunction longestSubarray(nums: number[]): | kazinov | NORMAL | 2023-05-24T08:12:38.175914+00:00 | 2023-05-24T08:12:38.175951+00:00 | 523 | false | # Complexity\n- Time complexity:\nO(n) time\n\n- Space complexity:\nO(1) space\n\n# Code\n```\n// O(n) time\n// O(1) space\nfunction longestSubarray(nums: number[]): number {\n let maxLength = 0;\n let count = 0;\n let onesBefore = 0;\n for(const num of nums) {\n if(num) {\n count++;\n ... | 7 | 0 | ['TypeScript'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | C++ Sliding Window (+ Cheat Sheet) | c-sliding-window-cheat-sheet-by-lzl12463-he1v | See my latest update in repo LeetCode\n## Solution 1.\n\nprev2 and prev are the indexes of the non-one values we\'ve seen most recently during scanning.\n\n\npr | lzl124631x | NORMAL | 2021-10-05T07:58:21.665441+00:00 | 2021-10-05T07:58:21.665469+00:00 | 3,247 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1.\n\n`prev2` and `prev` are the indexes of the non-one values we\'ve seen most recently during scanning.\n\n```\nprev2 prev i\n 0 1 1 1 0 1 1 1 0 \n```\n\nIf the array only contains 1,... | 7 | 0 | [] | 2 |
longest-subarray-of-1s-after-deleting-one-element | [Java] O(n) time, O(1) space with explanation. | java-on-time-o1-space-with-explanation-b-ogl9 | Maintain 2 variables a and c .c- number of continous ones till the current index.\na - number of continous ones with a single zero in between.\nWhenever a one i | hemanthsrinivas | NORMAL | 2020-06-28T08:18:49.700756+00:00 | 2020-07-01T16:33:50.141046+00:00 | 311 | false | Maintain 2 variables a and c .c- number of continous ones till the current index.\na - number of continous ones with a single zero in between.\nWhenever a one is encountered, a and c both are incremented.\nWhenever a zero is encountered, copy the value of c to a and make c = 0.\nEx : 1 0 0 1 1 0 1\t\t\nintially a = 0 ... | 7 | 1 | [] | 0 |
longest-subarray-of-1s-after-deleting-one-element | JavaScript + comments | DP | javascript-comments-dp-by-zhang1pr-g342 | This solution uses dynamic programming to keep track of non-deleted and deleted states.\n\nWe use an array of 2 for each position i for non-deleted state and de | zhang1pr | NORMAL | 2020-06-27T18:32:17.546614+00:00 | 2023-07-11T01:17:58.855669+00:00 | 1,039 | false | This solution uses dynamic programming to keep track of non-deleted and deleted states.\n\nWe use an array of 2 for each position `i` for non-deleted state and deleted state.\n`dp[i][0]` means the longest contiguous 1 to `nums[i]` if we haven\'t deleted one element.\n`dp[i][1]` means the longest contiguous 1 to `nums[i... | 7 | 1 | ['Dynamic Programming', 'JavaScript'] | 3 |
longest-subarray-of-1s-after-deleting-one-element | Simple Solution | 3ms | Two Pointer | Java | simple-solution-3ms-two-pointer-java-by-2ziok | \n# Code\njava []\nclass Solution {\n public int longestSubarray(int[] nums) {\n int zeroes = 0;\n int left = 0;\n int result = 0;\n | eshwaraprasad | NORMAL | 2024-09-24T11:46:25.544843+00:00 | 2024-09-24T11:46:25.544875+00:00 | 1,102 | false | \n# Code\n```java []\nclass Solution {\n public int longestSubarray(int[] nums) {\n int zeroes = 0;\n int left = 0;\n int result = 0;\n for(int right = 0; right < nums.length; right++) {\n if(nums[right] == 0) zeroes++;\n\n while(zeroes == 2) {\n int v... | 6 | 0 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Binary search on answers | binary-search-on-answers-by-algo_maniac-t2sq | Intuition\n Describe your first thoughts on how to solve this problem. \nWe are given an array of N length which contains only 1\'s and 0\'s. We can observe tha | algo_maniac | NORMAL | 2023-07-06T07:19:08.662632+00:00 | 2023-07-06T07:19:08.662671+00:00 | 234 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are given an array of N length which contains only 1\'s and 0\'s. We can observe that if we can form a subarray of length k(by deleting 1 or no zeros), then we can also form subarrays of length less than k.\nThis shows that we have a m... | 6 | 0 | ['Binary Search', 'C++'] | 2 |
longest-subarray-of-1s-after-deleting-one-element | C++ || SLIDING WINDOW || WITH EXPLANATION | c-sliding-window-with-explanation-by-neh-hn19 | Simple logic of sliding window there are two pointers left and right. We always include the right element and try to get maximum element from left. So while inc | neha0312 | NORMAL | 2023-07-05T03:34:29.618323+00:00 | 2023-07-05T03:34:29.618342+00:00 | 781 | false | Simple logic of sliding window there are two pointers left and right. We always include the right element and try to get maximum element from left. So while including we check if count of zeros in our current window is <=1 . if it is so the length of the window will be (right-left+1) but we will perform 1 deletion if o... | 6 | 0 | ['C', 'Sliding Window'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | [C++] Solution W/ Explanation | Sliding Window | Two Pointer | c-solution-w-explanation-sliding-window-2v953 | APPROACH :\n\n We need to find the longest subarray with all 1\'s after deleting any one zero.\n The question can be re-phrased as : Find the longest subarray w | Mythri_Kaulwar | NORMAL | 2022-02-14T16:09:58.370564+00:00 | 2022-02-14T16:10:14.415309+00:00 | 692 | false | **APPROACH :**\n\n* We need to find the longest subarray with all 1\'s after deleting any one zero.\n* The question can be re-phrased as : Find the longest subarray with **atmost 1** zero.\n* So we traverse the array with 2 pointers, at any point there\'s only atmost 1 zero in the window.\n* We count the number of zero... | 6 | 0 | ['C', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | [Java] Single pass solution, w/ diagram and explanation | java-single-pass-solution-w-diagram-and-c91hu | For every position of 0 in the array we need to find:\n length of the subarray consisting of only 1s, ending just before the current position.\n length of the s | SonicBoomer | NORMAL | 2021-02-23T20:49:27.706103+00:00 | 2021-02-23T20:58:29.397940+00:00 | 415 | false | For every position of `0` in the array we need to find:\n* length of the subarray consisting of only `1`s, ending just before the current position.\n* length of the subarray consisting of only `1`s, starting just after the current position.\n\nThe sum of these lengths is the length of the subarray of `1`s that will be ... | 6 | 0 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Python 3 Faster than 100% Explanation | python-3-faster-than-100-explanation-by-veq55 | \n```\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n l=len(nums)\n ar=[]\n\t\t\n c=0 # it will count 1\'s\n | anurag_tiwari | NORMAL | 2020-06-27T20:31:25.428595+00:00 | 2020-06-27T20:31:25.428628+00:00 | 1,094 | false | \n```\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n l=len(nums)\n ar=[]\n\t\t\n c=0 # it will count 1\'s\n su=sum(nums)\n\t\t# if all element are 1\n ... | 6 | 0 | ['Python', 'Python3'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | [Swift, C++, Python3] Simple solution with diagram and explanation 0ms 100% faster | swift-c-python3-simple-solution-with-dia-gjrm | Intuition\nCan we use Dynamic Programming to calculate all subarrays lengths? \nLike [1,1,1,1,1,0,1,1] = [1,2,3,4,5,0,1,2].\nBut how can we optimize this and no | evkobak | NORMAL | 2024-12-03T05:51:22.127808+00:00 | 2024-12-03T06:31:09.620716+00:00 | 264 | false | # Intuition\nCan we use Dynamic Programming to calculate all subarrays lengths? \nLike `[1,1,1,1,1,0,1,1]` = `[1,2,3,4,5,0,1,2]`.\nBut how can we optimize this and not check every subarray\'s number from the start before we find `0` and it ends? Can we check from backward? Sure :)\n\n# Approach\n 💡 Sliding window 🪟 Beginner Friendly 💯 | beats-9999-with-proof-solution-using-sli-n5ij | Proof:Approach
Variables:
left: This is the left pointer for the sliding window.
max_length: This will store the maximum length of the subarray of 1's found so | harsh9265 | NORMAL | 2024-10-18T05:22:30.125146+00:00 | 2024-12-20T19:43:21.784669+00:00 | 393 | false | # Proof:

# Approach
<!-- Describe your approach to solving the problem. -->
1) Variables:
**left**: This is the left pointer for the sliding window.
**max_length**: This will sto... | 5 | 0 | ['Array', 'Dynamic Programming', 'Sliding Window', 'Python', 'Python3'] | 2 |
longest-subarray-of-1s-after-deleting-one-element | This makes Your Life easy | this-makes-your-life-easy-by-anand_shukl-kj8g | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n$1):$ Initialization:\n\n=> n is the length of the input list nums.\n=> m | anand_shukla1312 | NORMAL | 2024-06-19T17:44:31.189193+00:00 | 2024-06-19T17:44:31.189217+00:00 | 269 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n$1):$ Initialization:\n\n=> n is the length of the input list nums.\n=> max_len keeps track of the maximum length of the subarray found so far.\n=> zero_count keeps track of the number of zeros in the current window.\n=> lef... | 5 | 0 | ['Array', 'Two Pointers', 'Sliding Window', 'Iterator', 'Python3'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | ✅ BEST C++ SOLUTION ☑️ | best-c-solution-by-2005115-vove | PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand | 2005115 | NORMAL | 2024-02-18T15:12:15.603338+00:00 | 2024-02-18T15:12:15.603371+00:00 | 180 | false | # **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/_pratay_nandy_/]()**\n\n# Approach\nTo approach this problem, we can utilize a sliding window technique with two pointers `i` and `j` to traverse the ... | 5 | 0 | ['Array', 'C', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | [C++] Recursion? I hardly know her. | c-recursion-i-hardly-know-her-by-jaintle-5jnc | \n\n# Code\n\nclass Solution {\npublic:\n int longest(vector<int>& nums, int index, int maxi, int curr, int flag){\n if(index>=nums.size()){\n | jaintle | NORMAL | 2023-07-05T09:23:35.747415+00:00 | 2023-07-05T09:23:35.747440+00:00 | 228 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int longest(vector<int>& nums, int index, int maxi, int curr, int flag){\n if(index>=nums.size()){\n return maxi;\n }\n int ans = 0;\n if(flag==1){\n if(nums[index]==1){\n ans = longest(nums,index+1,max(maxi... | 5 | 0 | ['Recursion', 'C++'] | 2 |
longest-subarray-of-1s-after-deleting-one-element | Simple iteration problem solved in O(n) time complexity | simple-iteration-problem-solved-in-on-ti-czoc | Intuition\nSimple iteration problem , can solove in O(n) time complexity \n\n\n# Approach\ncount the number of 1s together with no zero between among them.count | mairothiya | NORMAL | 2023-07-05T08:31:38.557082+00:00 | 2023-07-05T08:31:38.557109+00:00 | 23 | false | # Intuition\nSimple iteration problem , can solove in O(n) time complexity \n\n\n# Approach\ncount the number of 1s together with no zero between among them.count for every set of 1s, then check if we del the zero between them how many 1s we can get. for example...\nlet array be- 0 1 1 1 0 0 1 1 0 1 1 1 1 0\nthen we ge... | 5 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | 🏆Beats 99%🔥Java/C++🔥concise Solution + Explanation🔥 | beats-99javacconcise-solution-explanatio-zetw | Intuition\n\n\n Describe your first thoughts on how to solve this problem. \nThe main concept behind this question is to mantain a single 0 in your window.\n# A | Sanchit_Jain | NORMAL | 2023-07-05T07:20:38.193176+00:00 | 2023-07-05T07:30:24.924510+00:00 | 406 | false | Intuition\n\n\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe main concept behind this question is to mantain a single 0 in your window.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMain approach behind this solution is to start a valid window which only contain one ze... | 5 | 0 | ['Array', 'Sliding Window', 'C++', 'Java'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | C++ Solution using Two Pointers | c-solution-using-two-pointers-by-krishan-uqrq | 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 | KrishanBrar | NORMAL | 2023-07-05T05:56:44.182763+00:00 | 2023-07-05T05:56:44.182796+00:00 | 820 | 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++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | C# Solution for Longest Subarray of 1s after deleting one Element Problem | c-solution-for-longest-subarray-of-1s-af-k15a | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the solution is to use the sliding window technique to find the lo | Aman_Raj_Sinha | NORMAL | 2023-07-05T04:06:07.055970+00:00 | 2023-07-05T04:06:07.056001+00:00 | 507 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the solution is to use the sliding window technique to find the longest subarray containing only ones after deleting one element.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is... | 5 | 0 | ['C#'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | SIMPLE JAVA O(N) SOLUTION || FASTER THAN 99% || | simple-java-on-solution-faster-than-99-b-dyvu | 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 | deepak_kumar_m | NORMAL | 2023-07-05T03:38:59.948559+00:00 | 2023-07-05T03:42:08.274721+00:00 | 973 | 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)\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... | 5 | 0 | ['Two Pointers', 'Java'] | 4 |
longest-subarray-of-1s-after-deleting-one-element | Java Solution 5ms Sliding Window | java-solution-5ms-sliding-window-by-aadi-bc3q | \nclass Solution {\n public int longestSubarray(int[] nums) {\n int n=nums.length,o=0,z=0;\n for(int i=0;i<n;i++)\n { \n\t\t// Calcula | aadishjain__ | NORMAL | 2021-11-22T08:21:56.608215+00:00 | 2021-11-22T08:24:37.205264+00:00 | 126 | false | ```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int n=nums.length,o=0,z=0;\n for(int i=0;i<n;i++)\n { \n\t\t// Calculating One\n if(nums[i]==1)\n {\n o++;\n }\n\t\t\t//Calculating zero\n else\n {\n ... | 5 | 1 | [] | 0 |
longest-subarray-of-1s-after-deleting-one-element | easy solution using sliding window, O(n) time complexity | easy-solution-using-sliding-window-on-ti-2y93 | \n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n | ujjuengineer | NORMAL | 2024-09-28T06:10:41.718916+00:00 | 2024-09-28T06:10:41.718949+00:00 | 25 | false | \n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n // we can solve this problem just li... | 4 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Easy Solution | Java | better than 98% | easy-solution-java-better-than-98-by-chh-m6ye | Intuition\nCalculating no of zero\'s before 1 and after 1 \n\n# Approach\nMaths \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Cod | chhavigupta095 | NORMAL | 2024-02-05T18:28:56.655225+00:00 | 2024-02-05T18:28:56.655280+00:00 | 251 | false | # Intuition\nCalculating no of zero\'s before 1 and after 1 \n\n# Approach\nMaths \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int back =0, count=0,max =0;\n for(int i : nums){\n if(i==1)... | 4 | 0 | ['Math', 'Java'] | 3 |
longest-subarray-of-1s-after-deleting-one-element | ✅Beats 98% | Easy to Understand | C++ | Sliding Window Algorithm | | beats-98-easy-to-understand-c-sliding-wi-nqu5 | \n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe approach employs a sliding window technique to find the longest subarray with | sri_mayur | NORMAL | 2024-01-19T00:11:39.774215+00:00 | 2024-01-19T00:11:39.774232+00:00 | 7 | false | \n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach employs a sliding window technique to find the longest subarray with at most one zer... | 4 | 0 | ['Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | INTUITIVE || Easy to understand || No sliding window || No dp | intuitive-easy-to-understand-no-sliding-m2vum | Intuition\n Describe your first thoughts on how to solve this problem. \nIf we somehow manage to know the count of 1\'s before and after a particular occurence | nexgphoenix | NORMAL | 2023-07-05T19:35:19.867775+00:00 | 2023-07-05T19:35:19.867801+00:00 | 279 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we somehow manage to know the count of 1\'s **before** and **after** a particular occurence of 0 and the number of 0\'s in the subarray we are considering **must be one** because we are allowed to delete only one element. \n\n# Approac... | 4 | 0 | ['C++'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | VERY EASY||100% FAST||SLIDING WINDOW|| C++ | very-easy100-fastsliding-window-c-by-vai-ou90 | Very simple use of sliding window\n1. initailize i and j=0 \n2. maintain a counter and max counter\n3. set flag when counter with zero and store position after | VaidyaPS | NORMAL | 2023-07-05T10:18:34.262649+00:00 | 2023-07-05T10:24:22.777421+00:00 | 20 | false | Very simple use of sliding window\n1. initailize i and j=0 \n2. maintain a counter and max counter\n3. set flag when counter with zero and store position after zero.\n4. if we counter again 0 when our flag is set then set i and j both to stored position and reset counter and flag.\n5. manage to keep track of maxium cou... | 4 | 0 | ['C', 'Sliding Window'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | JAVA SIMPLE APPROUCH🔥🔥Easy to understand💯💯 | java-simple-approucheasy-to-understand-b-qwpl | Intuition\nInitialize three variables: cur (current count of consecutive 1s), prev (previous count of consecutive 1s), and ans (maximum length of the subarray f | Aisu-08 | NORMAL | 2023-07-05T09:33:11.465422+00:00 | 2023-07-05T09:33:11.465446+00:00 | 350 | false | # Intuition\nInitialize three variables: cur (current count of consecutive 1s), prev (previous count of consecutive 1s), and ans (maximum length of the subarray found so far).\n\nIterate through each element i in the nums array.\n\nIf the current element i is equal to 1, increment the cur variable to count consecutive ... | 4 | 0 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Simple 2-Step Java Solution | simple-2-step-java-solution-by-iamc0der-32sf | Intuition\nAs we need to allow only one zero in the subarray, the simplest way to track zeroes is to memorise the last zero position in the given array.\n\n# Ap | iamc0der | NORMAL | 2023-07-05T08:56:12.587008+00:00 | 2023-07-05T08:56:12.587040+00:00 | 299 | false | # Intuition\nAs we need to allow **only one zero in the subarray**, the simplest way to track zeroes is to memorise the last zero position in the given array.\n\n# Approach\nTo remember the last zero position we will use the variable `lastZeroIndex` with an initial value of `-1`.\nAdditionally, we will use 2 pointers t... | 4 | 0 | ['Java'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Simple and Fast C++ Code || Beats 99% in speed and 99% in memory | simple-and-fast-c-code-beats-99-in-speed-sgl7 | Intuition\nMaintain the count of 1\'s Before Zero and after Zero and the max sum of Before and after is our answer.\n\n# Approach\nMaintain the count of 1\'s Be | NNikhil_Nik | NORMAL | 2023-07-05T08:14:50.710121+00:00 | 2023-07-05T08:20:02.845711+00:00 | 496 | false | # Intuition\nMaintain the count of 1\'s Before Zero and after Zero and the max sum of Before and after is our answer.\n\n# Approach\nMaintain the count of 1\'s Before Zero and after Zero.\n->0 1 1 1 0 1 1 0 1\nIn the above example\nFirst element is zero,Make fz=1 and we will only increase After counter.\n->At Index 4 s... | 4 | 0 | ['Two Pointers', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Concise Intuitive Approach with Counters | concise-intuitive-approach-with-counters-xawg | Complexity\n- Time complexity: O(n).\n\n- Space complexity: O(1).\n\n# Code\n\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n | MikPosp | NORMAL | 2023-07-05T07:34:57.782974+00:00 | 2023-07-05T07:34:57.783006+00:00 | 273 | false | # Complexity\n- Time complexity: $$O(n)$$.\n\n- Space complexity: $$O(1)$$.\n\n# Code\n```\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n maxLen = 0\n prevOnesCntr = zero = curOnesCntr = 0\n for num in nums:\n if num == 1:\n curOnesCntr += 1\n ... | 4 | 0 | ['Array', 'Counting', 'Python3'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Longest Subarray of 1's After Deleting One Element || sliding window || O(N) | longest-subarray-of-1s-after-deleting-on-1a4n | \n# Approach\nwe can atlmost remove one 0 from the given array. selecting that 0 is the main task here. we will be counting the number of number of 0\'s in any | AD23315 | NORMAL | 2023-07-05T05:53:58.992912+00:00 | 2023-07-05T05:53:58.992946+00:00 | 350 | false | \n# Approach\nwe can atlmost remove one 0 from the given array. selecting that 0 is the main task here. we will be counting the number of number of 0\'s in any subarray. till the count of 0\'s is in our range we know we can remove that much 0\'s, but if the count goes out of bound the given subarray cannot be continued... | 4 | 0 | ['Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | 🏆 Image Explanation | C++ | Sliding Window | Optimised | Clean Code | Template | image-explanation-c-sliding-window-optim-vmp1 | Intuition\n Describe your first thoughts on how to solve this problem. \nWhen I read this problem statement, it had words like longest, subarray, exactly k. And | patelshubh694 | NORMAL | 2023-07-05T04:25:16.924434+00:00 | 2023-07-05T04:25:16.924468+00:00 | 430 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen I read this problem statement, it had words like longest, subarray, exactly k. And I know that, if problem statement contains -> \n\n1) Longest, Shortest\n2) subarray, substring\n3) Exactly, at most k\n4) Required to solve in O(n) ti... | 4 | 0 | ['Array', 'Dynamic Programming', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Easy C++/Python using 2 pointers||Beats 95.29% | easy-cpython-using-2-pointersbeats-9529-jgkv6 | Intuition\n Describe your first thoughts on how to solve this problem. \n\nThe code finds the length of the longest subarray in a given array, allowing at most | anwendeng | NORMAL | 2023-07-05T00:06:16.436938+00:00 | 2023-07-05T01:44:05.627194+00:00 | 921 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe code finds the length of the longest subarray in a given array, allowing at most one zero. It uses two pointers and a count of zeros to iterate through the array and update the answer by finding the maximum subarray length.\n# Appro... | 4 | 0 | ['Two Pointers', 'C++'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | ✅Easy sliding window implementation | time: O(n), space: O(1) | easy-sliding-window-implementation-time-iq5ep | \n# Code\n\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i=0,j=0,count=0,mx=0;\n bool flag=true;\n while(j | underground_coder | NORMAL | 2023-01-05T17:00:38.751131+00:00 | 2023-01-05T17:00:38.751184+00:00 | 1,760 | false | \n# Code\n```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i=0,j=0,count=0,mx=0;\n bool flag=true;\n while(j<nums.size()){\n if(nums[j] == 0){\n flag = false;\n count++;\n }\n \n if(count... | 4 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | C++ | Explanation | Sliding Window | Easy | c-explanation-sliding-window-easy-by-gjh-qt5h | Simple Solution using Sliding Window\nWe maintain the count of zero and one\nWhile count of zero is 1 we will keep the track of window size in mx\nIf count of z | gjha133 | NORMAL | 2022-08-15T00:51:03.213406+00:00 | 2022-08-15T00:51:03.213449+00:00 | 687 | false | Simple Solution using Sliding Window\nWe maintain the ```count of zero and one```\nWhile ```count of zero is 1``` we will keep the track of **window size** in ```mx```\nIf ```count of zero is 2```, we will **decrease** the window from left until ```count of zero is 1```.\n\nDo Upvote if it helped!\n\n```\nclass Solutio... | 4 | 0 | ['C', 'Sliding Window'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Simple || Intutive || Java Soln with explanation | simple-intutive-java-soln-with-explanati-slfh | Well as y\'all know that this is\'nt your normal sliding window question, because the size here could vary according the requirement of the question for eg:- [1 | kageyama09 | NORMAL | 2022-01-16T09:38:59.150053+00:00 | 2022-01-16T09:38:59.150088+00:00 | 132 | false | Well as y\'all know that this is\'nt your normal sliding window question, because the size here could vary according the requirement of the question for eg:- [1,1,1,0,1] this could be your possible answer and [1,0,1] too could be your possible answer. The only catch is that we have consider the maximum subarray in our ... | 4 | 0 | ['Array', 'Sliding Window'] | 2 |
longest-subarray-of-1s-after-deleting-one-element | C++ Sliding Window with explanation | c-sliding-window-with-explanation-by-sau-mj1h | Logic : At any point in time our current window must only contains 1\'s and at most one 0 . So if we encounter another zero in our path we must slide our left | saumitrakumar | NORMAL | 2021-08-10T11:39:48.013141+00:00 | 2021-08-10T11:39:48.013186+00:00 | 187 | false | Logic : At any point in time our current window must only contains 1\'s and at most one 0 . So if we encounter another zero in our path we must slide our left end of the window to `lastZeroIndex + 1` to remove a zero from our current window and accomodate the upcoming zero.\n ```\nint longestSubarray(vector<int>& nums... | 4 | 0 | [] | 0 |
longest-subarray-of-1s-after-deleting-one-element | C++ | Time Complexity - O(n) | Space Complexity - O(1) | c-time-complexity-on-space-complexity-o1-h9fa | \nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int ones=0, zero=0;\n int n=nums.size(), i=0, j=0, res=0;\n \n | manas02 | NORMAL | 2021-07-12T16:36:49.846490+00:00 | 2021-07-12T16:36:49.846530+00:00 | 268 | false | ```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int ones=0, zero=0;\n int n=nums.size(), i=0, j=0, res=0;\n \n while(j<n){\n if(nums[j]==0) zero++;\n else ones++;\n \n if(zero<2) res=max(res, ones);\n else{... | 4 | 0 | ['Sliding Window'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Java, sliding window, linear, O(n), explained | java-sliding-window-linear-on-explained-3kckx | If problem statement flipped than it can be equvivalent of finding longest array of all 1s if we allow to replace one 0 to 1. At the end we just do answer - 1 l | gthor10 | NORMAL | 2020-07-05T23:19:55.736430+00:00 | 2020-07-05T23:19:55.736464+00:00 | 458 | false | If problem statement flipped than it can be equvivalent of finding longest array of all 1s if we allow to replace one 0 to 1. At the end we just do answer - 1 like the 0 is deleted.\nSuch problem solved by sliding window approach in linear time. We have left and right pointers, advance right by 1 and check if number of... | 4 | 0 | ['Sliding Window', 'Java'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Simple DP solution, Easy to Understand | simple-dp-solution-easy-to-understand-by-hyau | Runtime: 3 ms, faster than 50.00% of Java online submissions for Longest Subarray of 1\'s After Deleting One Element.\nMemory Usage: 47.2 MB, less than 100.00% | aroraharsh010 | NORMAL | 2020-06-28T08:42:54.751554+00:00 | 2020-06-28T08:42:54.751585+00:00 | 369 | false | Runtime: 3 ms, faster than 50.00% of Java online submissions for Longest Subarray of 1\'s After Deleting One Element.\nMemory Usage: 47.2 MB, less than 100.00% of Java online submissions for Longest Subarray of 1\'s After Deleting One Element.\n\n```\nint[] dp=new int[nums.length];\n if(nums.length==0)return 0;\... | 4 | 2 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Very concise and intuitive solution | very-concise-and-intuitive-solution-by-z-svw2 | Intuition\nFirst, check if there are any zeros in the array. If not, it doens\'t make sence to iterate over the array.\n\n\nIterate until the right pointer is e | zhav1k | NORMAL | 2024-07-24T14:20:09.380521+00:00 | 2024-07-24T14:20:09.380546+00:00 | 155 | false | # Intuition\nFirst, check if there are any zeros in the array. If not, it doens\'t make sence to iterate over the array.\n\n\nIterate until the right pointer is equal to the size of the array. \n\nIf we didn\'t encounter zero, update the max length with the current max length and a new one (R-L)\nIf we encounter zero, ... | 3 | 0 | ['Python3'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Easy Java Solution for Beginners|| O(N) Solution....... | easy-java-solution-for-beginners-on-solu-d9jp | 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 | Bugs_Bunny15 | NORMAL | 2024-07-12T10:08:32.387113+00:00 | 2024-07-12T10:08:32.387134+00:00 | 120 | 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)\n\n- Space complexity:O(1)\n\n# Code\n```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int i=0;int j... | 3 | 0 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Easiest Optimal Solutions for Longest Subarray After Deleting One Element | easiest-optimal-solutions-for-longest-su-w6fe | Approach 1 Complexity\n- Time complexity:O(N)\n\n- Space complexity: O(1)\n\n# Approach 1\n\nclass Solution(object):\n def longestSubarray(self, nums):\n | Sachinonly__ | NORMAL | 2024-06-28T15:30:47.001687+00:00 | 2024-06-28T15:30:47.001727+00:00 | 299 | false | # Approach 1 Complexity\n- Time complexity:O(N)\n\n- Space complexity: O(1)\n\n# Approach 1\n```\nclass Solution(object):\n def longestSubarray(self, nums):\n ans = 0\n deleted = False\n prev = 0\n count = 0\n for x in nums:\n if x == 0:\n if ans < count:\... | 3 | 0 | ['Array', 'Dynamic Programming', 'Sliding Window', 'Python'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Greedy linear solution without additional memory | greedy-linear-solution-without-additiona-2ulf | \n# Approach\n Describe your approach to solving the problem. \nIf two sequences of ones with lengths $k_1$ and $k_2$ are separated by a single zero, i.e., $\un | drgavrikov | NORMAL | 2024-04-17T09:06:06.183122+00:00 | 2024-06-04T20:39:14.507556+00:00 | 70 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf two sequences of ones with lengths $k_1$ and $k_2$ are separated by a single zero, i.e., $\\underbrace{11..1}_{k_1}0\\underbrace{11..1}_{k_2}$, then by deleting $0$ with $1$, we can obtain a sequence of length $k_1 + k_2$.\n\nTo account for these... | 3 | 0 | ['Greedy', 'C++', 'Kotlin'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Detailed Explanation - Beats 96% Runtime, 85% Space | detailed-explanation-beats-96-runtime-85-s3bb | Intuition\nMy first thought was that we\'d need to track which zero we "dropped" within the sliding window. Then of course we\'d need the starting and end point | mckamike | NORMAL | 2024-02-09T21:47:24.096194+00:00 | 2024-03-20T23:50:49.115807+00:00 | 186 | false | # Intuition\nMy first thought was that we\'d need to track which zero we "dropped" within the sliding window. Then of course we\'d need the starting and end pointers of the window.\n\n# Approach\nIts fairly simple. \n1. We expand the window rightward (so, increment the `end` pointer)\n2. When `end` runs into the first ... | 3 | 0 | ['Swift'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | JavaScript Solution | javascript-solution-by-sahil3554-0iu7 | \n\n# Code\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n let leftPtr = 0;\n let result = 0;\n l | sahil3554 | NORMAL | 2023-11-29T03:23:27.631699+00:00 | 2023-11-29T03:23:27.631726+00:00 | 326 | false | \n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n let leftPtr = 0;\n let result = 0;\n let zeroCount = 0;\n for(let rightPtr=0;rightPtr<nums.length;rightPtr++){\n \n if(nums[rightPtr]===0){\n zeroCount++\n }\n\... | 3 | 0 | ['JavaScript'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Simple Sliding Window | simple-sliding-window-by-pndev0404-ij4m | Intuition\nMaximum substring with atmost K deletions\n\n# Approach\nIncrease the sliding window until we have only one zero in it, once encountered another zero | pndev0404 | NORMAL | 2023-10-14T18:12:26.833483+00:00 | 2023-10-14T18:12:26.833502+00:00 | 75 | false | # Intuition\nMaximum substring with atmost K deletions\n\n# Approach\nIncrease the sliding window until we have only one zero in it, once encountered another zero, shrink the window until previous zero goes out of window scope and continue.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\... | 3 | 0 | ['Sliding Window', 'Kotlin'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Longest Subarray of 1's After Deleting One Element C++ Solution | longest-subarray-of-1s-after-deleting-on-xmyj | 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 | rissabh361 | NORMAL | 2023-09-12T17:47:23.782154+00:00 | 2023-09-12T17:47:23.782188+00:00 | 119 | 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 | ['Array', 'Dynamic Programming', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Python short and clean. Functional programming. | python-short-and-clean-functional-progra-cndj | Approach\n1. For every element x in nums, calculate the length of streaks of 1s upto x excluding itself.\n\n2. Select the streaks corresponding to x == 0, lets | darshan-as | NORMAL | 2023-07-05T19:41:20.746323+00:00 | 2023-07-05T20:09:11.978539+00:00 | 856 | false | # Approach\n1. For every element `x` in `nums`, calculate the length of streaks of `1s` upto `x` excluding itself.\n\n2. Select the streaks corresponding to `x == 0`, lets call it `streaks_at_0`. This acts as deleting the corresponding `x` and selecting the streaks of `1s` to the left of it.\n\n3. The longest possible ... | 3 | 0 | ['Array', 'Dynamic Programming', 'Sliding Window', 'Python', 'Python3'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Ez Pz | Singe Loop | Zero Logic | ez-pz-singe-loop-zero-logic-by-lourdessa-1r8m | \n\n# Code\n\nclass Solution {\n public int longestSubarray(int[] nums) {\n int prev = 0, cur = 0, max = 0;\n\n for(int num : nums) {\n | LourdesSanthosh | NORMAL | 2023-07-05T16:45:24.710936+00:00 | 2023-07-05T16:45:24.710970+00:00 | 178 | false | \n\n# Code\n```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int prev = 0, cur = 0, max = 0;\n\n for(int num : nums) {\n if(num == 1) cur++;\n else {\n max = (max > prev+cur) ? max : prev+cur;\n prev = cur;\n cur = 0;\... | 3 | 0 | ['Brainteaser', 'Sliding Window', 'Prefix Sum', 'Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Easy Sliding Window Approach || C++ | easy-sliding-window-approach-c-by-rahul2-27g4 | Intuition\nLooks similar to sliding window pattern.\n\n# Approach\nStart with a sliding window. Keep a zero-count to track the number of zeroes in the current w | rahul2001dogra | NORMAL | 2023-07-05T14:09:08.742563+00:00 | 2023-07-05T14:09:08.742593+00:00 | 112 | false | # Intuition\nLooks similar to sliding window pattern.\n\n# Approach\nStart with a sliding window. Keep a zero-count to track the number of zeroes in the current window.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& ... | 3 | 0 | ['Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | EASY AND BEST C++ SOLUTION WITH NO EXTRA SPACE AND O(N)TIME COMPLEXITY | easy-and-best-c-solution-with-no-extra-s-a0z1 | Intuition\n Describe your first thoughts on how to solve this problem. \n#BEST SOLUTION WITH NO EXTRA SPACE AND O(N)TIME COMPLEXITY\n\n# Approach\n Describe you | its_arunra0 | NORMAL | 2023-07-05T11:04:22.187534+00:00 | 2023-07-05T11:04:22.187554+00:00 | 930 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n#BEST SOLUTION WITH NO EXTRA SPACE AND O(N)TIME COMPLEXITY\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. FIRST CHECK IF ALL ELEMENTS ARE 1 OR NOT BY CHECK POINTER;\n2. USE COUNT2 POINTER TO COUNT NO. OF 1 EVER... | 3 | 0 | ['Two Pointers', 'C++'] | 3 |
longest-subarray-of-1s-after-deleting-one-element | ✅C++ | ✅Efficient & Easy solution | c-efficient-easy-solution-by-yash2arma-xm88 | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution \n{\npublic:\n int longestSubarray(vector<int>& nums) \n {\n | Yash2arma | NORMAL | 2023-07-05T10:32:59.972806+00:00 | 2023-07-05T10:40:57.554531+00:00 | 240 | false | # Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution \n{\npublic:\n int longestSubarray(vector<int>& nums) \n {\n int lastzero=-1, i=0, j, ans=0, n=nums.size();\n for(j=0; j<n; j++)\n {\n if(nums[j]==0)\n {\n a... | 3 | 0 | ['Array', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Easy cpp solution with detailed step wise explanation||Sliding Window Approach | easy-cpp-solution-with-detailed-step-wis-gho9 | Intuition\nFirst thought was to relate somehow with zeroes,as it requires maximum numbers of 1.\n\n# Approach\n1. Initialize variables: Initialize n as the size | Harsh_Balwani | NORMAL | 2023-07-05T10:28:58.422071+00:00 | 2023-07-05T10:28:58.422088+00:00 | 160 | false | # Intuition\nFirst thought was to relate somehow with zeroes,as it requires maximum numbers of 1.\n\n# Approach\n1. Initialize variables: Initialize `n` as the size of the `nums` vector, `start` as 0 (indicating the start index of the current subarray), `longwind` as 0 (representing the length of the longest subarray w... | 3 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | ✅ O(n) solution | 86 % faster 🚀 | Easy Understanding with Images 🏙️ | on-solution-86-faster-easy-understanding-cnlx | Intuition\n Describe your first thoughts on how to solve this problem. \n- If we want to remove one element, most probably a zero from the array then we need to | codingWith_aman | NORMAL | 2023-07-05T07:02:30.847136+00:00 | 2023-07-05T07:02:30.847169+00:00 | 139 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- If we want to remove one element, most probably a zero from the array then we need to count the number of 1\'s that is place around every zero.\n- Simply find the count of 1\'s on left and right side of a zero and return the max value t... | 3 | 0 | ['Array', 'Prefix Sum', 'Java'] | 1 |
longest-subarray-of-1s-after-deleting-one-element | Simple Memoization approach | simple-memoization-approach-by-akashtoma-n8zg | Intuition\nTry all possiblilty and add memoization.\n\n# Approach\n Since \n Only in the case where all elements are one we will have to delete one (resul | akashtomar19 | NORMAL | 2023-07-05T05:53:44.726247+00:00 | 2023-07-07T16:50:39.119418+00:00 | 2,038 | false | # Intuition\nTry all possiblilty and add memoization.\n\n# Approach\n Since \n Only in the case where all elements are one we will have to delete one (result will be totalSum - 1)\n Otherwise we can always delete zero and in case of deletion we can have two possibilites\n 1) Affect our result that is might ... | 3 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 2 |
longest-subarray-of-1s-after-deleting-one-element | ✅✅C++ || Easy Solution || Sliding Window | c-easy-solution-sliding-window-by-raz3r-dzn2 | 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 | raz3r | NORMAL | 2023-07-05T05:44:58.291394+00:00 | 2023-07-05T05:44:58.291413+00:00 | 1,295 | 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 | ['Array', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Optimised solution using sliding windows and single pass | optimised-solution-using-sliding-windows-bbt5 | Approach\nTo solve this problem, we can use a sliding window approach. We\'ll maintain two pointers, left and right, that define the current subarray we\'re con | priyanshu11_ | NORMAL | 2023-07-05T05:37:14.680080+00:00 | 2023-07-05T05:37:14.680119+00:00 | 254 | false | # Approach\nTo solve this problem, we can use a sliding window approach. We\'ll maintain two pointers, left and right, that define the current subarray we\'re considering. We\'ll initialize both pointers to the start of the array.\n\nThe idea is to iterate through the array and expand the window by moving the right poi... | 3 | 0 | ['Array', 'Dynamic Programming', 'Sliding Window', 'C++', 'Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Simple C++ solution | simple-c-solution-by-samarpan27-8ssn | Intuition\n Describe your first thoughts on how to solve this problem. \nBased on counting number of 1 and 2 in nums\n# Approach\n Describe your approach to sol | Samarpan27 | NORMAL | 2023-07-05T05:07:22.490917+00:00 | 2023-07-05T05:08:07.787057+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBased on counting number of 1 and 2 in nums\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWhile traversing nums we keep track of number of 1 and 2. If nums[i] is 1 we simply increment n_one by 1 and calculate ans b... | 3 | 0 | ['Two Pointers', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | SUPER EASY SOLUTION | super-easy-solution-by-himanshu__mehra-cg01 | Code\n\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i=0;\n int j=0;\n int n=nums.size();\n int c0= | himanshu__mehra__ | NORMAL | 2023-07-05T04:51:24.466880+00:00 | 2023-07-05T04:51:24.466911+00:00 | 283 | false | # Code\n```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i=0;\n int j=0;\n int n=nums.size();\n int c0=0;\n int mx=0;\n while(j<n){\n if(nums[j]==0){\n c0++;\n }\n while(i<n&&c0==2){\n if(nums[i]=... | 3 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | 🔥💯Best Explanation [C++,JAVA]💯|| 🌟NO DP || Sliding Window✅ | best-explanation-cjava-no-dp-sliding-win-5y6z | Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Approach\n## 1. Initialize variables:\n- n stores the size of the in | aDish_21 | NORMAL | 2023-07-05T02:55:53.193127+00:00 | 2023-07-05T03:34:47.771427+00:00 | 236 | false | ### Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Approach\n## 1. Initialize variables:\n- n stores the size of the input vector nums.\n- i and j are indices used for iterating through the vector.\n- count_before_0 and count_after_0 are counters to keep track of the lengths... | 3 | 0 | ['Array', 'Sliding Window', 'C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Sliding Window - MAX 1 zero inside. [C++/Python] | sliding-window-max-1-zero-inside-cpython-g91y | \n\n# Code\n\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i = 0, j = 0, ans = 0, cnt = 1, n = nums.size();\n whi | tryingall | NORMAL | 2023-07-05T02:48:28.441114+00:00 | 2023-07-05T02:48:28.441138+00:00 | 618 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i = 0, j = 0, ans = 0, cnt = 1, n = nums.size();\n while(j < n)\n {\n if(nums[j] == 0) {\n --cnt;\n }\n while(cnt < 0)\n {\n if(nu... | 3 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | [ C++ ] [ Left and Right Counting ] | c-left-and-right-counting-by-sosuke23-z353 | Code\n\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int n=(int)nums.size();\n \n if(n==1){\n retur | Sosuke23 | NORMAL | 2023-07-05T02:41:02.975119+00:00 | 2023-07-05T02:41:02.975148+00:00 | 956 | false | # Code\n```\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int n=(int)nums.size();\n \n if(n==1){\n return 0;\n }\n if(count(nums.begin(),nums.end(),0)==0){\n return n-1;\n }\n \n int cnt=0;\n vector<int> to... | 3 | 0 | ['C++'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Java Easy Solution Sliding Window | java-easy-solution-sliding-window-by-sai-k89f | #upvote if you like the solution\n\n\n\nclass Solution {\n public int longestSubarray(int[] nums) {\n int ans = 0;\n int z = 0, si = 0 , cur | Saitama_2727 | NORMAL | 2023-07-05T02:24:14.482900+00:00 | 2023-07-05T02:24:14.482923+00:00 | 297 | false | # #upvote *if you like the solution*\n\n\n```\nclass Solution {\n public int longestSubarray(int[] nums) {\n int ans = 0;\n int z = 0, si = 0 , cur = 0, ei = nums.length-1;\n while(cu... | 3 | 0 | ['Java'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Python3 Solution | python3-solution-by-motaharozzaman1996-clm5 | \n\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n n=len(nums)\n best=0\n left=0\n right=0\n curr= | Motaharozzaman1996 | NORMAL | 2023-07-05T02:22:04.591643+00:00 | 2023-07-05T02:22:04.591674+00:00 | 292 | false | \n```\nclass Solution:\n def longestSubarray(self, nums: List[int]) -> int:\n n=len(nums)\n best=0\n left=0\n right=0\n curr=0\n while right<n:\n if nums[right]==0:\n curr+=1\n while curr>1:\n if nums[left]==0:\n ... | 3 | 0 | ['Python', 'Python3'] | 0 |
longest-subarray-of-1s-after-deleting-one-element | Sliding Window , C++ Beats 100% ✅✅ | sliding-window-c-beats-100-by-deepak_591-a7di | if it Helps You. Please Upvote Me.....\uD83E\uDDE1\uD83E\uDD0D\uD83D\uDC9A\n# Approach\n Describe your approach to solving the problem. \nUsing Sliding Window a | Deepak_5910 | NORMAL | 2023-07-05T01:36:11.305459+00:00 | 2023-07-05T01:36:11.305481+00:00 | 470 | false | # if it Helps You. Please Upvote Me.....\uD83E\uDDE1\uD83E\uDD0D\uD83D\uDC9A\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Using Sliding Window approach, Find the largest subarray in which zero occurs exactly once.**\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, ... | 3 | 0 | ['Sliding Window', 'C++'] | 1 |
minimum-moves-to-spread-stones-over-grid | ✅Recursion✅ || Brute Force || C++ || Java | recursion-brute-force-c-java-by-anishkrs-h9ii | Intuition \nSince the constraints are very less we can apply recursion here.\n# Approach\nEach time we encounter a cell with grid[i][j] == 0 then we can take 1 | AnishKrSingh | NORMAL | 2023-09-10T04:01:27.917447+00:00 | 2024-10-12T09:00:46.803259+00:00 | 11,046 | false | # Intuition \n**``` Since the constraints are very less we can apply recursion here.```**\n# Approach\n**```Each time we encounter a cell with grid[i][j] == 0 then we can take 1 from any of the other 8 cells which have a value > 1```**\n\n# Complexity\n**- Time complexity:**\n**```The maximum depth of recursion is O(n^... | 91 | 0 | ['Backtracking', 'Recursion', 'C++', 'Java'] | 17 |
minimum-moves-to-spread-stones-over-grid | 🔥✅ Java BFS Easy Solution 🔥✅ | java-bfs-easy-solution-by-vishesht27-sl6b | Intuition\nGiven the setup of the problem, it is reminiscent of sliding tile puzzles where you aim to get from one configuration to another using a series of sl | vishesht27 | NORMAL | 2023-09-10T04:04:03.740354+00:00 | 2023-09-10T04:05:58.121140+00:00 | 6,144 | false | # Intuition\nGiven the setup of the problem, it is reminiscent of sliding tile puzzles where you aim to get from one configuration to another using a series of slides. In this case, you\'re trying to shift the stones around to get from one grid configuration to the target configuration. Naturally, this leads to thinkin... | 60 | 1 | ['Array', 'Hash Table', 'Breadth-First Search', 'Queue', 'Matrix', 'Hash Function', 'Java'] | 13 |
minimum-moves-to-spread-stones-over-grid | Python: Hungarian assignment. 10 Lines. O(n^3) beats 100% | python-hungarian-assignment-10-lines-on3-yarl | Intuition\nThe problem is a standard Hungarian algorithm\n\nIterate over all elements in the matrix and check where you have 0 and where you have values > 1.\n\ | salvadordali | NORMAL | 2023-09-10T04:12:03.669013+00:00 | 2023-09-10T04:14:44.771620+00:00 | 3,621 | false | # Intuition\nThe problem is a standard [Hungarian algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm)\n\nIterate over all elements in the matrix and check where you have 0 and where you have values > 1.\n\nValues above 1 will be values from which you are moving, values with 0, where are you moving.\n\nThen bu... | 28 | 1 | ['Python3'] | 8 |
minimum-moves-to-spread-stones-over-grid | Python 3 || 6 lines, permutation, w/ explanation || T/S: 65% / 71% | python-3-6-lines-permutation-w-explanati-ma40 | Here\'s the plan:\n1. We compile the coordinates (i, j) of (a) zeros in zero and (b) spare stones in spare.\n\n1. We construct a set of permutations of spare a | Spaulding_ | NORMAL | 2023-09-10T19:03:05.518610+00:00 | 2024-06-18T00:52:29.482866+00:00 | 1,823 | false | Here\'s the plan:\n1. We compile the coordinates (i, j) of (a) zeros in `zero` and (b) *spare* stones in `spare`.\n\n1. We construct a set of permutations of `spare` and match each permutation with `zero`.\n1. We compute the sum of moves for each pairing and return the minimum.\n\n```\nclass Solution:\n def minimum... | 24 | 0 | ['Python3'] | 5 |
minimum-moves-to-spread-stones-over-grid | Java || DFS + Backtrack || Easy to Undertand | java-dfs-backtrack-easy-to-undertand-by-r2xlj | Idea\n\nLet\'s call empty cells consumers. Suppliers for rich cells.\n\n> Please \u2B06\uFE0F upvote if you like my diagrams :)\n\nFor each consumer, DFS on ea | cooper-- | NORMAL | 2023-09-10T04:01:49.706836+00:00 | 2023-09-10T04:17:33.403941+00:00 | 1,306 | false | ### Idea\n\nLet\'s call empty cells `consumers`. `Suppliers` for rich cells.\n\n> Please \u2B06\uFE0F upvote if you like my diagrams :)\n\nFor each `consumer`, DFS on each available `supplier`. Use `flag` to ... | 20 | 0 | ['Backtracking', 'Depth-First Search', 'Java'] | 3 |
minimum-moves-to-spread-stones-over-grid | Video Solution 🔥(C++,JAVA,PYTHON) || Brute Force✅ || Recursion 🔥 || Back Tracking ✅ | video-solution-cjavapython-brute-force-r-0gq3 | Intuition\n Describe your first thoughts on how to solve this problem. \nIf you observe the Constraints they are very minimum 33=9. So we can solve using Brute | ayushnemmaniwar12 | NORMAL | 2023-09-10T04:48:33.387722+00:00 | 2023-09-10T04:53:56.982106+00:00 | 3,396 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf you observe the Constraints they are very minimum 3*3=9. So we can solve using Brute Force methods\n\n# ***Detailed and easy Video Solution***\nhttps://youtu.be/soC2B658iFY\n\n# Summary\n<!-- Describe your approach to solving the probl... | 18 | 1 | ['Backtracking', 'Recursion', 'C++', 'Java', 'Python3'] | 2 |
minimum-moves-to-spread-stones-over-grid | 🔥Python two different methods: DFS & BFS🔥 | python-two-different-methods-dfs-bfs-by-c183e | \n\n# DFS Code \u2705\nThe state of DFS is the current grid, and one branch represents moving 1 stone from a cell with more than 1 stones to an empty cell. Opti | Michael-Yang | NORMAL | 2023-09-17T23:05:14.409742+00:00 | 2023-09-17T23:18:18.901923+00:00 | 1,881 | false | \n\n# DFS Code \u2705\nThe state of DFS is the current grid, and one branch represents moving 1 stone from a cell with more than 1 stones to an empty cell. Optimized with memorization.\n```\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n memo = {}\n def compute_string(g):\n ... | 15 | 0 | ['Python3'] | 0 |
minimum-moves-to-spread-stones-over-grid | Why Greedy won't Work ? || Backtracking || C++ | why-greedy-wont-work-backtracking-c-by-i-j8ng | Intuition\nWhy Greedy won\'t work\nIf we fill all the cells having value as zero with the closest cell having value greater than 1 line by line.\nTestcase for w | isht_1542 | NORMAL | 2023-09-10T04:53:15.739627+00:00 | 2023-09-11T17:12:11.989940+00:00 | 1,178 | false | # Intuition\n**Why Greedy won\'t work**\nIf we fill all the cells having value as zero with the closest cell having value greater than 1 line by line.\nTestcase for which it won\'t work: \n[[3,2,0] \n[0,1,0] \n[0,3,0]]\n**0 indexed**\n**-** Fill [0,3] from [0,2] steps = 1\n**-** Fill [1,0] from [0,0] steps = 1\n**-**... | 14 | 0 | ['Backtracking', 'Greedy', 'Recursion', 'C++'] | 5 |
minimum-moves-to-spread-stones-over-grid | 🤣😂 Permutation solution!!!🔄💡 GIGA EAZZ LOL!!! DONT FEEL❤️🔥 | permutation-solution-giga-eazz-lol-dont-5iu5i | Intuition\n Describe your first thoughts on how to solve this problem. \nLets build all possible combinations and choose the best from them\n# Approach\n Descri | LTDigor | NORMAL | 2023-09-10T04:11:44.735713+00:00 | 2023-09-10T04:27:52.986579+00:00 | 1,355 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLets build all possible combinations and choose the best from them\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe need to construct arrays target with empty cells and stones with cells with free stones. If we hav... | 9 | 2 | ['Python3'] | 6 |
minimum-moves-to-spread-stones-over-grid | JAVA || BACKTRACKING || EXPLAINED | java-backtracking-explained-by-minnikesw-qd3n | \n\n# Approach\nBacktracking and selecting an overfilled cell(grid[i][j] > 1) to fill an empty cell (grid[i][j] == 0)\n\nThe cost of each filling will be the Ma | Minnikeswar | NORMAL | 2023-09-10T04:25:26.817354+00:00 | 2023-09-11T12:48:18.767819+00:00 | 659 | false | \n\n# Approach\nBacktracking and selecting an overfilled cell(grid[i][j] > 1) to fill an empty cell (grid[i][j] == 0)\n\nThe cost of each filling will be the [Manhattan distance](https://www.quora.com/What-is-Manhattan-Distance) between the empty cell and overfilled cell\n\n\n\n# Code\n```\nclass Solution {\n int so... | 8 | 0 | ['Backtracking', 'Greedy', 'Java'] | 2 |
minimum-moves-to-spread-stones-over-grid | Video Explanation (Both N! & 2^N solution) | video-explanation-both-n-2n-solution-by-4g3ap | Explanation\n\nClick here for the video\n\n# Code\n\n#define pii pair<int, int>\n#define F first\n#define S second\n\n/*\nclass Solution {\n vector<pii> zero | codingmohan | NORMAL | 2023-09-10T05:34:22.871934+00:00 | 2023-09-10T05:34:22.871954+00:00 | 310 | false | # Explanation\n\n[Click here for the video](https://youtu.be/KTSBf8sJm5s)\n\n# Code\n```\n#define pii pair<int, int>\n#define F first\n#define S second\n\n/*\nclass Solution {\n vector<pii> zero;\n vector<pii> non_zero;\n int result;\n \n int Distance (pii x, pii y) {\n return abs(x.F - y.F) + abs... | 7 | 0 | ['C++'] | 0 |
minimum-moves-to-spread-stones-over-grid | Naive backtrack to try all possible movements. I thought it was BFS | naive-backtrack-to-try-all-possible-move-yy1e | Intuition\n Describe your first thoughts on how to solve this problem. \nTry to move any exceed stone in one cell to any other empty cell.\nIn the contest, I th | Hayleyy | NORMAL | 2023-09-10T04:39:33.622862+00:00 | 2023-09-10T04:39:33.622883+00:00 | 375 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to move any exceed stone in one cell to any other empty cell.\nIn the contest, I thought it is BFS/ multi source BFS, BFS from stones or BFS from empty cells. But it will not give the optimal solution.\n\n# Code\n```\nclass Solution {... | 7 | 0 | ['Backtracking', 'Depth-First Search', 'Java'] | 2 |
minimum-moves-to-spread-stones-over-grid | Handwritten | Why Greedy FAILS ? | Backtracking | handwritten-why-greedy-fails-backtrackin-6j71 | Intuition\n## Why Backtracking?\n\n\n Describe your first thoughts on how to solve this problem. \n- Extreme Brute Force with backtracking solution\n- See the i | bala_000 | NORMAL | 2023-09-10T04:09:55.109907+00:00 | 2023-09-10T04:34:48.786514+00:00 | 370 | false | # Intuition\n## Why Backtracking?\n\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Extreme Brute Force with backtracking solution\n- See the issue actu... | 7 | 0 | ['Backtracking', 'Greedy', 'C++'] | 2 |
minimum-moves-to-spread-stones-over-grid | [C++] Brute Force || but Couldn't solved in Time | c-brute-force-but-couldnt-solved-in-time-5402 | Couldn\'t solved in contest!Very disappointed\n# Intuition\nBrute Force\nTry all possiblities\n# Approach\njust using Brute Force\n\nThis code is an implementat | Pathak_Ankit | NORMAL | 2023-09-10T04:09:36.483384+00:00 | 2023-09-10T11:36:00.657092+00:00 | 920 | false | Couldn\'t solved in contest!Very disappointed\n# Intuition\nBrute Force\nTry all possiblities\n# Approach\njust using Brute Force\n\nThis code is an implementation of a recursive algorithm to find the minimum number of moves required to place one stone in each cell of a 3x3 grid, where each cell can have multiple stone... | 7 | 1 | ['Backtracking', 'C'] | 2 |
minimum-moves-to-spread-stones-over-grid | Backtracking Solution | backtracking-solution-by-hong_zhao-cmmu | Since n is 9, we can brute force the minimum with backtracking\npython []\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n n | hong_zhao | NORMAL | 2023-09-10T04:07:58.112084+00:00 | 2023-12-19T00:34:10.625787+00:00 | 650 | false | Since n is 9, we can brute force the minimum with backtracking\n```python []\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n need, has = [], {}\n for i in range(3):\n for j in range(3):\n if grid[i][j] == 0:\n need.append((i, j))\n... | 7 | 0 | ['Python3'] | 1 |
minimum-moves-to-spread-stones-over-grid | Simple Recursion || Brute Force || Memoization || C++ || JAVA || Python | simple-recursion-brute-force-memoization-paxh | Intuition\n Describe your first thoughts on how to solve this problem. \nI am mapping every 0 with every possible index. Will fail for 8^8, for handled it separ | amannimcet2021 | NORMAL | 2023-09-10T06:06:48.454418+00:00 | 2023-09-10T06:51:17.140627+00:00 | 1,240 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI am mapping every 0 with every possible index. Will fail for 8^8, for handled it separately. Else to avoid the 8^8 condition Memoize it.\n\n\n# Complexity\n- Time complexity: n^n (n<=7)\n<!-- Add your time complexity here, e.g. $$O(n)$$ ... | 6 | 0 | ['Recursion', 'Python', 'C++', 'Java'] | 1 |
minimum-moves-to-spread-stones-over-grid | TIME 100% BEATS || BRUTE FORCE || RECURSION || C++ | time-100-beats-brute-force-recursion-c-b-h275 | 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 | coding_night | NORMAL | 2023-09-10T09:06:46.703668+00:00 | 2023-09-10T09:06:46.703691+00:00 | 621 | 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 | ['Recursion', 'C++'] | 1 |
minimum-moves-to-spread-stones-over-grid | ✅☑[C++] || 2 Best Approaches || Rescursion 🔥 | c-2-best-approaches-rescursion-by-marksp-zl4o | \n\n# Approach\nEach time we encounter a cell with grid[i][j] == 0 then we can take 1 from any of the other 8 cells which have a value > 1\n\n\n# Code\n\n\n---- | MarkSPhilip31 | NORMAL | 2023-09-10T04:56:18.782281+00:00 | 2023-09-10T04:56:18.782304+00:00 | 1,033 | false | \n\n# Approach\nEach time we encounter a cell with grid[i][j] == 0 then we can take 1 from any of the other 8 cells which have a value > 1\n\n\n# Code\n```\n\n------------------Approach 1--------------------\nclass Solution {\nprivate:\n bool check(vector<vector<int>> &grid){\n for(int i = 0 ; i < 3 ; i++){\n... | 5 | 0 | ['Recursion', 'C++'] | 1 |
minimum-moves-to-spread-stones-over-grid | Simplest Backtracking solution beats 100% with explanation | simplest-backtracking-solution-beats-100-rymg | Intuition\n Describe your first thoughts on how to solve this problem. \nThe given code is an implementation of a solution to find the minimum number of moves r | noob0408 | NORMAL | 2023-09-10T04:15:20.605738+00:00 | 2023-09-10T04:15:20.605764+00:00 | 444 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given code is an implementation of a solution to find the minimum number of moves required to transform a given grid into a state where all cells contain the value 1. The grid contains cells with values 0 and values greater than 1. Th... | 5 | 0 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'C++', 'Java'] | 0 |
minimum-moves-to-spread-stones-over-grid | Easy C++ Backtracking Solution 🔥🔥 | easy-c-backtracking-solution-by-kingsman-byjm | Intuition\nFor every zero, use backtracking and try to fill it with values from cells with extra numbers and try out all possible such combinations using backtr | kingsman007 | NORMAL | 2023-09-10T04:04:09.336810+00:00 | 2023-09-10T04:04:09.336827+00:00 | 1,064 | false | # Intuition\nFor every zero, use backtracking and try to fill it with values from cells with extra numbers and try out all possible such combinations using backtracking.\n# Code\n```\nclass Solution {\nprivate:\n vector<vector<int>> xtra, zero;\n int ret;\n void solve(int i, int count) {\n // base case\... | 5 | 0 | ['Backtracking', 'Recursion', 'C++'] | 2 |
minimum-moves-to-spread-stones-over-grid | 🔥BackTracting It Is || C++ | backtracting-it-is-c-by-jainwinn-fct4 | Code\n\nclass Solution {\npublic:\n //for each position having zero stones, we try putting stone from each position which has excess stones at a particular i | JainWinn | NORMAL | 2023-09-10T04:03:23.403414+00:00 | 2023-09-10T04:04:24.854546+00:00 | 442 | false | # Code\n```\nclass Solution {\npublic:\n //for each position having zero stones, we try putting stone from each position which has excess stones at a particular instant.\n \n //Recursion/Backtracking\n int solve(int idx,vector<pair<int,int>> &more,vector<pair<int,int>> &zero,vector<vector<int>>& grid){\n ... | 5 | 0 | ['Backtracking', 'C++'] | 0 |
minimum-moves-to-spread-stones-over-grid | ☑️✅Easy Java Solution || Beats 99.7% users✅☑️ | easy-java-solution-beats-997-users-by-vr-28u5 | PLEASE UPVOTE IF IT HELPED\n\n---\n\n# Intuition\nThis question can not be solved with the help of a greedy approach.\nBut Why? Because we have try to all ways | vritant-goyal | NORMAL | 2024-02-24T12:19:14.400147+00:00 | 2024-02-24T12:19:14.400182+00:00 | 248 | false | # **PLEASE UPVOTE IF IT HELPED**\n\n---\n\n# Intuition\nThis question can not be solved with the help of a greedy approach.\nBut Why? Because we have try to all ways to find the minimum among all of them.\nI wasted a lot of my time on solving this question with greedy appoaches,but failed every time.\nBut i have came u... | 4 | 0 | ['Array', 'Recursion', 'Java'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.