classSolution: defcountTriplets(self, arr: List[int]) -> int: n = len(arr) s = [0] for val in arr: s.append(s[-1] ^ val) ans = 0 for i inrange(n): for j inrange(i + 1, n): for k inrange(j, n): if s[i] == s[k + 1]: ans += 1 return ans
classSolution: defcountTriplets(self, arr: List[int]) -> int: n = len(arr) s = [0] for val in arr: s.append(s[-1] ^ val) ans = 0 for i inrange(n): for k inrange(i + 1, n): if s[i] == s[k + 1]: ans += k - i return ans