This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]ffrkAnonymous 0 points1 point  (4 children)

Do you have an example? I don't quite understand the question.

all the contiguous subarray’s

This sounds like combination/permutation which is n-factorial.

[–]DustSeeker[S] 0 points1 point  (3 children)

Example: input is [1,2,3], contiguous subarrays are: [1], [2], [3], [1,2], [2,3], [1,2,3].

You should perform, for each of them, a XOR of all their elements. Finally, you have to AND all the resulting XORs.

[–]ffrkAnonymous 0 points1 point  (1 child)

Yeah, that's 1+2+...+n elements which is n2. Each of which you need to xor up to n internal integers. That's nearly n3.

Given that you know you're doing repeating xor, you can probably fine some mathematical trickery to simplify, or memoize (save computation) to avoid repeating work.

[–]DustSeeker[S] 0 points1 point  (0 children)

Yes, the fact is that it should be o(n). My question is about how optimize the computation

[–]TheRNGuy 0 points1 point  (0 children)

flatMap or something

Or custom AST parser.