We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Non-Divisible Subset
Non-Divisible Subset
Sort by
recency
|
813 Discussions
|
Please Login in order to post a comment
// Write your code here int arr[]=new int[k]; for(int i=0;i
int max=Math.min(arr[0],1);
for(int i=1;i<=k/2;i++) { if(i!=k-i) { max+=Math.max(arr[i],arr[k-i]); } else { max++; } } return max;
The fact that the hardest part on this thing was remembering how mods work other than checking if smt is divisible xd
The wording "maximal subset of S" is mistaken. "Maximal" does not mean largest. It means any set that can't be extended by adding a new element of S without violating the definition of the desired subset (the non-divisibility property). The correct term is "maximum", which means largest. Again, "maximal" only means not extendible, and a maximal subset may not be a maximum subset.
Here is my thought process:
Now is the fun part. I first thought it was a DP, but it was much easier. Each pair i+j = k -> choose the one with more elements
with i = 0 and i = k // 2 -> either 1 or 0
o(k/2)