✅☑[C++] || Beats 100% || EXPLAINED🔥
\n# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approach\n(Also explained in the code)\n\n1. The maxSubarrays function takes a vector nums as input.\n\n1. It start
\n# *PLEASE UPVOTE IF IT HELPED*\n\n---\n\n\n# Approach\n***(Also explained in the code)***\n\n1. The `maxSubarrays` function takes a vector `nums` as input.\n\n1. It starts by calculating the bitwise AND of all elements in `nums` and stores the result in `a_`.\n\n1. If `a_` is not zero, it means there is at least one element in `nums` with all bits set to 1. In this case, it returns 1.\n\n1. If `a_` is zero, it initializes `size` to 1 and `a_` as a 20-bit mask of all 1s.\n\n1. It then iterates through the elements of `nums`, calculating the bitwise AND of `a_` and each element.\n\n1. When `a_` becomes zero during this iteration, it increments the `size` and resets `a_` to the 20-bit mask of all 1s.\n\n1. After the loop, if a_ is not zero, it decrements the `size`.\n\n1. Finally, it returns the `size` as the result.\n\n\n---\n\n\n# Complexity\n- **Time complexity:**\n$$O(n)$$\n\n- **Space complexity:**\n$$O(1)$$\n\n---\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maxSubarrays(vector<int>& nums) {\n        int a_ = nums[0]; // Initialize a_ with the first element of nums.\n        \n        // Calculate bitwise AND of all elements in nums.\n        for(int num:nums) {\n            a_ &= num;\n        }\n        \n        if(a_) {\n            return 1; // If a_ is not zero, return 1.\n        }\n        \n        int size = 1; // Initialize the size to 1.\n        a_ = (1 << 20) - 1; // Initialize a_ as a 20-bit mask of all 1s.\n        \n        for(int num:nums) {\n            a_ &= num; // Calculate bitwise AND of a_ and the current element.\n            \n            if(a_ == 0) {\n                size++; // If a_ becomes zero, increment the size.\n                a_ = (1 << 20) - 1; // Reset a_ to the 20-bit mask of all 1s.\n            }\n        }\n        \n        if(a_) {\n            size--; // If a_ is not zero at the end, decrement the size.\n        }\n        \n        return size; // Return the final size.\n    }\n};\n\n```\n\n# *PLEASE UPVOTE IF IT HELPED*\n\n---\n\n---\n\n
['Array', 'Bit Manipulation', 'C++']