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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
three-equal-parts | Easy approach using Prefix Sum + 2 Sum [no one is talking about this] | easy-approach-using-prefix-sum-2-sum-no-0hazy | Prefix Sum\nNo post is talking about this apporach, and I came up with this when sleeping.\nTypically, sum of subarray problem can be resovled using prefix sum | jandk | NORMAL | 2021-07-17T23:02:25.231540+00:00 | 2021-07-17T23:02:25.231579+00:00 | 161 | false | ### Prefix Sum\nNo post is talking about this apporach, and I came up with this when sleeping.\nTypically, sum of subarray problem can be resovled using prefix sum array. So is this. Similarly, the `prefix[i]` represents the integer with the binary representation of `nums[:i]`, then `prefix[j] - prefix[i]` is the integ... | 2 | 0 | [] | 1 |
three-equal-parts | easy c++ | O(n) | faster than 99.4% solution | easy-c-on-faster-than-994-solution-by-ra-pqw1 | class Solution {\npublic:\n vector threeEqualParts(vector& arr) {\n int i,j,x=0,n=arr.size();\n for(i=0;iv(2);\n if(x%3!=0){\n | raoprashant61 | NORMAL | 2021-07-17T18:31:45.291885+00:00 | 2021-07-17T18:31:45.291936+00:00 | 42 | false | class Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n int i,j,x=0,n=arr.size();\n for(i=0;i<n;i++){\n if(arr[i]==1) x++;\n }\n vector<int>v(2);\n if(x%3!=0){\n v[1]=v[0]=-1;\n return v;\n }\n if(x==0){\n ... | 2 | 0 | [] | 0 |
three-equal-parts | ✔️ Easy Java O(N) || 100% fast || 1 ms time || count hack approach :) | easy-java-on-100-fast-1-ms-time-count-ha-gbyp | Added comments in java code to explain more deeply\n\n\n// 927. Three Equal Parts\n// Runtime: 1 ms, faster than 100.00% of Java online submissions for Three Eq | hitsa70 | NORMAL | 2021-07-17T17:55:00.686009+00:00 | 2022-02-01T17:35:06.678279+00:00 | 211 | false | **Added comments in java code to explain more deeply**\n```\n\n// 927. Three Equal Parts\n// Runtime: 1 ms, faster than 100.00% of Java online submissions for Three Equal Parts.\n// Memory Usage: 44.9 MB, less than 60.58% of Java online submissions for Three Equal Parts.\n\nclass Solution {\n public int[] threeEqual... | 2 | 0 | ['Counting', 'Java'] | 0 |
three-equal-parts | [HINTS] If You Look for Observations + Hints + Test Cases Come Over! | hints-if-you-look-for-observations-hints-6qjf | Observations\n1) Number of 1s should be dived by 3 with no remainder\n2) We can skip the leading zeros in the middle except trailing zeros\n3) Number of Middle | shtanriverdi | NORMAL | 2021-07-17T17:49:40.219388+00:00 | 2021-07-17T17:49:57.593039+00:00 | 44 | false | **Observations**\n1) Number of 1s should be dived by 3 with no remainder\n2) We can skip the leading zeros in the middle except trailing zeros\n3) Number of Middle zeros should be at least as num of trailing zeros\n\n**Some Good Test Cases**\n```\n[1,0,0,1,0,0,1,0,0]\n[1,0,0,1,0,0,0,1,0,0]\n[0,0,0,0,0,0,0,0,1,0,0,0,0,0... | 2 | 0 | [] | 0 |
three-equal-parts | Easy C++ Solution with comments | easy-c-solution-with-comments-by-ashish_-0sf3 | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n // count 1\n int countone=count(arr.begin(),arr.end(),1);\n | ashish_786 | NORMAL | 2021-07-17T12:34:23.923244+00:00 | 2021-07-17T15:49:26.323791+00:00 | 433 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n // count 1\n int countone=count(arr.begin(),arr.end(),1);\n int n=arr.size();\n if(countone%3)\n {\n return {-1,-1};\n }\n if(countone==0)\n {\n return {0,n... | 2 | 0 | ['C', 'C++'] | 1 |
three-equal-parts | C++ O(n) time and O(1) space | c-on-time-and-o1-space-by-ranjan_1997-182x | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n int count = 0;\n for (auto i:arr)\n {\n if(i | ranjan_1997 | NORMAL | 2021-07-17T11:53:53.208062+00:00 | 2021-07-17T11:53:53.208101+00:00 | 289 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n int count = 0;\n for (auto i:arr)\n {\n if(i == 1)\n count++;\n }\n if(count == 0)\n return {0,2};\n if(count%3 != 0)\n return {-1,-1};\n ... | 2 | 0 | [] | 0 |
three-equal-parts | [Python] BinarySearch O(nlogn) slow but viable solution | python-binarysearch-onlogn-slow-but-viab-hpyn | \nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n n = len(arr)\n ps = []\n cur = 0\n for x in arr:\n | samchan0221 | NORMAL | 2021-07-17T10:35:58.347502+00:00 | 2021-07-17T10:35:58.347544+00:00 | 55 | false | ```\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n n = len(arr)\n ps = []\n cur = 0\n for x in arr:\n cur <<= 1\n cur += x\n ps.append(cur)\n # print(ps[-1])\n for i in range(n-1):\n a = ps[i]\n ... | 2 | 1 | [] | 1 |
three-equal-parts | Python O(N) time /O(1) space | python-on-time-o1-space-by-tonymok97-j2dd | The idea is to count the trailing zero of the last session(must be counted)\nAs the leading zero can be ignored, we can just make sure that each session will ha | tonymok97 | NORMAL | 2021-07-17T09:13:25.499858+00:00 | 2021-07-17T12:54:14.935996+00:00 | 169 | false | The idea is to count the trailing zero of the last session(must be counted)\nAs the leading zero can be ignored, we can just make sure that each session will have enough trailing zeros.\n\nLeading zeros will be ignored automatically by accu sum\n```\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> Lis... | 2 | 0 | [] | 0 |
three-equal-parts | python O(n) beat 100% 304ms | python-on-beat-100-304ms-by-victerose-6ivh | \nclass Solution(object):\n def threeEqualParts(self, arr):\n N = len(arr)\n \n # ones_number : number of \'1\' in arr\n ones_num | victerose | NORMAL | 2021-07-17T08:44:47.104521+00:00 | 2021-07-17T08:44:47.104561+00:00 | 175 | false | ```\nclass Solution(object):\n def threeEqualParts(self, arr):\n N = len(arr)\n \n # ones_number : number of \'1\' in arr\n ones_number = sum(arr)\n if ones_number % 3 != 0: return [-1,-1]\n if ones_number == 0: return [0,N-1]\n \n # ones_each : number of \'1\'... | 2 | 0 | [] | 1 |
three-equal-parts | Three Equal Parts Python Solution, O(n) | three-equal-parts-python-solution-on-by-4dd4d | python\n\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n ones = []\n for i,num in enumerate(arr):\n if | haotianzhu | NORMAL | 2021-07-17T08:38:09.772802+00:00 | 2021-07-17T08:38:09.772840+00:00 | 87 | false | ```python\n\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n ones = []\n for i,num in enumerate(arr):\n if num == 1:\n ones.append(i)\n \n if len(ones) == 0:\n return [0,len(arr)-1]\n \n if len(ones) < 3 or len... | 2 | 1 | [] | 1 |
three-equal-parts | scala solution. | scala-solution-by-lyk4411-gu88 | \ndef findEndIdx(arr: Array[Int], i: Int, binary_value: String):Int = {\n if(arr.drop(i).dropWhile(_==0).take(binary_value.length).foldLeft("")((b,a)=> a | lyk4411 | NORMAL | 2021-05-10T03:09:02.880295+00:00 | 2021-05-10T03:09:02.880323+00:00 | 61 | false | ```\ndef findEndIdx(arr: Array[Int], i: Int, binary_value: String):Int = {\n if(arr.drop(i).dropWhile(_==0).take(binary_value.length).foldLeft("")((b,a)=> a + b) != binary_value) return -1\n return arr.drop(i).takeWhile(_==0).length + i + binary_value.length\n }\n def threeEqualParts(arr: Array[... | 2 | 0 | [] | 0 |
three-equal-parts | C++ short clean code | c-short-clean-code-by-soundsoflife-kzac | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int> &A) {\n vector<int> vi;\n for (int i = 0; i < A.size(); ++i) if (A[i] == | soundsoflife | NORMAL | 2020-08-27T15:54:59.805736+00:00 | 2020-08-27T16:02:17.852545+00:00 | 255 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int> &A) {\n vector<int> vi;\n for (int i = 0; i < A.size(); ++i) if (A[i] == 1) vi.push_back(i);\n if (vi.size() == 0) return vector{0, 2};\n if (vi.size() % 3 != 0) return vector{-1, -1};\n int len = A.size() - v... | 2 | 1 | [] | 0 |
three-equal-parts | Python simple solution | python-simple-solution-by-gyh75520-4d0a | If the solution exists, the number of 1 in list should be times of 3.\nSearch from right side to left, until we found num/3 1s. This index is not final answer, | gyh75520 | NORMAL | 2019-11-01T07:19:50.358795+00:00 | 2019-11-01T07:19:50.358844+00:00 | 261 | false | If the solution exists, the number of 1 in list should be times of 3.\nSearch from right side to left, until we found num/3 1s. This index is not final answer, but we find the binary value.\nFrom left side to right, find the first 1s and compare whether the first part value equal to bianay value and so on.\n\n```python... | 2 | 0 | [] | 3 |
three-equal-parts | [C++]O(n) time, simple sol with explaination | con-time-simple-sol-with-explaination-by-96a7 | cpp\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n // check number of 1s\n int oneCount = 0, n = A.size();\n | heyidk | NORMAL | 2019-09-27T13:16:45.607081+00:00 | 2019-09-27T13:16:45.607113+00:00 | 155 | false | ```cpp\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n // check number of 1s\n int oneCount = 0, n = A.size();\n for (int &i: A)\n oneCount += (i == 1);\n if (oneCount % 3 != 0)\n return vector<int> {-1, -1};\n if (oneCount == 0)\n... | 2 | 1 | [] | 0 |
three-equal-parts | Easy java solution | easy-java-solution-by-v2e4lisp-qt9c | \nclass Solution {\n public int[] threeEqualParts(int[] A) {\n List<Integer> plist = new ArrayList<>();\n for (int i = 0; i < A.length; i++) {\ | v2e4lisp | NORMAL | 2019-09-13T16:09:20.524068+00:00 | 2019-09-13T16:09:20.524125+00:00 | 230 | false | ```\nclass Solution {\n public int[] threeEqualParts(int[] A) {\n List<Integer> plist = new ArrayList<>();\n for (int i = 0; i < A.length; i++) {\n if (A[i] == 1) {\n plist.add(i);\n }\n }\n // all zero\n if (plist.size() == 0) {\n re... | 2 | 0 | [] | 1 |
three-equal-parts | simple C soultion with detailed analysis | simple-c-soultion-with-detailed-analysis-nut4 | The core idea is:\n1. if we look from backward, the last element must be valid part of the 3-rd number.\n2. we can get how many \'1\' should be in a part by cou | chilauhe | NORMAL | 2019-09-05T12:28:34.993025+00:00 | 2019-09-05T12:28:34.993059+00:00 | 218 | false | The core idea is:\n1. if we look from backward, **the last element must be valid part of the 3-rd number.**\n2. we can get *how many \'1\' should be in a part* by **counting how many one in array** and divde it into 3\n3. if we get a fraction instead an integer, it must **not** equal.\n4. then we just **count how many ... | 2 | 0 | ['C'] | 0 |
three-equal-parts | javascript 90ms | javascript-90ms-by-dchamud-game | \nvar threeEqualParts = function(A) {\n const getOneCount = () => {\n const oneCount = A.reduce((acc, bit) => bit == 1 ? acc + 1 : acc, 0)\n if | dchamud | NORMAL | 2019-04-22T16:08:30.833854+00:00 | 2019-04-22T16:08:30.833899+00:00 | 215 | false | ```\nvar threeEqualParts = function(A) {\n const getOneCount = () => {\n const oneCount = A.reduce((acc, bit) => bit == 1 ? acc + 1 : acc, 0)\n if(oneCount % 3 == 0) \n return oneCount / 3\n return -1\n }\n\n const getTail = oneCount => { \n let zeroCount = 0, idx = A.len... | 2 | 0 | ['JavaScript'] | 0 |
three-equal-parts | [Java] O(n) time; O(1) space (8 ms) | java-on-time-o1-space-8-ms-by-piroshki-yzh1 | Check if there are enough number of ones for three parts (aka number of ones is a multiple of 3). Iterate the array from the tail and find the spot that marks t | piroshki | NORMAL | 2018-10-21T20:12:49.593872+00:00 | 2018-10-21T20:12:49.593914+00:00 | 129 | false | 1. Check if there are enough number of ones for three parts (aka number of ones is a multiple of 3).
2. Iterate the array from the tail and find the spot that marks the start of a binary number with n/3 1s (n is total number of ones).
3. Lets call the marker in step 2 "part3". We need to check to see if there are 2 mor... | 2 | 0 | [] | 1 |
three-equal-parts | python solution with my thinking process (very simple logic,with extra Chinese explanation) | python-solution-with-my-thinking-process-25i1 | you can get Chinese explanation in \nhttps://buptwc.github.io/2018/10/21/Leetcode-927-Three-Equal-Parts/\n\nI define the three part as a,b,c.\nNotice that the l | bupt_wc | NORMAL | 2018-10-21T15:12:58.549489+00:00 | 2018-10-21T19:44:15.083997+00:00 | 213 | false | you can get Chinese explanation in \nhttps://buptwc.github.io/2018/10/21/Leetcode-927-Three-Equal-Parts/\n\nI define the three part as `a,b,c`.\nNotice that the length of A reaches 30000, so we cannot first determine the value of `a,b` separately and later compare with `c`, it\'s O(n^2) time! We need to find a way to d... | 2 | 2 | [] | 1 |
three-equal-parts | C# It is hard level algorithm and I could not make it in the contest | c-it-is-hard-level-algorithm-and-i-could-p312 | Oct. 20, 2018\n927. Three Equal Parts\n\nIt is the third algorithm in weekly contest 107. I did come out the idea but my code had a few bugs in the contest. It | jianminchen | NORMAL | 2018-10-21T03:36:13.106209+00:00 | 2020-08-20T22:08:41.326656+00:00 | 397 | false | Oct. 20, 2018\n927. Three Equal Parts\n\nIt is the third algorithm in weekly contest 107. I did come out the idea but my code had a few bugs in the contest. It took me more than 30 minutes in the contest and 20 minutes after the contest to make the code work. I also simplify the logic to make it readable. \n\nThe idea ... | 2 | 1 | [] | 0 |
three-equal-parts | [C++] O(n) Time, O(1) Space. 40ms | c-on-time-o1-space-40ms-by-goddice-hukm | First count the total number of 1s. If it is not a multiple of 3, then it is not possible. Otherwise divide it by 3, we can get the number of 1s should be in ea | goddice | NORMAL | 2018-10-21T03:13:57.287070+00:00 | 2018-10-21T21:53:22.818103+00:00 | 244 | false | First count the total number of 1s. If it is not a multiple of 3, then it is not possible.
Otherwise divide it by 3, we can get the number of 1s should be in each partition. The only uncertain thing now is the number tailing zeros for each partition. However, this can be easily determined by the last partition.
Now, we... | 2 | 1 | [] | 0 |
three-equal-parts | Solution | solution-by-deleted_user-nudy | C++ []\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n \n int countone=count(arr.begin(),arr.end(),1);\n int | deleted_user | NORMAL | 2023-05-14T03:04:10.618865+00:00 | 2023-05-14T03:26:01.334516+00:00 | 721 | false | ```C++ []\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n \n int countone=count(arr.begin(),arr.end(),1);\n int n=arr.size();\n if(countone%3)\n {\n return {-1,-1};\n }\n if(countone==0)\n {\n return {0,n-1};\n ... | 1 | 0 | ['C++', 'Java', 'Python3'] | 0 |
three-equal-parts | Easy C++ solution using strings in O(n) time and space complexity | easy-c-solution-using-strings-in-on-time-poo4 | Intuition\nThree Simple observations :-\n1.Total number of ones should be multiple of 3.\n2.Leading zeroes do not contribute\n3.Number of zeroes after the last | dattebayyo | NORMAL | 2023-01-28T19:59:15.490132+00:00 | 2023-01-28T19:59:15.490164+00:00 | 286 | false | # Intuition\nThree Simple observations :-\n1.Total number of ones should be multiple of 3.\n2.Leading zeroes do not contribute\n3.Number of zeroes after the last one of all 3 parts will be equal to the number of zeroes after the last one in 3rd part.\n\n# Approach\n1.Store the indexes of ones in a vector and check if t... | 1 | 0 | ['String', 'C++'] | 0 |
three-equal-parts | C++ | O(N) time complexity solution | c-on-time-complexity-solution-by-virtual-ocr4 | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n // Time complexity - O(N)\n\t\t\n int size = arr.size(), count= | Virtual91 | NORMAL | 2022-11-07T19:39:39.871327+00:00 | 2022-11-07T19:39:39.871375+00:00 | 181 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n // Time complexity - O(N)\n\t\t\n int size = arr.size(), count=0, tcount=0, iptr=0, jptr=2;\n string str = "", t = "", h1 = "", h2 = "";\n vector<int>res(2,-1);\n for(int i=0;i<size;i++){\n ... | 1 | 0 | ['C'] | 0 |
three-equal-parts | Python, faster than 100.00% | python-faster-than-10000-by-veanules-urij | \tdef threeEqualParts(self, arr: List[int]) -> List[int]:\n ones = arr.count(1)\n if ones == 0: return [0, 2]\n if ones % 3: return [-1, -1 | Veanules | NORMAL | 2022-04-15T12:25:41.526392+00:00 | 2022-04-15T12:25:41.526432+00:00 | 138 | false | \tdef threeEqualParts(self, arr: List[int]) -> List[int]:\n ones = arr.count(1)\n if ones == 0: return [0, 2]\n if ones % 3: return [-1, -1]\n ones_in_number = ones//3\n \n ones = 0\n start0 = i = arr.index(1)\n while(ones < ones_in_number):\n if arr[i]... | 1 | 0 | ['Python'] | 0 |
three-equal-parts | Three Equal Parts Solution Java | three-equal-parts-solution-java-by-bhupe-6zvy | class Solution {\n public int[] threeEqualParts(int[] A) {\n int ones = 0;\n\n for (int a : A)\n if (a == 1)\n ++ones;\n\n if (ones == 0)\ | bhupendra786 | NORMAL | 2022-04-12T07:45:03.159460+00:00 | 2022-04-12T07:45:03.159498+00:00 | 62 | false | class Solution {\n public int[] threeEqualParts(int[] A) {\n int ones = 0;\n\n for (int a : A)\n if (a == 1)\n ++ones;\n\n if (ones == 0)\n return new int[] {0, A.length - 1};\n if (ones % 3 != 0)\n return new int[] {-1, -1};\n\n int k = ones / 3;\n int i = 0;\n int j = 0;\n ... | 1 | 0 | ['Array', 'Math'] | 0 |
three-equal-parts | Typescript, documented to be easy-to-understand | typescript-documented-to-be-easy-to-unde-ptvp | \nfunction threeEqualParts(dd: number[]) {\n // Every part has to have the same number of digit 1, and so it must be divisible by 3.\n const countOnes = dd.re | user1145PG | NORMAL | 2022-02-01T22:12:46.423568+00:00 | 2022-02-01T22:12:46.423594+00:00 | 29 | false | ```\nfunction threeEqualParts(dd: number[]) {\n // Every part has to have the same number of digit 1, and so it must be divisible by 3.\n const countOnes = dd.reduce<number>((total, i) => total + (i === 1 ? 1 : 0), 0);\n if (countOnes === 0) return [0, 2];\n if (countOnes % 3 !== 0) return [-1, -1];\n\n // Get inc... | 1 | 0 | [] | 0 |
three-equal-parts | Golang & C++ solution | golang-c-solution-by-tjucoder-3pxh | go\nfunc threeEqualParts(arr []int) []int {\n\t// remove all leading zeros if 1 exist\n\tremovedLeadingZero := 0\n\tfor i := 0; i < len(arr); i++ {\n\t\tif arr[ | tjucoder | NORMAL | 2021-11-13T07:15:40.440667+00:00 | 2021-11-13T08:06:38.855889+00:00 | 101 | false | ```go\nfunc threeEqualParts(arr []int) []int {\n\t// remove all leading zeros if 1 exist\n\tremovedLeadingZero := 0\n\tfor i := 0; i < len(arr); i++ {\n\t\tif arr[i] == 1 {\n\t\t\tremovedLeadingZero = i\n\t\t\tarr = arr[i:]\n\t\t\tbreak\n\t\t}\n\t}\n\t// valid check\n\tif len(arr) < 3 {\n\t\treturn []int{-1, -1}\n\t}\n... | 1 | 0 | ['C', 'Go'] | 0 |
three-equal-parts | C++ || EASY | c-easy-by-priyanka1230-t6fx | \n\npublic:\n vector threeEqualParts(vector& arr) {\n int i,first,second,third,count=0,one=0;\n for(i=0;i<arr.size();i++)\n {\n | priyanka1230 | NORMAL | 2021-08-31T16:09:25.216817+00:00 | 2021-08-31T16:09:25.216864+00:00 | 111 | false | ```\n\n```public:\n vector<int> threeEqualParts(vector<int>& arr) {\n int i,first,second,third,count=0,one=0;\n for(i=0;i<arr.size();i++)\n {\n if(arr[i]==1)\n {\n count++;\n }\n }\n if(count==0)\n {\n return {0,2};... | 1 | 0 | [] | 0 |
three-equal-parts | Java easy O(N), 1ms, with comments | java-easy-on-1ms-with-comments-by-dimitr-kw9h | refactored version :\n\n public int[] threeEqualParts(int[] arr) {\n int len=arr.length, onesCount=0;\n int[] fail = new int[]{-1,-1}; //erro | dimitr | NORMAL | 2021-07-19T10:10:11.917473+00:00 | 2021-07-20T01:42:12.966687+00:00 | 98 | false | refactored version :\n```\n public int[] threeEqualParts(int[] arr) {\n int len=arr.length, onesCount=0;\n int[] fail = new int[]{-1,-1}; //error case return\n \n //every part of tree may have a variable number of zeros due to leading zeros, while\n //number of ones should be the s... | 1 | 0 | [] | 0 |
three-equal-parts | Simple O(n) logical approach explained with example | simple-on-logical-approach-explained-wit-i41d | Approach \n The array has to contain number of 1\'s that are multiple of 3\n Each of the three parts has to contain equal number of ones\n Now it\'s all abou | 495 | NORMAL | 2021-07-17T20:10:59.375065+00:00 | 2021-07-17T20:11:34.545911+00:00 | 116 | false | ### Approach \n* The array has to contain number of 1\'s that are multiple of 3\n* Each of the three parts has to contain equal number of ones\n* Now it\'s all about locating the beginning of 1s, and comparing the parts\n\n### Example\n```\n 000010101010000101010100001010101 << example\n [0]*1[1,0]*[0]*1[... | 1 | 0 | ['Python3'] | 0 |
three-equal-parts | Three Equal Parts | Java solution | three-equal-parts-java-solution-by-arjun-6z3x | ```\n public int[] threeEqualParts(int[] arr) {\n int n = arr.length ;\n List ones=new ArrayList() ;\n for(int i = 0 ; i < n ; i++)\n | arjunagarwal | NORMAL | 2021-07-17T19:39:39.181119+00:00 | 2021-07-17T19:39:39.181155+00:00 | 94 | false | ```\n public int[] threeEqualParts(int[] arr) {\n int n = arr.length ;\n List<Integer> ones=new ArrayList() ;\n for(int i = 0 ; i < n ; i++)\n {\n if(arr[i]>0)\n {\n ones.add(i) ;\n }\n }\n int cnt = ones.size() ;\n if(cnt ... | 1 | 0 | [] | 0 |
three-equal-parts | C++ (Clean, Commented for easy understanding) | c-clean-commented-for-easy-understanding-l05a | \n/*\n\tSuch approaches don\'t come to our minds in one go. I had taken help for this solution. Tried to put\n\tcomments so that others can understand well.\n\t | mazhar_mik | NORMAL | 2021-07-17T18:35:46.761876+00:00 | 2021-07-17T18:35:46.761902+00:00 | 42 | false | ```\n/*\n\tSuch approaches don\'t come to our minds in one go. I had taken help for this solution. Tried to put\n\tcomments so that others can understand well.\n\tPersonally, Leetcode\'s solution to this Qn and explanation are not written well. It seems like\n\ta mess and unreadable. I have tried to explain it with com... | 1 | 0 | [] | 0 |
three-equal-parts | Go Solution with a single iteration. Beats 100% | go-solution-with-a-single-iteration-beat-ds8g | \nvar Invalid = []int{-1, -1}\n\nfunc threeEqualParts(arr []int) []int {\n\tones := make([]int, 0, len(arr))\n\tfor i, n := range arr {\n\t\tif n == 1 {\n\t\t\t | evleria | NORMAL | 2021-07-17T17:42:22.192495+00:00 | 2021-07-17T17:42:22.192541+00:00 | 60 | false | ```\nvar Invalid = []int{-1, -1}\n\nfunc threeEqualParts(arr []int) []int {\n\tones := make([]int, 0, len(arr))\n\tfor i, n := range arr {\n\t\tif n == 1 {\n\t\t\tones = append(ones, i)\n\t\t}\n\t}\n\n\tif len(ones) == 0 {\n\t\treturn []int{0, len(arr) - 1}\n\t}\n\tif len(ones)%3 != 0 {\n\t\treturn Invalid\n\t}\n\n\tgr... | 1 | 0 | ['Go'] | 0 |
three-equal-parts | C++ Simple Solution | c-simple-solution-by-alamin-tokee-wth3 | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n vector<int> ans={-1,-1};\n int numOf1s = 0;\n for(int x: | alamin-tokee | NORMAL | 2021-07-17T17:23:33.527217+00:00 | 2021-07-17T17:23:33.527261+00:00 | 39 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n vector<int> ans={-1,-1};\n int numOf1s = 0;\n for(int x:arr){\n numOf1s += x;\n }\n if(numOf1s == 0){\n return {0,2};\n }\n if(numOf1s % 3 != 0){\n retu... | 1 | 0 | ['C'] | 0 |
three-equal-parts | Easy C++ Solution || O(n) Time Complexity | easy-c-solution-on-time-complexity-by-pr-uaxg | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) \n {\n int n = arr.size();\n vector<int> res(2);\n res[0] | pragyatewary24 | NORMAL | 2021-07-17T17:20:38.665868+00:00 | 2021-07-17T17:20:38.665911+00:00 | 25 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) \n {\n int n = arr.size();\n vector<int> res(2);\n res[0] = -1;\n res[1] = -1;\n \n int totalCountOne = 0;\n for(auto X: arr)\n {\n totalCountOne += X;\n }\n ... | 1 | 0 | [] | 0 |
three-equal-parts | C++ Solution | c-solution-by-saurabhvikastekam-b0la | \nclass Solution \n{\n public:\n vector<int> threeEqualParts(vector<int>& arr) \n {\n int count = 0;\n for (auto i:arr)\n {\n | SaurabhVikasTekam | NORMAL | 2021-07-17T16:45:24.733568+00:00 | 2021-07-17T16:45:24.733609+00:00 | 69 | false | ```\nclass Solution \n{\n public:\n vector<int> threeEqualParts(vector<int>& arr) \n {\n int count = 0;\n for (auto i:arr)\n {\n if(i == 1)\n count++;\n }\n if(count == 0)\n return {0,2};\n if(count%3 != 0)\n return {-1,-... | 1 | 0 | ['C', 'C++'] | 0 |
three-equal-parts | Linear times, O(n) Solution in Python [clean] | linear-times-on-solution-in-python-clean-fqqg | \n# Github: Shantanugupta1118\n# DAY 60 of DAY 100\n# 927. Three Equal Parts - Leetcode/July\n# https://leetcode.com/problems/three-equal-parts/\n\n\nclass So | shantanugupta1118 | NORMAL | 2021-07-17T15:46:24.757861+00:00 | 2021-07-17T15:50:48.913690+00:00 | 125 | false | ```\n# Github: Shantanugupta1118\n# DAY 60 of DAY 100\n# 927. Three Equal Parts - Leetcode/July\n# https://leetcode.com/problems/three-equal-parts/\n\n\nclass Solution:\n def threeEqualParts(self, arr):\n ans = [-1,-1]\n numsOf1s = 0\n for i in arr:\n numsOf1s += i\n if numsO... | 1 | 0 | ['Python', 'Python3'] | 0 |
three-equal-parts | Pretty short Java solution(~15 lines), explained | pretty-short-java-solution15-lines-expla-lpty | The idea is to count the number of ones numOnes: \n\nIf numOnes isn\'t divisible by 3, then you can\'t divide them into 3 parts so return [-1, -1]. \n\nSecondly | TheJesterKing | NORMAL | 2021-07-17T15:38:58.636259+00:00 | 2021-07-17T15:41:15.186966+00:00 | 76 | false | The idea is to count the number of ones `numOnes`: \n\nIf `numOnes` isn\'t divisible by 3, then you can\'t divide them into 3 parts so return [-1, -1]. \n\nSecondly, if there are only zeroes in the array, you can divide the array arbitrarily.\n\nFinally, if `numOnes` is divisible by 3, we run three pointers `first, sec... | 1 | 0 | ['Java'] | 0 |
three-equal-parts | O(n) Solution CPP | on-solution-cpp-by-gp1999-chlu | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n vector<int> ans{-1,-1};\n int count=0,ones=0,p1=0,p2=0,p3=0;\n | gp1999 | NORMAL | 2021-07-17T15:06:12.026457+00:00 | 2021-07-17T15:06:12.026486+00:00 | 43 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n vector<int> ans{-1,-1};\n int count=0,ones=0,p1=0,p2=0,p3=0;\n for(int i=0; i<arr.size();i++){\n count+=arr[i];\n }\n if(count%3) return ans;\n if(count==0){\n ans[0] = 0... | 1 | 0 | [] | 0 |
three-equal-parts | Rust solution | rust-solution-by-sugyan-9evi | rust\nimpl Solution {\n pub fn three_equal_parts(arr: Vec<i32>) -> Vec<i32> {\n let v = arr\n .iter()\n .enumerate()\n | sugyan | NORMAL | 2021-07-17T15:00:48.346334+00:00 | 2021-07-17T15:00:48.346398+00:00 | 70 | false | ```rust\nimpl Solution {\n pub fn three_equal_parts(arr: Vec<i32>) -> Vec<i32> {\n let v = arr\n .iter()\n .enumerate()\n .filter_map(|(i, &a)| if a == 1 { Some(i) } else { None })\n .collect::<Vec<_>>();\n if arr.len() < 3 || v.len() % 3 != 0 {\n ... | 1 | 0 | ['Rust'] | 0 |
three-equal-parts | c++(24ms 99,40%) pointers , three pass (greedy) | c24ms-9940-pointers-three-pass-greedy-by-we0j | Runtime: 24 ms, faster than 99.40% of C++ online submissions for Three Equal Parts.\nMemory Usage: 38.9 MB, less than 55.42% of C++ online submissions for Three | zx007pi | NORMAL | 2021-07-17T10:37:24.422283+00:00 | 2021-07-17T11:19:48.717511+00:00 | 133 | false | Runtime: 24 ms, faster than 99.40% of C++ online submissions for Three Equal Parts.\nMemory Usage: 38.9 MB, less than 55.42% of C++ online submissions for Three Equal Parts.\n**General idea:**\n**1.** If we can split this array for three equal parts we MUST have total number of "ones" is uqual 3* k \n**2.** split our a... | 1 | 1 | ['C', 'C++'] | 0 |
three-equal-parts | ✅✅Three Equal Parts || Python || Logic Building | three-equal-parts-python-logic-building-v39z4 | Key obseration is that three parts must have same number and pattern of 1s except the leading 0s part. \nMy idea is to:\n\n1. Count no. of ones, simply taking | code_assassin | NORMAL | 2021-07-17T10:37:10.897268+00:00 | 2021-07-17T10:38:29.883622+00:00 | 163 | false | Key obseration is that three parts must have same number and pattern of 1s except the leading 0s part. \nMy idea is to:\n\n1. Count no. of ones, simply taking sum. (if sum%3!=0 return [-1,-1])\n2. Search from right side to left, until we found sum/3 of 1s. This index defines the pattern of 1s.\n3. From left, ignore ... | 1 | 0 | [] | 0 |
three-equal-parts | javascript, 84ms | javascript-84ms-by-momocow-tc2w | Approximately 1.33N operations => O(N).\n\n\n/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar threeEqualParts = function (arr) {\n const gaps = [ | momocow | NORMAL | 2021-07-17T09:52:57.715231+00:00 | 2021-07-17T09:52:57.715271+00:00 | 145 | false | Approximately 1.33N operations => O(N).\n\n```\n/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar threeEqualParts = function (arr) {\n const gaps = []\n let head0s = 0\n let prev\n for (let p = 0; p < arr.length; p++) {\n if (arr[p] === 1) {\n if (prev !== undefined) {\n gaps.push(p - pr... | 1 | 0 | ['JavaScript'] | 0 |
three-equal-parts | Swift solution | swift-solution-by-yamironov-u3bx | Count ones in arr\n2. If there is no ones in arr, then all parts are zeros\n3. Ones count must be multiple of three, else it is not possible to split arr into t | yamironov | NORMAL | 2021-07-17T08:41:16.093090+00:00 | 2021-07-19T05:54:30.650354+00:00 | 49 | false | 1. Count ones in `arr`\n2. If there is no ones in `arr`, then all parts are zeros\n3. Ones count must be multiple of three, else it is not possible to split `arr` into three parts\n4. Find first significant bit for each part in `arr`\n5. The last part ends at the end of `arr`, it has a reference length. Check that the ... | 1 | 0 | ['Swift'] | 1 |
three-equal-parts | Just logic( Super Easy) | just-logic-super-easy-by-sramlax72-whcm | 1) Calculate number of 1\'s , let store it in cnt\n\n2) if cnt is not divisible by 3 return [-1,-1]\n\n\t3) now check in array from right to left and stop when | sramlax72 | NORMAL | 2021-07-17T08:23:05.483602+00:00 | 2021-07-17T08:27:22.323714+00:00 | 71 | false | 1) Calculate number of 1\'s , let store it in cnt\n\n2) if cnt is not divisible by 3 return [-1,-1]\n\n\t3) now check in array from right to left and stop when got cnt/3 ones. the part beyond it must be the number we need. It it is not then no other solution exists.Eg : arr = 01001000100 , so cnt = 3 ,and we got par... | 1 | 1 | [] | 0 |
three-equal-parts | Three Equal Parts || Easy C++ Solution | three-equal-parts-easy-c-solution-by-b_u-ylpr | \tclass Solution {\n\tpublic:\n vector threeEqualParts(vector& A) {\n //count number of 1\'s\n int totalOnes=accumulate(A.begin(), A.end(), 0); | B_U_Rafi | NORMAL | 2021-07-17T07:43:24.162080+00:00 | 2021-07-17T07:44:03.740394+00:00 | 86 | false | \tclass Solution {\n\tpublic:\n vector<int> threeEqualParts(vector<int>& A) {\n //count number of 1\'s\n int totalOnes=accumulate(A.begin(), A.end(), 0);\n //if we can not divide into 3 parts then return -1,-1\n if(totalOnes%3!=0){\n return {-1,-1};\n }\n \n ... | 1 | 1 | [] | 0 |
three-equal-parts | 1 ms, faster than 100.00% of Java online submissions . O(n) | 1-ms-faster-than-10000-of-java-online-su-5ppt | \nclass Solution {\n public int[] threeEqualParts(int[] A) {\n int l=A.length;\n int ones=0;\n int[] count=new int[l];\n for(int | ashutoshbhardwaj25122000 | NORMAL | 2021-02-18T07:07:27.747159+00:00 | 2021-02-18T07:07:27.747202+00:00 | 125 | false | ```\nclass Solution {\n public int[] threeEqualParts(int[] A) {\n int l=A.length;\n int ones=0;\n int[] count=new int[l];\n for(int i=0;i<l;i++){\n ones=(A[i]==1)?ones+1:ones;\n count[i]=ones;\n }\n \n int[] ans=new int[2];\n ans[0]=-1;\n ... | 1 | 1 | [] | 0 |
three-equal-parts | Python3 O(n) solution | python3-on-solution-by-owen2-llsc | \nclass Solution:\n def threeEqualParts(self, A: List[int]) -> List[int]:\n """\n 1: (# of 1) mod 3 == 0\n 2: calculate n3 values (start | owen2 | NORMAL | 2021-01-16T07:38:02.587663+00:00 | 2021-01-16T07:38:33.757249+00:00 | 99 | false | ```\nclass Solution:\n def threeEqualParts(self, A: List[int]) -> List[int]:\n """\n 1: (# of 1) mod 3 == 0\n 2: calculate n3 values (start with 0, end to tail)\n 3. check if there exists n1, n2 == n3\n """\n if sum(A) % 3 != 0:\n return [-1, -1]\n \n ... | 1 | 0 | [] | 0 |
three-equal-parts | o(n) c++ code with easy explanation | on-c-code-with-easy-explanation-by-mohit-pbdz | Intuition:\nall 3 halfs will have equal no of 1\'s. so find such 3 half\'s start index and end index.\n\nclass Solution {\npublic:\n vector<int> threeEqualPa | mohit_chau | NORMAL | 2020-08-28T20:22:19.394113+00:00 | 2020-08-28T20:22:19.394157+00:00 | 352 | false | **Intuition:**\nall 3 halfs will have equal no of 1\'s. so find such 3 half\'s start index and end index.\n```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n //count number of 1\'s\n int totalOnes=accumulate(A.begin(), A.end(), 0);\n //if we can not divide into 3 pa... | 1 | 1 | ['C'] | 0 |
three-equal-parts | C++ greedy | c-greedy-by-suhailakhtar039-uswo | The only thing horrifying in this problem is its tag hard and its proof which we don\'t have to do by the way.: )\n\nclass Solution {\npublic:\n vector<int> | suhailakhtar039 | NORMAL | 2020-07-05T12:03:15.959942+00:00 | 2020-07-05T12:03:15.959994+00:00 | 286 | false | The only thing horrifying in this problem is its tag hard and its proof which we don\'t have to do by the way.: )\n```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& a) {\n int one=0;\n int n=a.size();\n for(auto it:a)if(it)one++;\n if(one==0)\n return ve... | 1 | 0 | ['C'] | 1 |
three-equal-parts | Python 3 Solution Explained | python-3-solution-explained-by-hsweiner5-bbqe | \nclass Solution:\n def threeEqualParts(self, A):\n """\n Given an array of ones and zeros, this program determines whether\n the array | hsweiner54 | NORMAL | 2020-06-24T00:06:12.511886+00:00 | 2020-06-24T00:08:26.894088+00:00 | 181 | false | ```\nclass Solution:\n def threeEqualParts(self, A):\n """\n Given an array of ones and zeros, this program determines whether\n the array can be partitioned three ways where each partition contains\n the same pattern of ones and zeros beginning with a one. If there\n are no ones,... | 1 | 0 | ['Python3'] | 0 |
three-equal-parts | Java sol | java-sol-by-cuny-66brother-jzyn | \nclass Solution {\n int t;\n public int[] threeEqualParts(int[] A) {\n int res[]=new int[]{-1,-1};\n int part1=0;int part2=0;int part3=0;in | CUNY-66brother | NORMAL | 2020-04-26T17:38:13.312807+00:00 | 2020-04-26T17:38:13.312855+00:00 | 138 | false | ```\nclass Solution {\n int t;\n public int[] threeEqualParts(int[] A) {\n int res[]=new int[]{-1,-1};\n int part1=0;int part2=0;int part3=0;int cnt=1;\n Map<Integer,Integer>map=new HashMap<>();\n int ones=0;\n for(int n:A)if(n==1)ones++;\n if(ones==0)return new int[]{0,A... | 1 | 0 | [] | 0 |
three-equal-parts | simple solution O(N) time complexity O(1) Space | simple-solution-on-time-complexity-o1-sp-oaog | \tclass Solution(object):\n\tdef threeEqualParts(self, A):\n if len(A) < 3:\n return [-1,-1]\n nums = 0\n for i in range(len(A)) | fst-2391 | NORMAL | 2020-04-09T02:30:52.994978+00:00 | 2020-04-09T02:32:17.923014+00:00 | 138 | false | \tclass Solution(object):\n\tdef threeEqualParts(self, A):\n if len(A) < 3:\n return [-1,-1]\n nums = 0\n for i in range(len(A)):\n if A[i] == 1:\n nums += 1\n \n if nums % 3 != 0:\n return [-1,-1]\n \n if nums == 0:\n ... | 1 | 0 | [] | 0 |
three-equal-parts | [Python] intuitive solution, less than 100% memory usage | python-intuitive-solution-less-than-100-31pya | \nclass Solution(object):\n def threeEqualParts(self, A):\n """\n :type A: List[int]\n :rtype: List[int]\n """\n N = len(A | lljll | NORMAL | 2020-01-15T19:54:17.732237+00:00 | 2022-10-02T08:24:15.263605+00:00 | 214 | false | ```\nclass Solution(object):\n def threeEqualParts(self, A):\n """\n :type A: List[int]\n :rtype: List[int]\n """\n N = len(A)\n if N < 3:\n return [-1, -1]\n\n count_of_one = A.count(1)\n if count_of_one == 0:\n return [0, N-1]\n i... | 1 | 0 | ['Python', 'Python3'] | 0 |
three-equal-parts | Clean Java solution, with O(1) space and O(n) complexity | clean-java-solution-with-o1-space-and-on-c9dm | \npublic class Solution {\n public int[] threeEqualParts(int[] A) {\n if (A == null || A.length < 3) return new int[]{-1, -1};\n int oneCnt = 0 | sokui | NORMAL | 2019-05-28T00:27:57.072739+00:00 | 2019-05-28T00:27:57.072819+00:00 | 122 | false | ```\npublic class Solution {\n public int[] threeEqualParts(int[] A) {\n if (A == null || A.length < 3) return new int[]{-1, -1};\n int oneCnt = 0;\n for (int i = 0; i < A.length; i++) {\n if (A[i] == 1) oneCnt++;\n }\n if (oneCnt % 3 != 0) return new int[]{-1, -1};\n ... | 1 | 0 | [] | 0 |
three-equal-parts | python easy solution | python-easy-solution-by-butterfly-777-mwl1 | ```\nclass Solution:\n def threeEqualParts(self, A: List[int]) -> List[int]:\n n = len(A)\n ones = []\n for i in range(n):\n | butterfly-777 | NORMAL | 2019-05-10T15:49:44.115112+00:00 | 2019-05-10T15:49:44.115176+00:00 | 149 | false | ```\nclass Solution:\n def threeEqualParts(self, A: List[int]) -> List[int]:\n n = len(A)\n ones = []\n for i in range(n):\n if A[i]: ones.append(i)\n none = len(ones)\n if none == 0: return [0, n-1]\n if none % 3: return [-1, -1]\n g = none // 3\n i... | 1 | 0 | [] | 0 |
three-equal-parts | O(N) solution in Rust (4ms). | on-solution-in-rust-4ms-by-ttsugrii-cohb | The algorithm proceeds as follows:\n- find the number of 1s that each part must have. This number must be total_number_of_ones/3 sinceo otherwise parts would de | ttsugrii | NORMAL | 2019-01-21T05:09:14.639846+00:00 | 2019-01-21T05:09:14.639906+00:00 | 274 | false | The algorithm proceeds as follows:\n- find the number of `1`s that each part must have. This number must be `total_number_of_ones/3` sinceo otherwise parts would definitely not have same values. Because of this if the total number of `1`s is not a multiple of `3`, we can return `{-1, -1}` immediately. Another simple op... | 1 | 0 | [] | 1 |
three-equal-parts | My concise solution with explanation; beat 100% | my-concise-solution-with-explanation-bea-56uc | Please upvote if you like it.\n\nObservations/algorithm:\n1. Each part must have equal number of 1\'s.\n2. Let nums be the actual binary value of the parts, the | yuxiong | NORMAL | 2019-01-15T23:49:49.859530+00:00 | 2019-01-15T23:49:49.859594+00:00 | 132 | false | *Please upvote if you like it.*\n\n**Observations/algorithm**:\n1. Each part must have equal number of 1\'s.\n2. Let nums be the actual binary value of the parts, then num1 == num2 == num3, and each num starts with a 1. The only exception is when all nums are 0.\n3. Each part can have various number of leading 0\'s.\n ... | 1 | 0 | [] | 0 |
three-equal-parts | C++ O(n) time O(1) space with comments. | c-on-time-o1-space-with-comments-by-baba-ufde | If the number at each segment is same, the binary of those segment will also be same. \nThe key thing is to split all the ones into 3 equal parts. Then, the las | babaduredi | NORMAL | 2019-01-10T07:38:24.856308+00:00 | 2019-01-10T07:38:24.856374+00:00 | 184 | false | If the number at each segment is same, the binary of those segment will also be same. \nThe key thing is to split all the ones into 3 equal parts. Then, the last segment is final, it will be the value against which first 2 segments need to be compared.\n```\nvector<int> threeEqualParts(vector<int>& A) {\n int cn... | 1 | 0 | [] | 0 |
three-equal-parts | c++, simple to follow, fast, solution. O(n) time, O(1) space. With description and comments | c-simple-to-follow-fast-solution-on-time-np0z | The problem requires the dividing the input string such that the binary values are equal, so the first thing to do is check that the number of 'bits' set is div | christrompf | NORMAL | 2018-10-23T22:57:45.766723+00:00 | 2018-10-23T22:57:45.766768+00:00 | 178 | false | The problem requires the dividing the input string such that the binary values are equal, so the first thing to do is check that the number of 'bits' set is divisible by 3. If there are no set bits, then the answer is trivial and can be returned now.
If it is divisible by 3, we can relatively easily find the minimum t... | 1 | 1 | [] | 0 |
three-equal-parts | C++ 22 lines ,O(n) time Soluton | c-22-lines-on-time-soluton-by-panghu-ehik | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n int v[30005];\n int cnt = 0,n = A.size();\n for(int i=0;i< | panghu | NORMAL | 2018-10-22T11:38:25.389688+00:00 | 2018-10-22T11:38:25.389728+00:00 | 164 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n int v[30005];\n int cnt = 0,n = A.size();\n for(int i=0;i<n;i++)if(A[i])v[cnt++] = i;\n if (cnt%3!=0) return {-1,-1};\n if (cnt == 0) return {0, n-1};\n int a = v[0];\n int b = v[cnt/3];\... | 1 | 0 | [] | 0 |
three-equal-parts | Short C++ code | short-c-code-by-yuanjileet-jixh | \nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n int count = std::count(A.begin(), A.end(), 1);\n if(count % 3)\n | yuanjileet | NORMAL | 2018-10-22T02:02:32.731192+00:00 | 2018-10-22T02:02:32.731232+00:00 | 68 | false | ```\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& A) {\n int count = std::count(A.begin(), A.end(), 1);\n if(count % 3)\n return {-1, -1};\n count /= 3;\n int i = 0,j = 1,k = 2;\n for(int l = 0, cnt = 0; l < A.size(); cnt += A[l], ++l){\n ... | 1 | 0 | [] | 0 |
three-equal-parts | C++ solution in O(N), using cumulative sum and binary search | c-solution-in-on-using-cumulative-sum-an-7hoc | ```` class Solution { public: vector threeEqualParts(vector& A) { int ones = 0; vector B = A; for (int i = 0; i < A.size(); i+ | mjzyaad | NORMAL | 2018-10-21T18:25:59.842969+00:00 | 2018-10-21T18:25:59.843011+00:00 | 164 | false | ````
class Solution {
public:
vector<int> threeEqualParts(vector<int>& A) {
int ones = 0;
vector<int> B = A;
for (int i = 0; i < A.size(); i++)
ones += A[i];
if (ones == 0) {
return {0, 2};
}
else {
if (ones % 3 != ... | 1 | 0 | [] | 0 |
three-equal-parts | Java Solution: with detailed explanation | java-solution-with-detailed-explanation-a46ly | Approach We need to have 3 arrays with binary number represented by them should be all equal. We know that leading '0'(zero) in binary doesn't add value to bin | rkg | NORMAL | 2018-10-21T03:57:33.009799+00:00 | 2018-10-21T03:57:33.009847+00:00 | 131 | false | # Approach
We need to have 3 arrays with binary number represented by them should be all equal. We know that leading '0'(zero) in binary doesn't add value to binary number, but trailiing zero's do. So, if we could first count the trailing zeros in the incoming input first. Then we can try to find 2 other arrays with... | 1 | 0 | [] | 0 |
three-equal-parts | Python3 O(n) in 52ms with explanation | python3-on-in-52ms-with-explanation-by-h-4mk5 | The key observation is that if such a division is possible, then the three parts has to contain equal numbers of 1s. More details are in the comments.\n\ndef t | herbertzou | NORMAL | 2018-10-21T03:56:40.868722+00:00 | 2018-10-21T19:44:30.535026+00:00 | 168 | false | The key observation is that if such a division is possible, then the three parts has to contain equal numbers of 1s. More details are in the comments.\n```\ndef threeEqualParts(self, A):\n """\n :type A: List[int]\n :rtype: List[int]\n """\n one_count=A.count(1)\n if one_count... | 1 | 1 | [] | 1 |
three-equal-parts | O(n) O(1) beat 100% simple count and compare 3 part | on-o1-beat-100-simple-count-and-compare-f5mpq | Approach
count total of arr
separate to 3 part with the same total_part = total/3
compare each index in 3 part, check the same.
return result.
Complexity
Time c | luudanhhieu | NORMAL | 2025-04-08T13:59:05.512140+00:00 | 2025-04-08T13:59:05.512140+00:00 | 2 | false | # Approach
- count total of `arr`
- separate to 3 part with the same `total_part = total/3`
- compare each index in 3 part, check the same.
- return result.
# Complexity
- Time complexity: O(n)
- Space complexity:O(1)
# Code
```golang []
func threeEqualParts(arr []int) []int {
total := 0
for i := range arr {
tot... | 0 | 0 | ['Go'] | 0 |
minimum-white-tiles-after-covering-with-carpets | [Java/C++/Python] DP solution | javacpython-dp-solution-by-lee215-vqb5 | Explanation\ndp[i][k] means that,\nusing k tiles to cover the first i tiles\nthe minimum number of white tiles still visible.\n\n\nFor each tile s[i], we heve t | lee215 | NORMAL | 2022-03-19T16:02:23.187495+00:00 | 2022-03-19T16:06:47.176709+00:00 | 6,879 | false | # **Explanation**\n`dp[i][k]` means that,\nusing `k` tiles to cover the first `i` tiles\nthe minimum number of white tiles still visible.\n\n\nFor each tile `s[i]`, we heve two options,\nOne option is doing nothing, `jump` this tile,\n`jump = dp[i - 1][k] + int(s[i - 1])`\nThe other option is covering this tile\n`cover... | 117 | 3 | ['C', 'Python', 'Java'] | 18 |
minimum-white-tiles-after-covering-with-carpets | C++ Solution | Top-Down Dynamic Programming | Recursion + Memoization | c-solution-top-down-dynamic-programming-xwtvv | Iterate over string floor:\n\n- At each index pos in the string floor we have two options:\n\n - Use a carpet, that starts from the index pos and ends at pos | invulnerable | NORMAL | 2022-03-19T16:12:04.251920+00:00 | 2022-03-19T16:12:04.251952+00:00 | 3,175 | false | Iterate over string `floor`:\n\n- At each index `pos` in the string `floor` we have two options:\n\n - Use a carpet, that starts from the index `pos` and ends at `pos + carpetLength - 1`. All tiles in this part will change to black, hence move to index `pos + carpetLength`\n - Skip the index and move to next inde... | 58 | 2 | [] | 6 |
minimum-white-tiles-after-covering-with-carpets | [Python] short dp, explained | python-short-dp-explained-by-dbabichev-zuqn | Problem constraints will help you to understand that this problem can be solved with dp. Let the state dp(i, t) be minimum number of white tiles when we allowed | dbabichev | NORMAL | 2022-03-19T16:00:44.001968+00:00 | 2022-03-19T16:00:44.001991+00:00 | 1,552 | false | Problem constraints will help you to understand that this problem can be solved with `dp`. Let the state `dp(i, t)` be minimum number of white tiles when we allowed to use `t` number of carpets such that their right (and hence all carpets) lies in `[0, i]`. Then each moment of time we have option to take carpet or do n... | 29 | 3 | ['Dynamic Programming'] | 6 |
minimum-white-tiles-after-covering-with-carpets | DP detailed explanation with commented code | dp-detailed-explanation-with-commented-c-0zgr | Imagine we are covering the floor with carpets from left to right. At any point in this exercise, we will be at some point i and have carpetsRemaining carpets r | harmless-potato | NORMAL | 2022-03-19T16:01:33.181933+00:00 | 2022-03-19T16:01:33.181972+00:00 | 1,117 | false | Imagine we are covering the floor with carpets from left to right. At any point in this exercise, we will be at some point i and have carpetsRemaining carpets remaining. At this point we are only concerned with covering the floor from i to n - 1. \nIn other words i can say that the state at any point is fully defined b... | 28 | 3 | ['Dynamic Programming'] | 2 |
minimum-white-tiles-after-covering-with-carpets | Memory-Optimized DP | memory-optimized-dp-by-votrubac-hc08 | It feels like there could be some clever way to lay carpets, but there isn\'t. We need to search for an optimal solution.\n\n> Note: problem constrains give it | votrubac | NORMAL | 2022-03-19T16:02:37.149717+00:00 | 2022-03-21T09:24:14.260194+00:00 | 1,578 | false | It feels like there could be some clever way to lay carpets, but there isn\'t. We need to search for an optimal solution.\n\n> Note: problem constrains give it away.\n\nWe start with the top-down approach, and then convert it to the bottom-up one. By analyzing the tabulation, we can reduce the memory usage to O(n). The... | 24 | 2 | [] | 4 |
minimum-white-tiles-after-covering-with-carpets | C++ Easy to understand, with explanation and optimizations. DP | c-easy-to-understand-with-explanation-an-bcdy | Hello, while it may seem like a difficult one, the fourth question can be done with an almost bruteforce approach with some optimizations.\n\nLet dp[i][j] denot | dhruvatrejamain | NORMAL | 2022-03-19T16:01:42.163562+00:00 | 2022-03-19T20:21:23.851385+00:00 | 1,295 | false | Hello, while it may seem like a difficult one, the fourth question can be done with an almost bruteforce approach with some optimizations.\n\nLet dp[i][j] denote the maximum number of ones we can cover with i carpets till index j(**with current carpet ending exactly at index j**). Assuming that the current carpet ends ... | 15 | 1 | ['Dynamic Programming', 'C'] | 4 |
minimum-white-tiles-after-covering-with-carpets | Java Knapsack Solution | java-knapsack-solution-by-surajthapliyal-srdj | \nclass Solution {\n int pref[];\n\n public int minimumWhiteTiles(String floor, int tot, int len) {\n char a[] = floor.toCharArray();\n this | surajthapliyal | NORMAL | 2022-03-19T16:50:58.522484+00:00 | 2022-03-19T17:00:20.567291+00:00 | 814 | false | ```\nclass Solution {\n int pref[];\n\n public int minimumWhiteTiles(String floor, int tot, int len) {\n char a[] = floor.toCharArray();\n this.pref = new int[a.length];\n int c = 0;\n this.dp = new int[a.length + 1][tot + 1];\n for (int d[] : dp) Arrays.fill(d, -1);\n fo... | 12 | 1 | ['Memoization', 'Java'] | 3 |
minimum-white-tiles-after-covering-with-carpets | C++ Fixed-length Sliding Window + DP | c-fixed-length-sliding-window-dp-by-lzl1-ylwz | See my latest update in repo LeetCode\n\n## Solution 1. Fixed-length Sliding Window + DP\n\nIntuition:\n\n1. Use a sliding window of length carpetLen to compute | lzl124631x | NORMAL | 2022-03-19T16:00:52.804601+00:00 | 2022-03-29T17:14:04.143987+00:00 | 1,261 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Fixed-length Sliding Window + DP\n\n**Intuition**:\n\n1. Use a sliding window of length `carpetLen` to compute a `cover` array where `cover[i]` is the number of white tiles covered by a carpet placed ending at `floor[i]`.\... | 10 | 1 | [] | 3 |
minimum-white-tiles-after-covering-with-carpets | C++ Knapsack Memoization | c-knapsack-memoization-by-kamisamaaaa-fwi5 | \nclass Solution {\n int n;\n vector<int> suffix;\n vector<vector<int>> memo;\npublic:\n \n int doit(string& floor, int carp, int len, int ind) { | kamisamaaaa | NORMAL | 2022-03-19T17:08:43.835082+00:00 | 2022-03-19T18:04:28.281883+00:00 | 740 | false | ```\nclass Solution {\n int n;\n vector<int> suffix;\n vector<vector<int>> memo;\npublic:\n \n int doit(string& floor, int carp, int len, int ind) {\n if (ind >= n) return 0;\n if (carp == 0) return suffix[ind]; // if no carpets are left then all the white tiles from current index to the... | 9 | 1 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
minimum-white-tiles-after-covering-with-carpets | C++| DP | Memoization | c-dp-memoization-by-vaibhavshekhawat-2112 | ```\n\tvector> dp;\n int func(int i,string& s,int car,int len){\n if(i>=s.size()) return 0;\n if(dp[i][car]!=-1) return dp[i][car];\n if | vaibhavshekhawat | NORMAL | 2022-03-19T16:01:01.595632+00:00 | 2022-03-19T16:01:01.595661+00:00 | 632 | false | ```\n\tvector<vector<int>> dp;\n int func(int i,string& s,int car,int len){\n if(i>=s.size()) return 0;\n if(dp[i][car]!=-1) return dp[i][car];\n if(s[i]==\'0\') return dp[i][car]=func(i+1,s,car,len);\n else{ \n int ans=INT_MAX;\n ans=1+func(i+1,s,car,len);\n ... | 8 | 1 | ['Memoization', 'C'] | 4 |
minimum-white-tiles-after-covering-with-carpets | [C++] Simple C++ Code | c-simple-c-code-by-prosenjitkundu760-zg94 | If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n int d | _pros_ | NORMAL | 2022-07-25T16:59:39.221759+00:00 | 2022-07-25T16:59:39.221810+00:00 | 518 | false | # **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n int dfs(string &floor, int Carpets, int Len, int idx, vector<vector<int>> &dp)\n {\n if(idx >= floor.size())\n return 0;\n int v... | 7 | 0 | ['Dynamic Programming', 'Memoization', 'C', 'C++'] | 0 |
minimum-white-tiles-after-covering-with-carpets | ✅ C++ | DP + Memoization | c-dp-memoization-by-chandanagrawal23-hpub | \nclass Solution\n{\n public:\n int recur(string &s, int numCarpets, int len, int i, vector<vector < int>> &dp, vector< int > &sufOnes)\n {\n | chandanagrawal23 | NORMAL | 2022-03-19T16:23:01.068959+00:00 | 2022-03-19T16:25:05.596227+00:00 | 469 | false | ```\nclass Solution\n{\n public:\n int recur(string &s, int numCarpets, int len, int i, vector<vector < int>> &dp, vector< int > &sufOnes)\n {\n if (i >= s.size())\n return 0;\n if (numCarpets == 0)\n return sufOnes[i];\n\n if (dp[i][numCar... | 7 | 0 | ['Memoization'] | 0 |
minimum-white-tiles-after-covering-with-carpets | ✅[Python] Dynamic Programming + Prefix Sum Solution | Explained | python-dynamic-programming-prefix-sum-so-8exn | So this is a dynamic programming question with a trick.\nYou can guess it using the given constraints.\nThe solution can be divided into two parts:\n Recursive | mostlyAditya | NORMAL | 2022-03-19T16:01:33.349825+00:00 | 2022-03-19T16:01:33.349918+00:00 | 497 | false | So this is a dynamic programming question with a trick.\nYou can guess it using the given constraints.\nThe solution can be divided into two parts:\n* Recursively find ways to use carpets to cover the floor \n* Optimize using **Prefix Sum** to find the number of white tiles present between two indices of the floor\n\n... | 6 | 1 | ['Dynamic Programming', 'Prefix Sum', 'Python'] | 3 |
minimum-white-tiles-after-covering-with-carpets | [Python] Readable and Easy understand Bottom-Up DP solution in Python | python-readable-and-easy-understand-bott-qgjh | \nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int:\n n = len(floor)\n if carpetLen*numCarpets | alex391a | NORMAL | 2022-03-22T09:01:13.421497+00:00 | 2022-10-10T17:07:01.641499+00:00 | 298 | false | ```\nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int:\n n = len(floor)\n if carpetLen*numCarpets >= n:\n return 0\n floorlist = []\n for i in floor:\n if i == \'1\':\n floorlist.append(1)\n e... | 5 | 0 | ['Dynamic Programming', 'Python'] | 1 |
minimum-white-tiles-after-covering-with-carpets | Recursion + memoization + Time-Saver Trick | recursion-memoization-time-saver-trick-b-1zot | \nclass Solution {\npublic: \n int dp[1001][1001];\n int helper(string &floor, int idx, int numCarpets, int len)\n {\n if(idx >= floor.size())\n | ashishdtu007 | NORMAL | 2022-03-19T16:17:51.351087+00:00 | 2022-03-19T18:32:05.166002+00:00 | 327 | false | ```\nclass Solution {\npublic: \n int dp[1001][1001];\n int helper(string &floor, int idx, int numCarpets, int len)\n {\n if(idx >= floor.size())\n return 0;\n\t\t\t\n int &ans = dp[idx][numCarpets]; //reference variable so that we dont have to write this again \n \n if(a... | 4 | 0 | ['Recursion', 'Memoization'] | 1 |
minimum-white-tiles-after-covering-with-carpets | Dynamic Programming based solution || Recursion + Memoization || C++ Code | dynamic-programming-based-solution-recur-f2dx | \nclass Solution {\npublic:\n int dp[1002][1002];\n int min(int a, int b)\n {\n if(a<b) return a;\n return b;\n }\n \n int func( | KmIndu | NORMAL | 2022-03-27T17:03:08.949257+00:00 | 2022-03-27T17:03:08.949302+00:00 | 246 | false | ```\nclass Solution {\npublic:\n int dp[1002][1002];\n int min(int a, int b)\n {\n if(a<b) return a;\n return b;\n }\n \n int func(string &floor, int numCarpets, int &carpetLen, int i, vector<int> &prefix)\n {\n //Base Cases\n if(i>=floor.size())\n return 0;\n... | 3 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Java | Top Down Dynamic Programming | Memoization | java-top-down-dynamic-programming-memoiz-74e9 | Solution:\n\nclass Solution {\n Map<String, Integer> cache;\n \n public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n c | gnaby | NORMAL | 2022-03-24T20:23:18.868026+00:00 | 2022-03-24T20:23:18.868071+00:00 | 223 | false | Solution:\n```\nclass Solution {\n Map<String, Integer> cache;\n \n public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n cache = new HashMap<>();\n return helper(floor, 0, numCarpets, carpetLen);\n }\n \n public int helper(String floor, int position, int numCarpe... | 3 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Problem Analysis with formula, dynamic programming (tabulation approach) | problem-analysis-with-formula-dynamic-pr-587t | At first glance\n\nLet\'s analyze the problem at hand before writing the code. We are given the following inputs:\n\n - Floor, which is a string of characters 0 | adriandmen | NORMAL | 2022-03-19T16:06:26.671776+00:00 | 2022-03-19T16:22:23.663909+00:00 | 118 | false | ## At first glance\n\nLet\'s analyze the problem at hand before writing the code. We are given the following inputs:\n\n - **Floor**, which is a string of characters `0` and `1` only.\n\t - **0** denotes a black tile.\n\t - **1** denotes a white tile.\n - **Number of Carpets**, the number of carpets we can place.\n - *... | 3 | 0 | [] | 0 |
minimum-white-tiles-after-covering-with-carpets | Python3 DP Accepted (Is my runtime analysis correct? O(2^N)?) | python3-dp-accepted-is-my-runtime-analys-lf0v | Below is accepted.\n\nI struggle with figuring out runtime for DP problems, can someone help? \nIs it O(2^N)? My reasoning being that at each backtrack calll, y | breadsticks | NORMAL | 2022-03-19T16:00:38.657912+00:00 | 2022-03-19T16:00:38.657953+00:00 | 322 | false | Below is accepted.\n\nI struggle with figuring out runtime for DP problems, can someone help? \nIs it O(2^N)? My reasoning being that at each backtrack calll, you either cover the piano, or you don\'t. That\'s 2 choices with at most N steps/piano tiles.\n\nAlso what would be the best way to manually memoize the results... | 3 | 0 | [] | 1 |
minimum-white-tiles-after-covering-with-carpets | C++ || 0/1 knapsack | c-01-knapsack-by-rajput9189-qy9m | \nclass Solution {\nprivate:\n int dp[1001][1001];\n int solve(string& floor,int idx,int n,int car,int len,vector<int>&prefix)\n {\n if(idx==n | | rajput9189 | NORMAL | 2022-04-27T04:48:09.299851+00:00 | 2022-04-27T04:48:09.299883+00:00 | 149 | false | ```\nclass Solution {\nprivate:\n int dp[1001][1001];\n int solve(string& floor,int idx,int n,int car,int len,vector<int>&prefix)\n {\n if(idx==n || car==0)\n return 0;\n \n if(dp[idx][car]!=-1)\n return dp[idx][car];\n \n int range=min(idx+len-1,n-1);\n... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Dynamic Programming based solution || Recursion + Memoization || C++ Clean Code | dynamic-programming-based-solution-recur-cdmt | Code :\n\n\n class Solution {\n vector<int> whiteCount; // Stores no. of white tiles from ith index till the end\n \n\t// Count number of white tile from | i_quasar | NORMAL | 2022-03-23T17:44:46.198283+00:00 | 2022-03-23T17:57:23.565561+00:00 | 131 | false | # Code :\n\n```\n class Solution {\n vector<int> whiteCount; // Stores no. of white tiles from ith index till the end\n \n\t// Count number of white tile from index till end \n\t// Suffix sum of no. of white tiles\n void countTiles(string& floor, int n) {\n whiteCount.resize(n+2, 0);\n \n ... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
minimum-white-tiles-after-covering-with-carpets | ✔ C++ | DP | Heavily Commented | c-dp-heavily-commented-by-jk20-2mqa | \nclass Solution {\n \nprivate:\n int dp[1001][1001];\n int suffix[1001];\npublic:\n int recur(string &floor,int numCarpets,int carpetLen,int idx)\n | jk20 | NORMAL | 2022-03-23T12:21:27.090052+00:00 | 2022-03-23T12:21:27.090128+00:00 | 203 | false | ```\nclass Solution {\n \nprivate:\n int dp[1001][1001];\n int suffix[1001];\npublic:\n int recur(string &floor,int numCarpets,int carpetLen,int idx)\n {\n //Base Cases\n if(idx>=floor.size())\n return 0;\n \n if(numCarpets==0)\n return suffix[idx];\n ... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'C', 'C++'] | 1 |
minimum-white-tiles-after-covering-with-carpets | [Python3] dp | python3-dp-by-ye15-80w1 | Please pull this commit for solutions of biweekly 74. \n\n\nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int | ye15 | NORMAL | 2022-03-23T01:59:30.885124+00:00 | 2022-03-23T02:18:02.191835+00:00 | 268 | false | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/7e91381aab0f51486f380f703245463c99fed635) for solutions of biweekly 74. \n\n```\nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int:\n \n @cache\n def fn(i, n):\n """... | 2 | 0 | ['Python3'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Java solution 100% faster Using DP Tabulation | java-solution-100-faster-using-dp-tabula-xr8b | Explatation in comments.\nPlease Upvote if you undrstand this.\n...\nclass Solution {\n\n\tpublic int minimumWhiteTiles(String floor, int numCarpets, int carpet | harshy736 | NORMAL | 2022-03-20T07:16:35.685013+00:00 | 2022-03-20T07:16:35.685046+00:00 | 199 | false | Explatation in comments.\nPlease **Upvote** if you undrstand this.\n...\nclass Solution {\n\n\tpublic int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n\t\n\t\tchar[] arr = floor.toCharArray();\n\t\t\n\t\tint n = arr.length;\n\t\t//using dp\n\t\t\n\t\tint[][] dp = new int[numCarpets + 1][n + 1];\n\t... | 2 | 0 | ['Array', 'Dynamic Programming', 'Java'] | 1 |
minimum-white-tiles-after-covering-with-carpets | Simple Solution in Java || Concise and Elegant || With Memoization | simple-solution-in-java-concise-and-eleg-zttg | \nclass Solution {\n private int[][] dp;\n \n public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n this.dp = new int[fl | PRANAV_KUMAR99 | NORMAL | 2022-03-20T06:57:05.228654+00:00 | 2022-03-20T06:57:56.243004+00:00 | 49 | false | ```\nclass Solution {\n private int[][] dp;\n \n public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n this.dp = new int[floor.length()+1][numCarpets+1];\n for(int i=0; i<floor.length(); i++){\n Arrays.fill(dp[i], -1);\n }\n \n char[] str = ... | 2 | 0 | [] | 0 |
minimum-white-tiles-after-covering-with-carpets | Top Down || C++ Solution || Well commented | top-down-c-solution-well-commented-by-sh-ihve | \nclass Solution {\npublic:\n int explore(int i,string &floor,int numCarpets, int &carpetLen, vector<vector<int>> &dp)\n {\n if(i==floor.length())\ | Shishir_Sharma | NORMAL | 2022-03-20T02:23:09.956678+00:00 | 2022-03-20T02:23:09.956708+00:00 | 90 | false | ```\nclass Solution {\npublic:\n int explore(int i,string &floor,int numCarpets, int &carpetLen, vector<vector<int>> &dp)\n {\n if(i==floor.length())\n {\n return 0;\n }\n if(dp[i][numCarpets]!=-1)\n {\n return dp[i][numCarpets];\n }\n \n ... | 2 | 0 | ['C', 'C++'] | 0 |
minimum-white-tiles-after-covering-with-carpets | C++ Dynamic Programing Solution | Time-O(n^2), Space- O(n) | c-dynamic-programing-solution-time-on2-s-ss7v | \nclass Solution {\npublic:\n int minimumWhiteTiles(string a, int n, int k) {\n \n int m= a.size();\n \n vector<int> v(m+1,0),h;\ | abhinandan__22 | NORMAL | 2022-03-19T19:16:48.340110+00:00 | 2022-03-19T19:16:48.340152+00:00 | 53 | false | ```\nclass Solution {\npublic:\n int minimumWhiteTiles(string a, int n, int k) {\n \n int m= a.size();\n \n vector<int> v(m+1,0),h;\n \n v[0] = 0;\n \n for(int i=1;i<=m;i++)\n {\n v[i] = v[i-1];\n if(a[i-1]==\'1\')\n ... | 2 | 0 | [] | 0 |
minimum-white-tiles-after-covering-with-carpets | [Python][DP] Inspired by kadane algo and buy sell stock IV | pythondp-inspired-by-kadane-algo-and-buy-1033 | I. Intuition:\nThe key idea is that we find the maximum tiles can be covered with one carpet (at a time).\n\nFor the example:\nfloor = "10110101"\nnumCarpets=2\ | hangnguyendieu | NORMAL | 2022-03-19T16:40:52.619374+00:00 | 2022-03-19T16:40:52.619429+00:00 | 140 | false | I. Intuition:\nThe key idea is that we find the maximum tiles can be covered with one carpet (at a time).\n\nFor the example:\n`floor = "10110101"`\n`numCarpets=2`\n`carpetLen=2`\n\nWith numCapets = 2, that means we will have 2 carpets to use. \nFirst, we find the maximum tiles that the first carpet can cover.\n`dp[fir... | 2 | 0 | ['Dynamic Programming', 'Python'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Neat and clean Recursion + Memoization || Easy to understand | neat-and-clean-recursion-memoization-eas-u8cf | ```class Solution {\npublic:\n string s;\n int n;\n int prefix[1001];\n int len;\n int dp[1001][1001];\n int solve(int index, int carpet) {\n | lakshaygrover7 | NORMAL | 2022-03-19T16:21:45.603104+00:00 | 2022-03-19T16:21:45.603140+00:00 | 106 | false | ```class Solution {\npublic:\n string s;\n int n;\n int prefix[1001];\n int len;\n int dp[1001][1001];\n int solve(int index, int carpet) {\n if(carpet <= 0 || index >= n)\n return 0;\n if(dp[index][carpet] != -1)\n return dp[index][carpet];\n int x = 0;\n ... | 2 | 0 | ['Dynamic Programming', 'Memoization'] | 1 |
minimum-white-tiles-after-covering-with-carpets | [Python3] simple bottom-up DP solution | python3-simple-bottom-up-dp-solution-by-9tonu | python\nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int:\n n = len(floor)\n dp = [[0]*(numCar | rayhongz | NORMAL | 2022-03-19T16:19:41.573557+00:00 | 2022-03-19T16:19:41.573583+00:00 | 132 | false | ```python\nclass Solution:\n def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int:\n n = len(floor)\n dp = [[0]*(numCarpets+1) for _ in range(n+1)]\n for i in range(1, n+1):\n dp[i][0] = dp[i-1][0] + (floor[i-1] == \'1\')\n \n for k in range(1,... | 2 | 0 | ['Dynamic Programming', 'Python'] | 0 |
minimum-white-tiles-after-covering-with-carpets | Classical DP | Memoization | Similiar to 0/1 Knapsack | classical-dp-memoization-similiar-to-01-4cwyr | ```\nclass Solution {\npublic:\n vector pre;\n int n;\n vector> dp;\n int fun(int i,string &f,int nc,int len){\n \n if(i >= n) return | njcoder | NORMAL | 2022-03-19T16:13:15.690377+00:00 | 2022-03-19T16:14:44.177324+00:00 | 158 | false | ```\nclass Solution {\npublic:\n vector<int> pre;\n int n;\n vector<vector<int>> dp;\n int fun(int i,string &f,int nc,int len){\n \n if(i >= n) return 0;\n if(nc == 0){\n return pre[n-1] - (i == 0 ? 0 : pre[i-1]);\n }\n if(dp[i][nc] != -1) return dp[i][nc];\n ... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'Prefix Sum'] | 0 |
minimum-white-tiles-after-covering-with-carpets | [c++] Simple recursive + memoization | Easy to think | Commented | c-simple-recursive-memoization-easy-to-t-8dj1 | \nclass Solution {\npublic:\n vector<vector<int>> dp;\n int minCover(string& s, int index, int numCarpets, int len){\n if(index >= s.length()) | mohammedismail | NORMAL | 2022-03-19T16:06:08.438489+00:00 | 2022-03-19T16:06:38.583335+00:00 | 73 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> dp;\n int minCover(string& s, int index, int numCarpets, int len){\n if(index >= s.length()) // if index >= s.length(), then there is no tiles present.\n return 0;\n if(dp[index][numCarpets] != -1) // State of the dp is represen... | 2 | 0 | [] | 0 |
minimum-white-tiles-after-covering-with-carpets | Simple Memoization based solution | simple-memoization-based-solution-by-use-3717 | Approach\nThree choices\n1. Use carpet if available and necessary. In this can case jump to index + carpet length\n2. Do not use carpet even if available and ne | user6337nf | NORMAL | 2023-04-12T05:28:05.008755+00:00 | 2023-04-12T05:28:05.008798+00:00 | 40 | false | # Approach\nThree choices\n1. Use carpet if available and necessary. In this can case jump to index + carpet length\n2. Do not use carpet even if available and necessary. Increase count by 1 and move to next index. Here we save carpt to be used later. \n3. Handle scenarios like no carpet available or carpet not necessa... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Java'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.