Help with Approach

I think it can be solved with taking prefix & suffix xor of cosecutive equal charactes considered as a pile, E.g. : -
S = “aaaabbbcc”
piles array could be {4, 3, 2}
=> pre[] = {4, 7, 5} & suf[] = {5, 1, 2}
now we need to find an i such that pre[i] XOR suf[i+1] == 0
This is my approach but i’m getting WA.

Your approach is correct but some implementation error.
This implementation is much cleaner, please see https://ide.codingblocks.com/s/271399

@sdevwrat In your code why have you done this : dp1[n-i-1]=dp1[n-i]^sr^(sr+1);
why have you done xor operation with sr & sr+1, shouldn’t this : dp1[n-i-1]=dp1[n-i]^sr; would’ve been enough ?

sr will nullify itself from dp1[n-i] and we would only be left with sr+1 xored with the number before the start of this sequence of same characters.

ok, but dp[1] should be dp[0]^2 which is 1^2 = 3, but in your code it gives 2 ? Explain this

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.