Rust/Python linear solution with detail explanation why zero
Intuition\n\nFirst lets answer a simpler qustion. What is the minimum number we can obtain? To answer it you need to understand what the AND operation does to a
# Intuition\n\nFirst lets answer a simpler qustion. What is the minimum number we can obtain? To answer it you need to understand what the `AND` operation does to a number: it can only decrease it. \n\nSo the minimum number is `AND` of all the numbers. Now lets assume that this minimum is `v`. If the value is positive then the only possible way to achieve is to take the whole array.\n\nIf the value is zero, it might be possible to divide array into more parts and still get zero (as addition of multiple zeros is zero). So all we need is to greedily take elements until the current_and of them is zero. When you get zero you increase the result and start anew.\n\nAt the end you need to check if it is zero to potentially increment one more time\n\n# Complexity\n\n- Time complexity: $O(n)$\n- Space complexity: $O(1)$\n\n# Code\n```Rust []\nimpl Solution {\n  pub fn max_subarrays(nums: Vec<i32>) -> i32 {\n    let (mut res, mut curr) = (0, nums[0]);\n    for i in 1 .. nums.len() {\n      if curr == 0 {\n        res += 1;\n        curr = nums[i];\n      } else {\n        curr &= nums[i];\n      }\n    }\n\n    if curr == 0 {\n      res += 1;\n    }\n    return 1.max(res);\n  }\n}\n```\n```python []\nclass Solution:\n  def maxSubarrays(self, nums: List[int]) -> int:\n    curr, res = nums[0], 0\n    for v in nums[1:]:\n      if curr == 0:\n        res += 1\n        curr = v\n      else:\n        curr &= v\n  \n    return max(1, res + (1 if curr == 0 else 0))\n```\n
['Python', 'Rust']