Trie intervew (testcases)

could you please ellaborate on the possibilities of the question?
i think the question should be done like a subarray for left and for right side and then work accordingly…
basically i am not clear with how can the left/right subarray have elements?
Like if we have 9 elemets in array,is it possible to hace 2 elements with index 2 and 3 in left subarray and 3 eleemnts with index 7,8,9 in the right subaaray??
Could you please explain more testaces?

@Vibhuti0206
Like if we have 9 elemets in array,is it possible to hace 2 elements with index 2 and 3 in left subarray and 3 eleemnts with index 7,8,9 in the right subaaray??
Yes this is possible
ex -
Q : 5
8 8 8 8 8
A : 16
index 0 and index 4

If your doubt is resolved please close it

but in the test case that you have given considering left subarray with elements 8 and 2 would give larger numbe than 8,so we will consideer that?

What exactly should be the approach in finding left and right respective subarrays

@Vibhuti0206
Make an array of prefix xor sum
where larr[i] = arr[i] ^ larr[i-1]
then run another loop larr[i] = max(larr[i], larr[i-1])
Similarly a right xor array
Then you can find ans by doing max(ans,larr[i]+rarr[i+1])

But this way in larr[i] will have xor of 2 elemnt pair only,how would it check for subarray like if 3 elements give the greates xor value?

@Vibhuti0206
Please check it carefully
I’ve used larr not arr there

i am unable to figure how to fnf greatest left and right subarrays…kindly elaborate usiing code?

@Vibhuti0206
Let’s take another question
Lets say A = [ 1, 4, 2, -4, 3, -5]
Ques says for each index find max sum from index 0 upto any index including current index
So first you’ll take cumulative sum
A becomes [1, 5, 7, 3, 6, 1]
Then to find max at each index you start taking max of sum upto current index and max sum found till prev index
So A becomes [1, 5, 7, 7, 7, 7]

I hope you’ve understood what I meant

i got how to find left subarray,the stopping point would be when we get a value less than the previous one? and hence the right array starts from that index??? but like as in the above given sample[1,2,6,8] larr would be 1 3 5 15,so how will we maange to find rarr?

@Vibhuti0206
You can see the solution here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.