You are provided an array of integers. You are required to partition the array into the minimum number of subarrays such that the of any non-empty subset of the subarrays is not equal to zero. If no such partition exists, then print . Otherwise, print 1.
Note:
Note:
- A subarray is a non-empty contiguous subsequence of an array.
- The of a set of subarrays is defined as the sum of determined of the numbers in all the subarrays when accumulated.
Solution
#include <iostream>
using namespace std;
int main() {
long long num,c=0;
cin >> num;
long long a[num];
for(long long i=0;i<num;i++)
{
cin>>a[i]; }
for(long long i=0;i<num;i++)
{
c=c^a[i];
if(c==0)
{
cout<<-1;
exit(0);
}
}
cout<<1;
}
if you have any problem in this code, take a screenshot and contact with Rishabh Chaubey.
Post a Comment