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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
minimum-operations-to-make-the-array-k-increasing | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-jf9g | Using Binary Search\n\n Time Complexity :- O(NlogN * K)\n\n Space Complexity :- O(N * K)\n\n\nclass Solution {\npublic:\n int kIncreasing(vector<int>& nums, | __KR_SHANU_IITG | NORMAL | 2022-07-04T06:00:11.612637+00:00 | 2022-07-04T06:00:36.532620+00:00 | 141 | false | * ***Using Binary Search***\n\n* ***Time Complexity :- O(NlogN * K)***\n\n* ***Space Complexity :- O(N * K)***\n\n```\nclass Solution {\npublic:\n int kIncreasing(vector<int>& nums, int k) {\n \n int n = nums.size();\n \n // all the k subsets are independent of each other, so we can perfo... | 0 | 0 | ['Binary Search', 'C', 'Binary Tree'] | 0 |
minimum-operations-to-make-the-array-k-increasing | python LIS - TC(nlogn) | python-lis-tcnlogn-by-vincent_great-7es9 | \ndef kIncreasing(self, arr: List[int], k: int) -> int: \n\tdef lis(nums):\n\t\tans = [nums[0]]\n\t\tfor n in nums[1:]:\n\t\t\tif ans[-1]<=n:\n\t\t\t\tans.appen | vincent_great | NORMAL | 2022-06-30T16:25:57.341528+00:00 | 2022-06-30T16:25:57.341578+00:00 | 58 | false | ```\ndef kIncreasing(self, arr: List[int], k: int) -> int: \n\tdef lis(nums):\n\t\tans = [nums[0]]\n\t\tfor n in nums[1:]:\n\t\t\tif ans[-1]<=n:\n\t\t\t\tans.append(n)\n\t\t\telse:\n\t\t\t\tidx = bisect.bisect(ans, n)\n\t\t\t\tans[idx] = n\n\t\treturn len(ans)\n\n\tres = 0\n\tfor i in range(k):\n\t\tcans = []\n\t\twhil... | 0 | 0 | [] | 0 |
minimum-operations-to-make-the-array-k-increasing | Golang 100/80 | golang-10080-by-adam-hoelscher-a86y | Logic in comments. O(n * log n/k)time; O(n/k) space\n\nfunc kIncreasing(arr []int, k int) int {\n\n // the name of this problem is not optimal. We\'re not ac | adam-hoelscher | NORMAL | 2022-06-28T00:46:42.433946+00:00 | 2022-06-28T00:46:42.433978+00:00 | 26 | false | Logic in comments. `O(n * log n/k)`time; `O(n/k)` space\n```\nfunc kIncreasing(arr []int, k int) int {\n\n // the name of this problem is not optimal. We\'re not actually trying to make the suqsequences increasing\n // we\'re trying to make them non-decreasing\n\n // the general approach is the same idea as ht... | 0 | 0 | ['Binary Search', 'Dynamic Programming'] | 0 |
minimum-operations-to-make-the-array-k-increasing | K grps LIS | k-grps-lis-by-ishubhamrana-6bjp | \nclass Solution {\npublic:\n int kIncreasing(vector<int>& arr, int k) {\n vector<vector<int> > lis(k);\n int N=arr.size();\n \n | iShubhamRana | NORMAL | 2022-06-24T05:30:58.906827+00:00 | 2022-06-24T05:30:58.906869+00:00 | 19 | false | ```\nclass Solution {\npublic:\n int kIncreasing(vector<int>& arr, int k) {\n vector<vector<int> > lis(k);\n int N=arr.size();\n \n for(int i=0;i<N;i++){\n int grp = i%k;\n grp_size[grp]++;\n \n auto &lis_grp = lis[grp];\n \n ... | 0 | 0 | [] | 0 |
minimum-operations-to-make-the-array-k-increasing | [Python 10 lines] Binary Search with thought process when being asked during interviews | python-10-lines-binary-search-with-thoug-82fe | Binary Search\nLet\'s simply the problem first. What if k is large enough such that there is only one pair for each i to construct the sequence? We just need to | jandk | NORMAL | 2022-06-12T10:57:05.684654+00:00 | 2022-06-12T10:57:05.684695+00:00 | 96 | false | ### Binary Search\nLet\'s simply the problem first. What if `k` is large enough such that there is only one pair for each `i` to construct the sequence? We just need to check each pair to see if it\'s valid or not, and increase the final result by 1 if the pair is invalid.\n\nThen let\'s decrement `k` , the number of i... | 0 | 0 | ['Binary Tree'] | 0 |
minimum-operations-to-make-the-array-k-increasing | [JAVA] Easy to understand O(NlogN) | java-easy-to-understand-onlogn-by-chenya-cxie | very very similar to longest increasing subsequence\n\n\nclass Solution {\n public int kIncreasing(int[] A, int k) {\n // Longest increasing subsequen | chenyang_johan | NORMAL | 2022-05-11T07:41:34.499707+00:00 | 2022-05-11T07:41:34.499747+00:00 | 144 | false | very very similar to longest increasing subsequence\n\n```\nclass Solution {\n public int kIncreasing(int[] A, int k) {\n // Longest increasing subsequence for\n // A[i]..A[i + k].. A[i + 2k]\n int n = A.length;\n // int[] memo = new int[n];\n int res = 0;\n for (int s = 0; ... | 0 | 0 | ['Binary Tree'] | 0 |
minimum-operations-to-make-the-array-k-increasing | [C++] LIS with binary search | c-lis-with-binary-search-by-kaminyou-b6bi | \nclass Solution {\npublic:\n int upperBound(vector<int>& nums, int x) {\n int left = 0;\n int right = nums.size();\n while (left < righ | kaminyou | NORMAL | 2022-04-29T16:57:21.787866+00:00 | 2022-04-29T16:57:21.787901+00:00 | 117 | false | ```\nclass Solution {\npublic:\n int upperBound(vector<int>& nums, int x) {\n int left = 0;\n int right = nums.size();\n while (left < right) {\n int mid = left + (right - left) / 2;\n if (nums[mid] > x) right = mid;\n else left = mid + 1;\n }\n ret... | 0 | 0 | ['C', 'Binary Tree'] | 0 |
minimum-operations-to-make-the-array-k-increasing | [C++] Beats 97% | LIS | Just ignore K for a while :) | c-beats-97-lis-just-ignore-k-for-a-while-zw3u | We can skip K for a while, which makes this question as Minimum operations to Make the Array Increasing, which can be solved by finding the LIS (Longest Increas | meKabhi | NORMAL | 2022-04-23T12:30:17.820753+00:00 | 2022-04-23T12:30:47.916800+00:00 | 157 | false | We can skip `K` for a while, which makes this question as `Minimum operations to Make the Array Increasing`, which can be solved by finding the LIS (Longest Increasing Subsequence), using binary search, and subtracting the size of LIS from size of the array. Performing this step `K` times will give the desired result.\... | 0 | 0 | ['Dynamic Programming', 'C', 'Binary Tree', 'C++'] | 0 |
minimum-operations-to-make-the-array-k-increasing | C++ 11 line | c-11-line-by-sanzenin_aria-mye8 | ```\n int kIncreasing(vector& arr, int k) {\n int numGood = 0;\n for(int i = 0; i<k; i++){\n vector v;\n for(int j=i;j<ar | sanzenin_aria | NORMAL | 2022-04-14T00:54:08.938944+00:00 | 2022-04-14T00:54:08.938985+00:00 | 82 | false | ```\n int kIncreasing(vector<int>& arr, int k) {\n int numGood = 0;\n for(int i = 0; i<k; i++){\n vector<int> v;\n for(int j=i;j<arr.size();j+=k){\n auto it = upper_bound(v.begin(), v.end(), arr[j]);\n if(it == v.end()) v.push_back(arr[j]);\n ... | 0 | 0 | [] | 0 |
minimum-operations-to-make-the-array-k-increasing | C++ lis | c-lis-by-wufengxuan1230-n67q | \nclass Solution {\npublic:\n int kIncreasing(vector<int>& nums, int k) {\n int res = 0;\n vector<int> lis(nums.size() / k + 2, INT_MAX);\n | wufengxuan1230 | NORMAL | 2022-03-29T04:44:19.541007+00:00 | 2022-03-29T04:47:56.219112+00:00 | 66 | false | ```\nclass Solution {\npublic:\n int kIncreasing(vector<int>& nums, int k) {\n int res = 0;\n vector<int> lis(nums.size() / k + 2, INT_MAX);\n for (int i = 0; i < k; ++i) {\n std::fill(lis.begin(), lis.end(), INT_MAX);\n int maxLen = 1;\n lis[maxLen] = nums[i];\n... | 0 | 0 | [] | 0 |
minimum-operations-to-make-the-array-k-increasing | Golang LIS Binary Search O(nlog(n)) time complexity | golang-lis-binary-search-onlogn-time-com-r2a7 | \nfunc kIncreasing(arr []int, k int) int {\n buckets := partition(arr, k)\n \n // T -> O(n)\n // S -> O(n)\n var numberOfOperations int\n for | alyxjperkins | NORMAL | 2022-03-27T19:24:51.636592+00:00 | 2022-03-27T19:24:51.636635+00:00 | 50 | false | ```\nfunc kIncreasing(arr []int, k int) int {\n buckets := partition(arr, k)\n \n // T -> O(n)\n // S -> O(n)\n var numberOfOperations int\n for _, bucket := range buckets {\n numberOfOperations += longestIncreasingSequence(bucket)\n }\n \n return numberOfOperations\n}\n\n// T -> O(n)\... | 0 | 0 | [] | 0 |
minimum-operations-to-make-the-array-k-increasing | [Java] Clean LC-300 LIS version with Collections.binarySearch | java-clean-lc-300-lis-version-with-colle-wywn | \nclass Solution {\n private int lis(List<Integer> nums) {\n List<Integer> sub = new ArrayList<>();\n sub.add(nums.get(0));\n \n | srinathcoder | NORMAL | 2022-03-22T05:41:59.786653+00:00 | 2022-03-28T02:05:11.321757+00:00 | 186 | false | ```\nclass Solution {\n private int lis(List<Integer> nums) {\n List<Integer> sub = new ArrayList<>();\n sub.add(nums.get(0));\n \n for (int i = 1; i < nums.size(); i++) {\n int num = nums.get(i);\n if (num >= sub.get(sub.size() - 1)) {\n sub.add(num);... | 0 | 0 | ['Binary Tree', 'Java'] | 0 |
minimum-operations-to-make-the-array-k-increasing | C++ | Binary Search | LIS | c-binary-search-lis-by-offamikumar-nh0t | \nclass Solution {\n int getPos(int val, vector<int>&v) {\n int high = v.size()-1, low = 0; \n int idx{}; \n while (low < high) {\n | offamikumar | NORMAL | 2022-03-15T08:23:48.219284+00:00 | 2022-03-15T08:23:48.219317+00:00 | 80 | false | ```\nclass Solution {\n int getPos(int val, vector<int>&v) {\n int high = v.size()-1, low = 0; \n int idx{}; \n while (low < high) {\n int mid = (low + high) / 2; \n if (val >= v[mid]) {\n low = mid + 1; \n } else {\n high = mid; \n ... | 0 | 0 | ['Binary Tree'] | 0 |
binary-prefix-divisible-by-5 | Detailed Explanation using Modular Arithmetic O(n) | detailed-explanation-using-modular-arith-omhg | Intuition\n First, let us see how to append an extra bit at the end of a binary number\n Any binary number akak-1...a0 has the form a020 + a121 + ........ a02k | just__a__visitor | NORMAL | 2019-03-31T05:02:07.125180+00:00 | 2019-03-31T05:02:07.125242+00:00 | 9,796 | false | **Intuition**\n* First, let us see how to append an extra bit at the end of a binary number\n* Any binary number **a<sub>k</sub>a<sub>k-1</sub>...a<sub>0</sub>** has the form a<sub>0</sub>*2<sup>0</sup> + a<sub>1</sub>*2<sup>1</sup> + ........ a<sub>0</sub>*2<sup>k</sup>\n\n\n* To free up an extra slot at the end, we ... | 147 | 10 | [] | 12 |
binary-prefix-divisible-by-5 | [Java/Python 3] 7/1 liners - left shift, bitwise or, and mod. | javapython-3-71-liners-left-shift-bitwis-tgbi | Since A includes only 0s and 1s, we can imitate binary operations.\n\njava\n public List<Boolean> prefixesDivBy5(int[] A) {\n int k = 0;\n List | rock | NORMAL | 2019-03-31T04:30:38.062831+00:00 | 2022-02-28T18:58:20.309831+00:00 | 5,261 | false | Since A includes only `0s` and `1s`, we can imitate binary operations.\n\n```java\n public List<Boolean> prefixesDivBy5(int[] A) {\n int k = 0;\n List<Boolean> ans = new ArrayList<>();\n for (int a : A) {\n k = (k << 1 | a) % 5; // left shift k by 1 bit and plus current element a is t... | 66 | 3 | [] | 10 |
binary-prefix-divisible-by-5 | Java solution with best explanation(don't know why some explanation not concise) | java-solution-with-best-explanationdont-xp36i | Prerequisite\n\nYou need to know how to contruct a number with bits in some numeric representation. \n\nFor example: \n1. Contruct the number from a string in d | 416486188 | NORMAL | 2019-05-21T03:20:34.471163+00:00 | 2020-01-08T21:37:34.805515+00:00 | 2,539 | false | **Prerequisite**\n\nYou need to know how to contruct a number with bits in some numeric representation. \n\nFor example: \n1. Contruct the number from a string in decimal like `"12345678"`, key: `num = num * 10 + (c - \'0\')` where `c` is the current character.\n2. Contruct the number from a string in binary like `"010... | 54 | 1 | [] | 5 |
binary-prefix-divisible-by-5 | [Python] Calculate Prefix Mod | python-calculate-prefix-mod-by-lee215-1sgk | Solution 1\npy\n def prefixesDivBy5(self, A):\n for i in xrange(1, len(A)):\n A[i] += A[i - 1] * 2 % 5\n return [a % 5 == 0 for a in | lee215 | NORMAL | 2019-03-31T04:03:41.623466+00:00 | 2021-03-29T04:32:25.103402+00:00 | 4,997 | false | # Solution 1\n```py\n def prefixesDivBy5(self, A):\n for i in xrange(1, len(A)):\n A[i] += A[i - 1] * 2 % 5\n return [a % 5 == 0 for a in A]\n```\n`O(1)` space\n```\n def prefixesDivBy5(self, A):\n sums = 0\n for i, a in enumerate(A):\n sums = sums * 2 % 5 + a\n ... | 38 | 5 | [] | 11 |
binary-prefix-divisible-by-5 | C++ 4 lines | c-4-lines-by-votrubac-owmy | Just build your number from the binary string. The only trick here is to track modulo 5, not the actual number, to avoid overflow.\n\nvector<bool> prefixesDivBy | votrubac | NORMAL | 2019-03-31T04:27:50.842973+00:00 | 2019-03-31T04:27:50.843024+00:00 | 3,701 | false | Just build your number from the binary string. The only trick here is to track modulo 5, not the actual number, to avoid overflow.\n```\nvector<bool> prefixesDivBy5(vector<int>& A, vector<bool> a = {}, int num = 0) {\n for (auto i : A) {\n num = (num * 2 + i) % 5;\n a.push_back(!num);\n }\n return a;\n}\n``` | 31 | 2 | [] | 6 |
binary-prefix-divisible-by-5 | Simple method(Java) | simple-methodjava-by-poorvank-087n | When a binary number is appended by 0 , the new remainder can be calculated based on current remainder only.\nremainder = (remainder * 2) % 5;\n\nAnd when a bin | poorvank | NORMAL | 2019-03-31T04:23:55.131992+00:00 | 2019-03-31T04:23:55.132055+00:00 | 1,685 | false | When a binary number is appended by 0 , the new remainder can be calculated based on current remainder only.\nremainder = (remainder * 2) % 5;\n\nAnd when a binary number is appended by 1.\n remainder = (remainder * 2 + 1) % 5;\n \n For example:\n If it is appended by 0 it will become 10 (2 in decimal) means twice of t... | 29 | 3 | [] | 3 |
binary-prefix-divisible-by-5 | C++ and Python simple solution | c-and-python-simple-solution-by-tovam-ltcq | C++ :\n\n\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> res;\n int num;\n \n | TovAm | NORMAL | 2021-10-06T10:25:12.370295+00:00 | 2021-10-06T10:25:12.370484+00:00 | 2,688 | false | **C++ :**\n\n```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> res;\n int num;\n \n for(int i = 0; i < nums.size(); ++i)\n {\n num = (num * 2 + nums[i]) % 5;\n res.push_back(num == 0);\n }\n ... | 28 | 0 | ['C', 'Python', 'C++', 'Python3'] | 2 |
binary-prefix-divisible-by-5 | Detailed explanation for mod calculation and equation (with super simple Java solution) | detailed-explanation-for-mod-calculation-gm4s | Java solution\n\njava\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> result = new ArrayList<>();\n int r = | phoenixpan | NORMAL | 2019-04-02T00:32:22.054228+00:00 | 2019-04-02T00:32:22.054270+00:00 | 757 | false | **Java solution**\n\n```java\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> result = new ArrayList<>();\n int r = 0;\n for (int bit : A) {\n r = (r * 2 + bit) % 5;\n result.add(r % 5 == 0);\n }\n return result;\n }\n}\n``... | 14 | 0 | [] | 1 |
binary-prefix-divisible-by-5 | [Java] 100% Runtime easy just 1 iteration | java-100-runtime-easy-just-1-iteration-b-uw5e | \n\nUPVOTE IF YOU FIND IT USEFUL\n\n\n\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> list = new ArrayList<>();\n | pulkitswami7 | NORMAL | 2020-09-05T07:06:12.250363+00:00 | 2020-09-05T07:06:12.250424+00:00 | 451 | false | <hr>\n\n***UPVOTE IF YOU FIND IT USEFUL***\n<hr>\n\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> list = new ArrayList<>();\n \n int val = 0;\n for(int i=0;i<A.length;i++){\n val = val * 2 + A[i];\n \n if((val %= 5)... | 9 | 0 | [] | 2 |
binary-prefix-divisible-by-5 | Simple Java Solution With Explanation | simple-java-solution-with-explanation-by-bxgn | Idea\ncurr keeping track of decimal representation so far. When scanning from right, if we multiply curr by 2, it will shift all the bits in curr to left to mak | naveen_kothamasu | NORMAL | 2019-03-31T05:00:40.870081+00:00 | 2019-03-31T05:00:40.870116+00:00 | 608 | false | **Idea**\n`curr` keeping track of decimal representation so far. When scanning from right, if we multiply `curr` by 2, it will shift all the bits in `curr` to left to make place for the incoming digit `i`. That way, we are reusing the computations. We are not interested in the actual number, so to avoid overflow, we ca... | 8 | 2 | [] | 3 |
binary-prefix-divisible-by-5 | [Java] 2ms, 100% + math theory | java-2ms-100-math-theory-by-stefanelstan-0oyk | \nclass Solution {\n /** Algorithm/Theory\n 1. In order to determine if a binary is divisible by 5, we have to build the 10 base & check\n 2. A | StefanelStan | NORMAL | 2022-05-27T15:11:31.969295+00:00 | 2022-05-27T15:11:31.969334+00:00 | 997 | false | ```\nclass Solution {\n /** Algorithm/Theory\n 1. In order to determine if a binary is divisible by 5, we have to build the 10 base & check\n 2. As the problem states, there will be a stream of bits, 1 and 0 that will build n numbers\n In order to build the next number, start with a value of ... | 7 | 0 | ['Java'] | 1 |
binary-prefix-divisible-by-5 | Python3 using yield | python3-using-yield-by-wingsoflight2003-w0fy | \nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n x = 0\n for i in range(len(A)):\n x = x*2+A[i]\n | wingsoflight2003 | NORMAL | 2020-02-10T15:23:15.525592+00:00 | 2020-02-10T15:23:15.525784+00:00 | 526 | false | ```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n x = 0\n for i in range(len(A)):\n x = x*2+A[i]\n yield x%5==0\n``` | 7 | 0 | ['Python3'] | 2 |
binary-prefix-divisible-by-5 | [C++] Simple Solution | c-simple-solution-by-pankajgupta20-ty24 | \tclass Solution {\n\tpublic:\n\t\tvector prefixesDivBy5(vector& nums) {\n\t\t\tvector res;\n\t\t\tint t = 0;\n\t\t\tfor(int i = 0; i < nums.size(); i++){\n\t\t | pankajgupta20 | NORMAL | 2021-05-31T11:58:04.882830+00:00 | 2021-05-31T11:58:04.882875+00:00 | 700 | false | \tclass Solution {\n\tpublic:\n\t\tvector<bool> prefixesDivBy5(vector<int>& nums) {\n\t\t\tvector<bool> res;\n\t\t\tint t = 0;\n\t\t\tfor(int i = 0; i < nums.size(); i++){\n\t\t\t\tt = (t * 2 + nums[i]) % 5;\n\t\t\t\tres.push_back(t == 0);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}; | 5 | 0 | ['C', 'C++'] | 2 |
binary-prefix-divisible-by-5 | 1018 | JavaScript 1 Line Solution | 1018-javascript-1-line-solution-by-spork-1vwz | Runtime: 72 ms, faster than 59.00% of JavaScript online submissions\n> Memory Usage: 38.2 MB, less than 92.31% of JavaScript online submissions\n\nNot the faste | sporkyy | NORMAL | 2019-08-12T15:06:54.475362+00:00 | 2021-08-31T13:44:28.390736+00:00 | 727 | false | > Runtime: **72 ms**, faster than *59.00%* of JavaScript online submissions\n> Memory Usage: **38.2 MB**, less than *92.31%* of JavaScript online submissions\n\nNot the fastest.\n\n```\n/**\n * @param {number[]} A\n * @param {number} acc\n * @return {boolean[]}\n */\nconst prefixesDivBy5 = (A, acc = 0) => A.map(d => !(... | 5 | 0 | ['JavaScript'] | 1 |
binary-prefix-divisible-by-5 | A couple of different solutions in Python | a-couple-of-different-solutions-in-pytho-13tk | Here is the first solution:\n\npython\nclass Solution:\n def prefixesDivBy5(self, A):\n result = []\n number = 0\n for bit in A:\n | lxnn | NORMAL | 2019-07-14T11:52:29.299869+00:00 | 2019-07-14T14:23:55.380058+00:00 | 417 | false | Here is the first solution:\n\n```python\nclass Solution:\n def prefixesDivBy5(self, A):\n result = []\n number = 0\n for bit in A:\n number = 2*number + bit\n result.append(number % 5 == 0)\n return result\n```\n\nThe idea is simple: we accumulate the bits into a bi... | 5 | 0 | [] | 2 |
binary-prefix-divisible-by-5 | Easy Solution | easy-solution-by-algoartisan-q7j6 | \nvector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool>v;\n \n int sum=0;\n \n for(auto x : nums){\n | AlgoArtisan | NORMAL | 2022-09-10T21:24:43.254888+00:00 | 2022-09-10T21:24:43.254926+00:00 | 921 | false | ```\nvector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool>v;\n \n int sum=0;\n \n for(auto x : nums){\n \n sum=(sum*2+x)%5;\n \n v.push_back(sum==0);\n }\n \n return v;\n }\n``` | 4 | 0 | ['C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Java Solution with Explanation, faster than 100.00% | java-solution-with-explanation-faster-th-fngb | \nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n int sum = 0;\n int length = nums.length;\n List<Boolean> result | kingston880420 | NORMAL | 2021-05-29T04:04:49.546906+00:00 | 2021-05-29T04:04:49.546937+00:00 | 500 | false | ```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n int sum = 0;\n int length = nums.length;\n List<Boolean> result = new ArrayList<>();\n //Go through the nums notice that shifting a binary number to the left is equals to multiplying a decimal number by 2\n ... | 4 | 0 | ['Java'] | 2 |
binary-prefix-divisible-by-5 | Python | Fast > 99% | python-fast-99-by-ddhnnng-feri | \nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n answer = [None] * len(A)\n S = 0\n for idx, i in enumerate(A | ddhnnng | NORMAL | 2021-03-12T21:32:16.498000+00:00 | 2021-03-12T21:33:45.078709+00:00 | 290 | false | ```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n answer = [None] * len(A)\n S = 0\n for idx, i in enumerate(A):\n S <<= 1 # bit shift left\n S += i # add new least-sig bit\n S %= 5... | 4 | 0 | ['Python'] | 0 |
binary-prefix-divisible-by-5 | Python O(n) use <<= to solve | python-on-use-to-solve-by-abandonblue101-6g1g | \ndef prefixesDivBy5(self, A: List[int]) -> List[bool]:\n \n cum = 0\n ans = []\n \n for i in range(len(A)):\n cum | abandonblue1015 | NORMAL | 2020-07-23T12:31:40.496490+00:00 | 2020-07-23T12:31:40.496519+00:00 | 143 | false | ```\ndef prefixesDivBy5(self, A: List[int]) -> List[bool]:\n \n cum = 0\n ans = []\n \n for i in range(len(A)):\n cum <<= 1 # based on binary\n cum += (A[i])\n if cum % 5 == 0:\n ans.append(True)\n else:\n ans... | 4 | 0 | ['Python3'] | 1 |
binary-prefix-divisible-by-5 | Solution in Python 3 (beats ~98%) (three lines) ( O(1) space ) | solution-in-python-3-beats-98-three-line-lo0c | ```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n \tn = 0\n \tfor i in range(len(A)): A[i], n = (2n + A[i]) % 5 == 0, (2n | junaidmansuri | NORMAL | 2019-08-11T14:45:13.659533+00:00 | 2019-08-11T14:46:09.491418+00:00 | 474 | false | ```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n \tn = 0\n \tfor i in range(len(A)): A[i], n = (2*n + A[i]) % 5 == 0, (2*n + A[i]) % 5\n \treturn A\n\t\t\n\t\t\n- Junaid Mansuri\n(LeetCode ID)@hotmail.com | 4 | 1 | ['Python', 'Python3'] | 1 |
binary-prefix-divisible-by-5 | 🔥VERY SIMPLE || JAVA || BEATS 99.11% 🔥 | very-simple-java-beats-9911-by-tamilselv-ilf1 | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n) \n# Code\n\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n L | Tamilselvan_Srini | NORMAL | 2024-01-05T10:14:16.904827+00:00 | 2024-01-05T10:20:29.227185+00:00 | 680 | false | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$ \n# Code\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n List<Boolean>list=new ArrayList<>();\n int sum=0;\n for(int i=0;i<nums.length;i++)\n {\n sum = (sum * 2 + nums[i]) ... | 3 | 0 | ['Array', 'Java'] | 1 |
binary-prefix-divisible-by-5 | || Easy Solution || DFA || | easy-solution-dfa-by-leetcode_ashutosh-yscp | Intuition\nUsing Deterministic Finite Automata \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nConstant\n\n# Code\n\nclass Solution {\n pu | leetcode_Ashutosh | NORMAL | 2023-07-19T18:10:48.648386+00:00 | 2023-10-16T15:03:46.150974+00:00 | 173 | false | # Intuition\nUsing Deterministic Finite Automata \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nConstant\n\n# Code\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n List<Boolean> res = new ArrayList<>();\n int daigram[][] ={{0,1},{2,3},{4,0},{1,2},{3,4}};\... | 3 | 0 | ['Math', 'Brainteaser', 'C++', 'Java', 'Python3'] | 1 |
binary-prefix-divisible-by-5 | Java, C++, Python | 🚀 A pinch of math in 7 lines explained | java-c-python-a-pinch-of-math-in-7-lines-v8ec | \u26A0\uFE0F Disclaimer: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe tas | wallandteen | NORMAL | 2023-05-04T21:16:18.902431+00:00 | 2023-05-09T04:46:05.358313+00:00 | 824 | false | > \u26A0\uFE0F **Disclaimer**: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe task requires us to check whether the binary prefix of each number in an array is divisible by 5. We need to return a boolean array where each index correspo... | 3 | 0 | ['C++', 'Java', 'Python3'] | 0 |
binary-prefix-divisible-by-5 | With Explanation Comments: Time: 3 ms (100.00%), Space: 14 MB (46.11%) | with-explanation-comments-time-3-ms-1000-f2i3 | Like it? ->Upvote please! \u30C4\n\n\'\'\'\nclass Solution {\npublic:\n vector prefixesDivBy5(vector& nums) {\n \n //initialize a new vector wi | deleted_user | NORMAL | 2022-09-05T19:56:24.177570+00:00 | 2022-09-08T18:53:35.197734+00:00 | 343 | false | **Like it? ->Upvote please!** \u30C4\n\n\'\'\'\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n //initialize a new vector with boolean values\n vector<bool> res;\n int num=0;\n \n //loop over the whole array numbers\n for(int i=0;i<nu... | 3 | 0 | ['Array', 'C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | C++|| EASY TO UNDERSTAND || fast and efficient | c-easy-to-understand-fast-and-efficient-pdtdg | \nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n int n=nums.size();\n vector<bool> vec;\n int num=0; \n f | aarindey | NORMAL | 2021-10-19T22:09:13.610677+00:00 | 2021-10-19T22:12:29.091601+00:00 | 184 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n int n=nums.size();\n vector<bool> vec;\n int num=0; \n for(int i=0;i<n;i++)\n {\n num=(num*2+nums[i])%10;\n vec.push_back(num%5==0);\n }\n return vec;\n }\n};\n```\n**Please upvote ... | 3 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | C++ || Fast and Easy Method | c-fast-and-easy-method-by-suniti0804-hzdi | \n vector prefixesDivBy5(vector& A) \n {\n vector res;\n int n = A.size();\n \n int num = 0;\n \n for(int i = 0; | suniti0804 | NORMAL | 2021-04-13T14:49:18.587362+00:00 | 2021-04-14T17:37:57.121093+00:00 | 271 | false | \n vector<bool> prefixesDivBy5(vector<int>& A) \n {\n vector<bool> res;\n int n = A.size();\n \n int num = 0;\n \n for(int i = 0; i < n; i++)\n {\n num = num * 2 + A[i];\n if(num % 5 == 0)\n res.push_back(true);\n els... | 3 | 0 | ['C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Java 100% fast, simple | java-100-fast-simple-by-umedjan-0f75 | \nclass Solution {\n\tpublic List<Boolean> prefixesDivBy5(int[] A) {\n\t\tList<Boolean> result = new ArrayList<>(A.length);\n\t\tint s = 0;\n\t\tfor (int i : A) | umedjan | NORMAL | 2021-02-10T09:53:27.520991+00:00 | 2021-02-10T09:53:27.521022+00:00 | 383 | false | ```\nclass Solution {\n\tpublic List<Boolean> prefixesDivBy5(int[] A) {\n\t\tList<Boolean> result = new ArrayList<>(A.length);\n\t\tint s = 0;\n\t\tfor (int i : A)\n\t\t\tresult.add((s = (s * 2 + i) % 5) == 0);\n\n\t\treturn result;\n\t}\n}\n``` | 3 | 0 | ['Java'] | 3 |
binary-prefix-divisible-by-5 | C++ 12ms 100% Fast | c-12ms-100-fast-by-kumaranuj1303-u9fr | \nvector<bool> prefixesDivBy5(vector<int>& A) \n {\n int size = A.size();\n vector<bool> B(size);\n for (auto i = 1; i < size; i++)\n | kumaranuj1303 | NORMAL | 2020-10-20T13:10:42.541165+00:00 | 2020-10-20T13:10:42.541205+00:00 | 219 | false | ```\nvector<bool> prefixesDivBy5(vector<int>& A) \n {\n int size = A.size();\n vector<bool> B(size);\n for (auto i = 1; i < size; i++)\n {\n A[i] = (A[i] + A[i-1] * 2) % 10;\n if (A[i] % 5)\n B[i] = 0;\n else\n B[i] = 1;\n ... | 3 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | [Java] Simple bit shifting | O(n) time, O(1) space | java-simple-bit-shifting-on-time-o1-spac-ijo7 | ```\nclass Solution {\n public List prefixesDivBy5(int[] A) {\n \n List result = new ArrayList<>(A.length);\n int num = 0;\n for(i | mdshahnawaz459 | NORMAL | 2020-09-08T12:20:28.273713+00:00 | 2020-09-08T12:23:28.173775+00:00 | 278 | false | ```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n \n List<Boolean> result = new ArrayList<>(A.length);\n int num = 0;\n for(int i = 0; i < A.length; i++) {\n num <<= 1;\n num |= A[i];\n result.add((num = (num % 5)) == 0 ? true: false)... | 3 | 0 | ['Bit Manipulation', 'Java'] | 0 |
binary-prefix-divisible-by-5 | Javascript simple solution with explanation | javascript-simple-solution-with-explanat-3yjk | \nvar prefixesDivBy5 = function (A) {\n let stv = 0;\n return A.map((bit) => {\n stv = stv * 2 + bit;\n\t//adding 1 binary bit means whether the number get | leomacode | NORMAL | 2020-08-25T18:37:01.540257+00:00 | 2020-08-25T18:40:52.686430+00:00 | 453 | false | ```\nvar prefixesDivBy5 = function (A) {\n let stv = 0;\n return A.map((bit) => {\n stv = stv * 2 + bit;\n\t//adding 1 binary bit means whether the number gets doubled (if add 0) or gets doubled and plus 1 (if add 1)\n\t//Example: decimal 2 is 10 in binary. If add 0 in binary: 10 will be 100 which is 4 in decimal ... | 3 | 0 | ['JavaScript'] | 0 |
binary-prefix-divisible-by-5 | Python Simple solution | python-simple-solution-by-lokeshsk1-7og0 | \nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n s=\'\';l=[]\n for i in A:\n s+=str(i)\n l.app | lokeshsk1 | NORMAL | 2020-08-14T08:52:44.943453+00:00 | 2020-08-14T10:25:28.688260+00:00 | 412 | false | ```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n s=\'\';l=[]\n for i in A:\n s+=str(i)\n l.append(int(s,2)%5==0)\n return l\n \n``` | 3 | 0 | ['Python', 'Python3'] | 0 |
binary-prefix-divisible-by-5 | C++ solution | c-solution-by-oleksam-u7wm | \nvector<bool> prefixesDivBy5(vector<int>& A) {\n\tint iCurr = 0;\n\tvector<bool> vRes;\n\tfor (auto n : A) {\n\t\tiCurr = (iCurr << 1) | n;\n\t\tvRes.push_back | oleksam | NORMAL | 2020-06-30T12:49:06.506140+00:00 | 2020-06-30T12:49:06.506173+00:00 | 414 | false | ```\nvector<bool> prefixesDivBy5(vector<int>& A) {\n\tint iCurr = 0;\n\tvector<bool> vRes;\n\tfor (auto n : A) {\n\t\tiCurr = (iCurr << 1) | n;\n\t\tvRes.push_back(iCurr % 5 == 0);\n\t\tiCurr %= 10;\n\t}\n\treturn vRes;\n}\n```\n | 3 | 0 | ['C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | JAVA Solution with a Trick to prevent Overflow | java-solution-with-a-trick-to-prevent-ov-7m3z | \npublic List<Boolean> prefixesDivBy5(int[] A) {\n\tint currentNum = 0;\n\tList<Boolean> sol = new ArrayList<>();\n\tfor(int a : A) {\n\t\t// (a * b + c) % d = | anubhavjindal | NORMAL | 2019-11-16T06:21:50.433788+00:00 | 2019-11-16T06:21:50.433845+00:00 | 227 | false | ```\npublic List<Boolean> prefixesDivBy5(int[] A) {\n\tint currentNum = 0;\n\tList<Boolean> sol = new ArrayList<>();\n\tfor(int a : A) {\n\t\t// (a * b + c) % d = ((a % d) * (b % d) + c % d) % d\n\t\tcurrentNum = (currentNum << 1 | a)%5;\n\t\tsol.add(currentNum==0);\n\t}\n\treturn sol;\n}\n``` | 3 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Simple, C++ Solution [beats 98%, 100%] | simple-c-solution-beats-98-100-by-pooja0-y5hc | Runtime: 8 ms, faster than 98.57% of C++ online submissions for Binary Prefix Divisible By 5.\nMemory Usage: 10.6 MB, less than 100.00% of C++ online submission | pooja0406 | NORMAL | 2019-09-01T08:18:45.228178+00:00 | 2019-09-01T08:18:45.228210+00:00 | 477 | false | Runtime: 8 ms, faster than 98.57% of C++ online submissions for Binary Prefix Divisible By 5.\nMemory Usage: 10.6 MB, less than 100.00% of C++ online submissions for Binary Prefix Divisible By 5.\n\n```\n vector<bool> prefixesDivBy5(vector<int>& A) {\n \n vector<bool> res;\n int n = A.size();\n ... | 3 | 0 | ['C++'] | 1 |
binary-prefix-divisible-by-5 | C solution with DFA; general purpose | c-solution-with-dfa-general-purpose-by-j-kwo7 | A general purpose solution written in C with DFA:\n\nc\nbool* prefixesDivBy5(int* A, int ASize, int* returnSize){\n *returnSize = ASize;\n bool *res = (bo | jules3in | NORMAL | 2019-08-07T05:18:03.682804+00:00 | 2019-08-07T05:18:03.682840+00:00 | 234 | false | A general purpose solution written in C with DFA:\n\n```c\nbool* prefixesDivBy5(int* A, int ASize, int* returnSize){\n *returnSize = ASize;\n bool *res = (bool *)malloc(ASize * sizeof(bool));\n\n int q0 = 0, q1 = 1, q2 = 2, q3 = 3, q4 = 4;\n int DFA[5][2] = { {q0, q1}, {q2, q3}, {q4, q0}, {q1, q2}, {q3, q4}... | 3 | 0 | ['C'] | 0 |
binary-prefix-divisible-by-5 | Python Solution - Bit shift with mod check | python-solution-bit-shift-with-mod-check-vyky | Each time you look you add a bit, you are multiplying the previous sum by 2 and adding the value of the current bit. This can be achieved by a simple left bit s | raosrika89 | NORMAL | 2019-05-26T18:47:06.274556+00:00 | 2019-05-26T19:44:47.826249+00:00 | 320 | false | Each time you look you add a bit, you are multiplying the previous sum by 2 and adding the value of the current bit. This can be achieved by a simple left bit shift by 1. \n\nIt is then just a matter of checking if the total is divisible by 5 or not. \n\n```\nclass Solution:\n \n def prefixesDivBy5(self, A: List... | 3 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | JavaScript Solution, Straight forward | javascript-solution-straight-forward-by-kmlzs | javascript\\\nvar prefixesDivBy5 = function(A) {\n let cur = 0;\n const r = []\n for (const a of A) {\n cur = ((cur << 1) | a) % 5;\n r.p | ruinan | NORMAL | 2019-04-21T05:19:31.000013+00:00 | 2019-04-21T05:19:31.000181+00:00 | 282 | false | ```javascript\\\nvar prefixesDivBy5 = function(A) {\n let cur = 0;\n const r = []\n for (const a of A) {\n cur = ((cur << 1) | a) % 5;\n r.push(cur === 0);\n }\n return r;\n};\n``` | 3 | 0 | [] | 1 |
binary-prefix-divisible-by-5 | 个人觉得很好理解的java解法 | ge-ren-jue-de-hen-hao-li-jie-de-javajie-5313z | \nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> result = new ArrayList<>();\n int current = 0;\n for | zhf123 | NORMAL | 2019-04-17T02:50:20.007613+00:00 | 2019-04-17T02:50:20.007656+00:00 | 248 | false | ```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> result = new ArrayList<>();\n int current = 0;\n for (int i:A){\n current = (current*2+i)%10;\n result.add(current%5==0);\n }\n return result;\n}\n}``\n``` | 3 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Java, simple 3 lines, no modulo | java-simple-3-lines-no-modulo-by-jpv-kvmb | I see lots of solutions using %, which is an expensive operation. If you have something between 0 and 4, then double it and add 0 or 1, your result is between | jpv | NORMAL | 2019-03-31T13:49:57.440502+00:00 | 2019-03-31T13:49:57.440544+00:00 | 355 | false | I see lots of solutions using %, which is an expensive operation. If you have something between 0 and 4, then double it and add 0 or 1, your result is between 0 and 9. Just subtracting 5 if needed is cheaper/faster than using modulo.\n```\n public List<Boolean> prefixesDivBy5(int[] A) {\n List<Boolean> ans ... | 3 | 2 | [] | 1 |
binary-prefix-divisible-by-5 | Simple and Easy Java Solution || Beats 99% || With intuition and approach | simple-and-easy-java-solution-beats-99-w-myjn | 🔍 Intuition:
The given binary array represents a number whose digits are read sequentially.
We need to check if the number formed by the prefix (from index0toi) | Yashvendra | NORMAL | 2025-02-18T17:45:39.448830+00:00 | 2025-02-18T17:45:39.448830+00:00 | 157 | false | ## 🔍 Intuition:
- The given binary array represents a number whose digits are read sequentially.
- We need to check if the number formed by the prefix (from index `0` to `i`) is divisible by `5`.
- Instead of converting the entire prefix into an integer (which may cause overflow for large inputs), we can maintain the ... | 2 | 0 | ['Array', 'Bit Manipulation', 'Java'] | 0 |
binary-prefix-divisible-by-5 | python solution | python-solution-by-bhavanabharatisingh-ybrv | Intuitionconvert it into numeric value and check the visibilityComplexity
Time complexity:
O(n)
Space complexity:
O(n)Code | bhavanabharatisingh | NORMAL | 2024-12-22T12:20:04.859431+00:00 | 2024-12-22T12:20:04.859431+00:00 | 182 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
convert it into numeric value and check the visibility
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)
# Code
```p... | 2 | 0 | ['Python3'] | 0 |
binary-prefix-divisible-by-5 | Two Solutions | Bit Manipulation & DFA | Both O(n) | two-solutions-bit-manipulation-dfa-both-fy95r | Solution 1 | Bit Manipulation:\n## Intuition\n\nWith each new bit, we can determine the new remainder by left-shifting the new bit onto the existing remainder a | SquirtleHerder | NORMAL | 2024-02-23T22:22:53.859215+00:00 | 2024-04-13T04:44:12.891124+00:00 | 631 | false | # Solution 1 | Bit Manipulation:\n## Intuition\n\nWith each new bit, we can determine the new remainder by left-shifting the new bit onto the existing remainder and then computing the modulo of the resultant value. \n\nThis approach ensures that the length of the resulting value would remain at most 4 bits vs other bit... | 2 | 0 | ['Bit Manipulation', 'C', 'Simulation', 'C++', 'Python3'] | 0 |
binary-prefix-divisible-by-5 | Solution | solution-by-deleted_user-n77d | C++ []\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> r;\n int n=0;\n for(int b : nums){\n | deleted_user | NORMAL | 2023-05-21T07:25:16.874924+00:00 | 2023-05-21T07:49:00.002614+00:00 | 712 | false | ```C++ []\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> r;\n int n=0;\n for(int b : nums){\n n = ((n<<1) | b) % 5;\n r.push_back(n==0);\n }\n return r;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def pr... | 2 | 0 | ['C++', 'Java', 'Python3'] | 0 |
binary-prefix-divisible-by-5 | Java && JavaScript Solution does not need to convert anything | java-javascript-solution-does-not-need-t-mncq | There are many solutions for solving this problem and most of them are awesome. This solution based on that and just modified it to easier and cleaner\n=> Here | tonybuidn | NORMAL | 2022-11-26T06:16:58.187901+00:00 | 2023-02-26T15:26:01.924719+00:00 | 713 | false | There are many solutions for solving this problem and most of them are awesome. This solution based on that and just modified it to easier and cleaner\n=> Here using loop enhancement instead original loop => because we always to get the value for each index start the first to the end of the array.\n=> so we use loop en... | 2 | 0 | ['Java'] | 1 |
binary-prefix-divisible-by-5 | C++ || easy and efficient | c-easy-and-efficient-by-prakhar_20-i3xo | \nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> v1;\n int sum=0;\n for(int i=0;i | prakhar_20 | NORMAL | 2022-09-01T19:12:26.420036+00:00 | 2022-09-01T19:12:26.420077+00:00 | 580 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> v1;\n int sum=0;\n for(int i=0;i<nums.size();i++)\n { \n sum+=nums[i]; //to check for each element\n sum*=2; // to conve... | 2 | 0 | ['C++'] | 1 |
binary-prefix-divisible-by-5 | Least Runtime Solution | least-runtime-solution-by-day_tripper-06m3 | \nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n c,l=0,[]\n for i in nums:\n c=(c*2+i)%5\n | Day_Tripper | NORMAL | 2022-07-19T09:39:49.620194+00:00 | 2022-07-19T09:39:49.620231+00:00 | 159 | false | ```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n c,l=0,[]\n for i in nums:\n c=(c*2+i)%5\n l.append(c==0)\n return l\n``` | 2 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | 𝗗𝗲𝘁𝗮𝗶𝗹𝗲𝗱 𝗘𝘅𝗽𝗹𝗮𝗻𝗮𝘁𝗶𝗼𝗻 | Python | C | 𝗢(𝗻) | DFA | Theory | Thought Process | detailed-explanation-python-c-on-dfa-the-gp10 | \u2714 \uD835\uDDD7\uD835\uDDD8\uD835\uDDE7\uD835\uDDD4\uD835\uDDDC\uD835\uDDDF\uD835\uDDD8\uD835\uDDD7 \uD835\uDDD8\uD835\uDDEB\uD835\uDDE3\uD835\uDDDF\uD835\u | RohitSgh | NORMAL | 2022-06-02T01:50:35.934185+00:00 | 2023-01-10T20:39:42.305959+00:00 | 377 | false | # \u2714 \uD835\uDDD7\uD835\uDDD8\uD835\uDDE7\uD835\uDDD4\uD835\uDDDC\uD835\uDDDF\uD835\uDDD8\uD835\uDDD7 \uD835\uDDD8\uD835\uDDEB\uD835\uDDE3\uD835\uDDDF\uD835\uDDD4\uD835\uDDE1\uD835\uDDD4\uD835\uDDE7\uD835\uDDDC\uD835\uDDE2\uD835\uDDE1 \n\nThis **Solution** will use the concept of **Finite Automaton**, and is simila... | 2 | 0 | ['C', 'Python'] | 0 |
binary-prefix-divisible-by-5 | Simple C++ Solution | simple-c-solution-by-nikhilgupta25-spd6 | \nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool>ans;\n int dec=0;\n for(int i=0;i<nums.size | NikhilGupta25 | NORMAL | 2022-04-14T10:30:42.975446+00:00 | 2022-04-14T10:30:42.975486+00:00 | 332 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool>ans;\n int dec=0;\n for(int i=0;i<nums.size();i++){\n dec = dec * 2 + nums[i];\n if(dec%5==0){\n ans.push_back(true);\n }\n else{\n ... | 2 | 0 | ['C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Easy Python code for beginners | easy-python-code-for-beginners-by-vistri-elgf | \ndef prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n l=[]\n su=""\n for i in nums:\n su+=str(i)\n if int(su,2 | vistrit | NORMAL | 2021-11-24T07:23:06.602663+00:00 | 2021-11-24T07:23:06.602699+00:00 | 195 | false | ```\ndef prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n l=[]\n su=""\n for i in nums:\n su+=str(i)\n if int(su,2)%5==0:\n l.append(True)\n else:\n l.append(False)\n return l\n``` | 2 | 0 | ['Python', 'Python3'] | 0 |
binary-prefix-divisible-by-5 | Java O(n) solution with explaination | java-on-solution-with-explaination-by-ak-1jr0 | \n\n/* \n * First thing first, note that by adding a zero bit digit to any binary\n * number, we get a new binary number that represent double of the original b | aknuclear | NORMAL | 2021-06-12T03:43:20.411419+00:00 | 2021-06-12T03:43:33.765006+00:00 | 132 | false | ```\n\n/* \n * First thing first, note that by adding a zero bit digit to any binary\n * number, we get a new binary number that represent double of the original binary value.\n * Similarly, adding a 1 bit digit yields original value * 2 + 1.\n * So we can walk the binary array nums from left to right,\n * starting fro... | 2 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Python3 simple solution | python3-simple-solution-by-eklavyajoshi-lnvl | \nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n res = []\n n = 0\n for i in nums:\n n *= 2\n | EklavyaJoshi | NORMAL | 2021-05-26T03:36:50.010714+00:00 | 2021-05-26T03:36:50.010749+00:00 | 96 | false | ```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n res = []\n n = 0\n for i in nums:\n n *= 2\n if i == 1:\n n += 1\n res.append(n % 5 == 0)\n return res\n```\n**If you like this solution, please upvote for thi... | 2 | 0 | ['Python3'] | 0 |
binary-prefix-divisible-by-5 | Java solution with given hint | java-solution-with-given-hint-by-ayansam-m7d7 | class Solution {\n\n\n public List prefixesDivBy5(int[] a) {\n List l = new ArrayList<>();\n long num = a[0];\n l.add(num%5 == 0?true:fa | ayansam | NORMAL | 2021-04-22T08:11:30.521418+00:00 | 2021-04-22T08:11:30.521471+00:00 | 100 | false | class Solution {\n\n\n public List<Boolean> prefixesDivBy5(int[] a) {\n List<Boolean> l = new ArrayList<>();\n long num = a[0];\n l.add(num%5 == 0?true:false);\n for(int i=1;i<a.length;i++){\n num = 2*num +a[i];\n l.add(num%5 == 0?true:false);\n num = num%... | 2 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | java-solution | java-solution-by-meteor18-talj | \nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n int temp = 0;\n List<Boolean> result = new ArrayList<Boolean>(A.length);\ | meteor18 | NORMAL | 2019-12-27T02:58:47.958033+00:00 | 2019-12-27T02:58:47.958070+00:00 | 190 | false | ```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] A) {\n int temp = 0;\n List<Boolean> result = new ArrayList<Boolean>(A.length);\n for (int i = 0; i < A.length; i++) {\n temp = (temp * 2 + A[i]) % 5;\n if (temp == 0)\n result.add(i, Boolean.T... | 2 | 0 | ['Java'] | 1 |
binary-prefix-divisible-by-5 | [JavaScript] Beats 100% Time and Memory | javascript-beats-100-time-and-memory-by-2jw93 | Bit shift only to least significant digit to avoid overflow. Current number is divisible by 5 if LSD is 0 or 5.\n\njavascript\nvar prefixesDivBy5 = function(A) | ethan-marsh | NORMAL | 2019-09-27T04:09:33.993199+00:00 | 2019-09-27T04:09:33.993242+00:00 | 373 | false | Bit shift only to least significant digit to avoid overflow. Current number is divisible by 5 if LSD is 0 or 5.\n\n```javascript\nvar prefixesDivBy5 = function(A) {\n let lsd = 0;\n return A.map((bit) => {\n lsd <<= 1;\n lsd += bit;\n lsd %= 10;\n return lsd === 0 || lsd === 5;\n });\n};\n``` | 2 | 1 | ['JavaScript'] | 1 |
binary-prefix-divisible-by-5 | Go golang solution | go-golang-solution-by-leaf_peng-nvhb | Runtime: 332 ms, faster than 71.93% of Go online submissions for Binary Prefix Divisible By 5.\nMemory Usage: 8.2 MB, less than 40.00% of Go online submissions | leaf_peng | NORMAL | 2019-09-22T02:28:27.270286+00:00 | 2019-09-22T02:28:27.270335+00:00 | 88 | false | >Runtime: 332 ms, faster than 71.93% of Go online submissions for Binary Prefix Divisible By 5.\nMemory Usage: 8.2 MB, less than 40.00% of Go online submissions for Binary Prefix Divisible By 5.\n\n```go\nfunc prefixesDivBy5(A []int) []bool {\n\n\tans := []bool{}\n\tn := 0\n\n\tfor _, v := range A {\n\t\tn = (n<<1 + v)... | 2 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | javascript | javascript-by-huihancarl188-a9fv | \nvar prefixesDivBy5 = function(A) {\n // i => current binary number;\n let cur = 0;\n let res = [];\n for(let i = 0 ; i < A.length; i++) {\n | huihancarl188 | NORMAL | 2019-05-26T04:28:19.159410+00:00 | 2019-05-26T04:28:19.159459+00:00 | 164 | false | ```\nvar prefixesDivBy5 = function(A) {\n // i => current binary number;\n let cur = 0;\n let res = [];\n for(let i = 0 ; i < A.length; i++) {\n cur = cur << 1;\n cur = cur % 5;\n cur += A[i];\n res.push(cur % 5 === 0);\n }\n return res;\n};\n``` | 2 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Weird Javascript Question, can anyone explain? (Solved) | weird-javascript-question-can-anyone-exp-ehug | If I write my code like this\n\nvar prefixesDivBy5 = function(A) {\n let res = [];\n let remainder = 0;\n for(let i=0; i<A.length; i++){\n remai | 0618 | NORMAL | 2019-03-31T14:47:53.906920+00:00 | 2019-03-31T14:47:53.906967+00:00 | 302 | false | If I write my code like this\n```\nvar prefixesDivBy5 = function(A) {\n let res = [];\n let remainder = 0;\n for(let i=0; i<A.length; i++){\n remainder = remainder*2 + A[i];\n res.push(remainder%5===0);\n\t\tif(remainder%5===0) remainder = 0;\n }\n\n return res;\n};\n```\nI can\'t pass test... | 2 | 0 | [] | 2 |
binary-prefix-divisible-by-5 | Python straightforward bit manipulation | python-straightforward-bit-manipulation-0jke7 | On each iteration, num bits shift 1 index to left while least-significant bit is A[i].\n\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bo | cenkay | NORMAL | 2019-03-31T04:27:57.284956+00:00 | 2019-03-31T04:27:57.284989+00:00 | 188 | false | * On each iteration, num bits shift 1 index to left while least-significant bit is A[i].\n```\nclass Solution:\n def prefixesDivBy5(self, A: List[int]) -> List[bool]:\n num = 0\n for i in range(len(A)):\n num = (num << 1) + A[i]\n A[i] = num % 5 == 0\n return A\n```\nTime c... | 2 | 2 | [] | 0 |
binary-prefix-divisible-by-5 | Simple C++ Solution || Beats 100% | simple-c-solution-beats-100-by-devanshv1-ynbn | IntuitionThe problem requires checking whether the binary number formed by each prefix of the given array (nums) is divisible by 5. Instead of constructing larg | Devanshv123 | NORMAL | 2025-03-01T14:26:10.961546+00:00 | 2025-03-01T14:26:10.961546+00:00 | 43 | false | # Intuition
The problem requires checking whether the binary number formed by each prefix of the given array (nums) is divisible by 5. Instead of constructing large numbers explicitly (which could lead to overflow), we can track only the remainder when divided by 5.
<!-- Describe your first thoughts on how to solve thi... | 1 | 0 | ['Array', 'Bit Manipulation', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Simple C++ Solution || Beats 100% | simple-c-solution-beats-100-by-devanshv1-xt6a | IntuitionThe problem requires checking whether the binary number formed by each prefix of the given array (nums) is divisible by 5. Instead of constructing larg | Devanshv123 | NORMAL | 2025-03-01T14:26:07.802732+00:00 | 2025-03-01T14:26:07.802732+00:00 | 30 | false | # Intuition
The problem requires checking whether the binary number formed by each prefix of the given array (nums) is divisible by 5. Instead of constructing large numbers explicitly (which could lead to overflow), we can track only the remainder when divided by 5.
<!-- Describe your first thoughts on how to solve thi... | 1 | 0 | ['Array', 'Bit Manipulation', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Java Solution | java-solution-by-hksuthar12-t6fv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Hksuthar12 | NORMAL | 2025-02-03T12:14:14.144809+00:00 | 2025-02-03T12:14:14.144809+00:00 | 79 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Java'] | 0 |
binary-prefix-divisible-by-5 | EASY SOLUTION IN JAVA BEATING 98.16% IN 3ms | easy-solution-in-java-beating-9816-in-3m-66ac | IntuitionThe problem asks us to determine whether the number represented by the binary subarray nums[0..i] (where i ranges from 0 to n-1) is divisible by 5. The | arshi_bansal | NORMAL | 2025-02-03T06:47:04.671421+00:00 | 2025-02-03T06:47:04.671421+00:00 | 68 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem asks us to determine whether the number represented by the binary subarray nums[0..i] (where i ranges from 0 to n-1) is divisible by 5. The binary number formed from nums[0..i] is built progressively as we move through the array... | 1 | 0 | ['Array', 'Bit Manipulation', 'Java'] | 0 |
binary-prefix-divisible-by-5 | O(n) | on-by-bhavanabharatisingh-w2fh | Intuition\n Describe your first thoughts on how to solve this problem. \nTake each number from the array nums and convert into decimal and check its divisiabli | bhavanabharatisingh | NORMAL | 2024-10-01T04:15:54.151698+00:00 | 2024-10-01T04:15:54.151730+00:00 | 33 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake each number from the array nums and convert into decimal and check its divisiablity with 5\n \n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n- O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n... | 1 | 0 | ['Python3'] | 0 |
binary-prefix-divisible-by-5 | easy-peasy solution | O(n) time complexity | easy-peasy-solution-on-time-complexity-b-vgie | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | ilovevectors | NORMAL | 2024-09-09T18:48:01.472457+00:00 | 2024-09-09T18:48:01.472495+00:00 | 274 | false | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> ret;\n int x... | 1 | 0 | ['C++'] | 0 |
binary-prefix-divisible-by-5 | EASY SOLUTION USING ONLY ONE WHILE LOOP IN C++ | easy-solution-using-only-one-while-loop-7gi5b | 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 | vasu049 | NORMAL | 2024-08-23T16:26:56.841103+00:00 | 2024-08-23T16:26:56.841133+00:00 | 20 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
binary-prefix-divisible-by-5 | Python Easy Approach | python-easy-approach-by-_ss_official_006-sgon | Code\n\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n Integer=[]\n output=[]\n Final=[]\n for i in | _ss_official_006 | NORMAL | 2024-08-10T08:17:56.846253+00:00 | 2024-08-10T08:17:56.846278+00:00 | 168 | false | # Code\n```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n Integer=[]\n output=[]\n Final=[]\n for i in nums:\n Integer.append(str(i))\n for i in range(len(Integer)):\n output.append(int("".join(Integer[:i+1]),2))\n for i ... | 1 | 0 | ['Array', 'Bit Manipulation', 'Python3'] | 1 |
binary-prefix-divisible-by-5 | Simple java code for beginners | simple-java-code-for-beginners-by-arobh-o0yc | \n# Complexity\n- \n\n# Code\n\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n ArrayList<Boolean> ans = new ArrayList<>();\n | Arobh | NORMAL | 2024-01-07T03:36:22.099830+00:00 | 2024-01-07T03:36:22.099852+00:00 | 35 | false | \n# Complexity\n- \n\n# Code\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n ArrayList<Boolean> ans = new ArrayList<>();\n int num = 0;\n for(int i = 0 ;... | 1 | 0 | ['Java'] | 0 |
binary-prefix-divisible-by-5 | Simple C# solution | simple-c-solution-by-dmitriy-maksimov-aled | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\npublic class Solution\n{\n public IList<bool> PrefixesDivBy5(int[] nums)\n {\n | dmitriy-maksimov | NORMAL | 2023-09-06T01:59:33.491451+00:00 | 2023-09-06T01:59:33.491478+00:00 | 28 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\npublic class Solution\n{\n public IList<bool> PrefixesDivBy5(int[] nums)\n {\n var result = new List<bool>();\n var num = 0;\n foreach (var n in nums)\n {\n num = (num * 2 + n) % 5;\n ... | 1 | 0 | ['C#'] | 0 |
binary-prefix-divisible-by-5 | Simple Javascript solution | simple-javascript-solution-by-kamalbhera-zpfh | \n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n | kamalbhera | NORMAL | 2023-05-16T01:37:30.366102+00:00 | 2023-05-16T01:37:30.366151+00:00 | 161 | false | \n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {boolean[]}\n */\nvar prefixesDivBy5 = function(nums) {\n let result = ... | 1 | 0 | ['JavaScript'] | 0 |
binary-prefix-divisible-by-5 | Python3 Solution || Beats 99.30% || Prefix Approach | python3-solution-beats-9930-prefix-appro-rgmw | python\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n currBinary, result = 0, []\n for bit in nums:\n | Heber_Alturria | NORMAL | 2023-02-24T02:41:39.625254+00:00 | 2023-02-24T02:42:31.996141+00:00 | 656 | false | ```python\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n currBinary, result = 0, []\n for bit in nums:\n currBinary = (currBinary * 2 + bit) % 5 \n result.append(currBinary == 0)\n return result\n``` | 1 | 0 | ['Array', 'Prefix Sum', 'Python'] | 0 |
binary-prefix-divisible-by-5 | Java and Python Solution | java-and-python-solution-by-a_shekhar-ymag | 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 | a_shekhar | NORMAL | 2022-10-11T16:46:41.474064+00:00 | 2023-10-03T16:27:46.843363+00:00 | 482 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 1 | 0 | ['Python', 'Java', 'Python3'] | 1 |
binary-prefix-divisible-by-5 | [C++] Faster than 98% | c-faster-than-98-by-nil24-ok90 | \nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n int n=0;\n vector<bool> res;\n\t\t\n for(int i=0;i<nums | Nil24 | NORMAL | 2022-08-17T08:55:54.330319+00:00 | 2022-08-17T08:55:54.330367+00:00 | 347 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n int n=0;\n vector<bool> res;\n\t\t\n for(int i=0;i<nums.size();i++){\n n=(n<<1)+nums[i];\n res.push_back(n%5==0);\n n=n%5;\n }\n\t\t\n return res;\n }\n};\n``` | 1 | 0 | ['C'] | 1 |
binary-prefix-divisible-by-5 | java solution | 100% efficient | java-solution-100-efficient-by-aayushkum-tno9 | \nclass Solution {\n func prefixesDivBy5(_ nums: [Int]) -> [Bool] {\n var divisibleByFive = [Bool]()\n var n = 0\n for bit in nums {\n | aayushkumar20 | NORMAL | 2022-07-19T18:59:55.692192+00:00 | 2022-07-19T18:59:55.692238+00:00 | 147 | false | ```\nclass Solution {\n func prefixesDivBy5(_ nums: [Int]) -> [Bool] {\n var divisibleByFive = [Bool]()\n var n = 0\n for bit in nums {\n n = (n * 2 + bit) % 10\n divisibleByFive.append(n == 5 || n == 0)\n }\n return divisibleByFive\n }\n}\n``` | 1 | 0 | ['Swift'] | 1 |
binary-prefix-divisible-by-5 | C++ simple solution | c-simple-solution-by-osmanay-pedp | \nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n int n = nums.size();\n vector<bool> res(n);\n | osmanay | NORMAL | 2022-07-02T23:30:06.654306+00:00 | 2022-07-02T23:30:06.654344+00:00 | 92 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n int n = nums.size();\n vector<bool> res(n);\n \n int num = 0;\n \n for(int i=0; i<n; i++)\n {\n num = num*2 + nums[i];\n num %= 5;\n res[i] =... | 1 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Java | 3 liner | Explained | java-3-liner-explained-by-prashant404-c81j | Idea: Iterate over the array, form the new number and check for divisibility by 5. Mod by 5 at every iteration to avoid overflows\n>T/S: O(n)/O(1), where n = si | prashant404 | NORMAL | 2022-03-07T02:08:31.188053+00:00 | 2022-03-07T02:09:41.834256+00:00 | 194 | false | **Idea:** Iterate over the array, form the new number and check for divisibility by 5. Mod by 5 at every iteration to avoid overflows\n>**T/S:** O(n)/O(1), where n = size(nums). Ignoring space for output\n```\npublic List<Boolean> prefixesDivBy5(int[] nums) {\n\tvar answer = new ArrayList<Boolean>(nums.length);\n\tfor ... | 1 | 0 | ['Java'] | 0 |
binary-prefix-divisible-by-5 | [ Problem No. 1018 ] Easy solution for beginners | C++ | problem-no-1018-easy-solution-for-beginn-bikh | \nclass Solution {\npublic:\n\tvector<bool> prefixesDivBy5(vector<int>& nums) {\n\t\tvector<bool> res;\n\t\tint t = 0;\n\t\tfor(int i = 0; i < nums.size(); i++) | rakibhasan1030 | NORMAL | 2022-03-01T18:35:13.335117+00:00 | 2022-03-01T18:35:13.335158+00:00 | 141 | false | ```\nclass Solution {\npublic:\n\tvector<bool> prefixesDivBy5(vector<int>& nums) {\n\t\tvector<bool> res;\n\t\tint t = 0;\n\t\tfor(int i = 0; i < nums.size(); i++){\n\t\t\tt = (t * 2 + nums[i]) % 5;\n\t\t\tres.push_back(t == 0);\n\t\t}\n\t\treturn res;\n\t}\n};\n```\n***Please upvote if it was helpful for you, thank ... | 1 | 0 | ['Array', 'C', 'C++'] | 0 |
binary-prefix-divisible-by-5 | Simple Python Solution | simple-python-solution-by-idebbarh-x4io | \n def prefixesDivBy5(self, nums):\n output = []\n nums = "".join([str(i) for i in nums])\n for i in range(0,len(nums)) :\n i | idebbarh | NORMAL | 2022-02-28T11:27:13.890599+00:00 | 2022-02-28T11:27:13.890639+00:00 | 48 | false | ```\n def prefixesDivBy5(self, nums):\n output = []\n nums = "".join([str(i) for i in nums])\n for i in range(0,len(nums)) :\n if int(nums[0:i+1], 2)%5==0 :\n output.append(True)\n else :\n output.append(False)\n return output\n``` | 1 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | (C++) 1018. Binary Prefix Divisible By 5 | c-1018-binary-prefix-divisible-by-5-by-q-uh13 | \n\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> ans; \n int prefix = 0; \n for (auto& x | qeetcode | NORMAL | 2022-02-02T21:17:45.986963+00:00 | 2022-02-02T21:17:45.986995+00:00 | 166 | false | \n```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> ans; \n int prefix = 0; \n for (auto& x : nums) {\n prefix = (2*prefix + x) % 5; \n ans.push_back(!prefix); \n }\n return ans; \n }\n};\n``` | 1 | 0 | ['C'] | 0 |
binary-prefix-divisible-by-5 | Golang easy solution 8ms 100% | golang-easy-solution-8ms-100-by-fshiori-1rct | \nfunc prefixesDivBy5(nums []int) []bool {\n ans := make([]bool, len(nums))\n var t int\n for i, num := range nums {\n t = t << 1 + num\n | fshiori | NORMAL | 2021-12-26T13:15:40.404183+00:00 | 2021-12-26T13:15:40.404223+00:00 | 136 | false | ```\nfunc prefixesDivBy5(nums []int) []bool {\n ans := make([]bool, len(nums))\n var t int\n for i, num := range nums {\n t = t << 1 + num\n if t % 5 == 0 {\n ans[i] = true\n t = 0\n } else {\n t %= 5\n }\n }\n return ans\n}\n``` | 1 | 0 | ['Go'] | 0 |
binary-prefix-divisible-by-5 | Binary Prefix Divisible By 5: Combining a bit shift with modulo | binary-prefix-divisible-by-5-combining-a-7mzn | This solution has a space complexity of O(n) because the length of the list returned is n. But if we use a generator instead, this becomes O(1). We iterate thro | jodawill | NORMAL | 2021-12-07T20:40:38.882876+00:00 | 2021-12-07T20:40:38.882908+00:00 | 65 | false | This solution has a space complexity of `O(n`) because the length of the list returned is `n`. But if we use a generator instead, this becomes `O(1)`. We iterate through each bit in the list, shifting as we go, and adding true or false to the results, based on whether `n % 5 == 0`. So the time complexity is also `O(n)`... | 1 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Python: 5 lines of code with bad explanation | python-5-lines-of-code-with-bad-explanat-e7ol | python\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n n = 0\n for i, bit in enumerate(nums):\n n = (n | ctonic | NORMAL | 2021-12-06T20:04:31.252818+00:00 | 2021-12-06T20:04:31.252856+00:00 | 100 | false | ```python\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n n = 0\n for i, bit in enumerate(nums):\n n = (n << 1) + bit\n nums[i] = not (n % 5)\n return nums`\n```\n\nReuse the list to save space\nIDK if (n << 1) or (n * 2) is faster | 1 | 0 | ['Python3'] | 0 |
binary-prefix-divisible-by-5 | O(n) time, O(n) space. | on-time-on-space-by-yayarokya-7byy | \npublic class Solution {\n public IList<bool> PrefixesDivBy5(int[] nums) {\n var res = new List<bool>();\n int curr = 0;\n foreach(var | yayarokya | NORMAL | 2021-09-10T06:14:27.890789+00:00 | 2021-09-10T06:19:16.431115+00:00 | 99 | false | ```\npublic class Solution {\n public IList<bool> PrefixesDivBy5(int[] nums) {\n var res = new List<bool>();\n int curr = 0;\n foreach(var n in nums) {\n curr = (2*curr + n) % 5;\n res.Add(curr == 0);\n }\n return res;\n }\n}\n``` | 1 | 1 | [] | 0 |
binary-prefix-divisible-by-5 | Python simple solution O(n) | python-simple-solution-on-by-doya1-gc1o | \nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n answer = []\n start = 1\n val = 0\n for i in nums: | doya1 | NORMAL | 2021-07-26T05:01:55.450139+00:00 | 2021-07-26T05:01:55.450188+00:00 | 68 | false | ```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n answer = []\n start = 1\n val = 0\n for i in nums:\n val += i\n if val%5==0:\n answer.append(True)\n else:\n answer.append(False)\n v... | 1 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Java Simple Solution | java-simple-solution-by-kunalojha1999-yn13 | \nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n int cur = 0;\n ArrayList<Boolean> res = new ArrayList<>();\n \n | kunalojha1999 | NORMAL | 2021-07-22T15:45:35.357586+00:00 | 2021-07-22T15:45:35.357638+00:00 | 178 | false | ```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n int cur = 0;\n ArrayList<Boolean> res = new ArrayList<>();\n \n for(int i = 0 ; i < nums.length ; i++){\n cur = (2 * cur + nums[i]) % 5;\n if(cur == 0)\n res.add(true);\n ... | 1 | 0 | [] | 0 |
binary-prefix-divisible-by-5 | Java | Bit-manipulation | java-bit-manipulation-by-tangjiawei18-0s32 | \n public List<Boolean> prefixesDivBy5(int[] nums) {\n int a = 0;\n List<Boolean> res = new ArrayList<>();\n for (int i :nums) {\n | tangjiawei18 | NORMAL | 2021-06-29T07:05:10.178541+00:00 | 2021-06-29T07:05:10.178600+00:00 | 97 | false | ```\n public List<Boolean> prefixesDivBy5(int[] nums) {\n int a = 0;\n List<Boolean> res = new ArrayList<>();\n for (int i :nums) {\n a = (a << 1 | i) % 5;\n res.add(a == 0);\n }\n return res;\n }\n``` | 1 | 0 | ['Bit Manipulation'] | 0 |
binary-prefix-divisible-by-5 | C++ ||Clean Code|| Easy explanation||Short| T: 90%, Mem:100% | c-clean-code-easy-explanationshort-t-90-udlzx | the intution is based on storing prefix sum, but instead of sum, i am storing the number upto that point.\nIt would be easier to understand if we consider decim | DivyanshuCS | NORMAL | 2021-06-21T19:23:54.502129+00:00 | 2021-06-21T19:23:54.502171+00:00 | 108 | false | the intution is based on storing prefix sum, but instead of sum, i am storing the number upto that point.\nIt would be easier to understand if we consider decimal number system.\nImagine nums represet a decimal number array instead of binary and you have an array like\n1 0 2 3 8 9 0 1\nso at index 0, the number it will... | 1 | 0 | ['C++'] | 1 |
binary-prefix-divisible-by-5 | 100% FASTER || c++ SOLUTION || SIMPLE 5 LINES SOLUTION | 100-faster-c-solution-simple-5-lines-sol-ili8 | ```\nclass Solution {\npublic:\n vector prefixesDivBy5(vector& nums) {\n vectorans;\n int sum=0;\n \n \n for(int i=0;i<num | SJ4u | NORMAL | 2021-05-30T19:01:41.494150+00:00 | 2021-05-30T19:01:41.494185+00:00 | 124 | false | ```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool>ans;\n int sum=0;\n \n \n for(int i=0;i<nums.size();i++)\n {\n sum*=2;\n sum+=nums[i];\n sum=sum%5;\n ans.push_back(sum%5==0);\n ... | 1 | 1 | ['C'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.