Count of triplets that satisfy the given equation | C # implementation of the approach ; Function to return the count of required triplets ; First element of the current sub - array ; XOR every element of the current sub - array ; If the XOR becomes 0 then update the count of triplets ; Driver code
using System ; class GFG { static int CountTriplets ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int first = arr [ i ] ; for ( int j = i + 1 ; j < n ; j ++ ) { first ^= arr [ j ] ; if ( first == 0 ) ans += ( j - i ) ; } } return ans ; } public static void Main ( ) { int [ ] arr = { 2 , 5 , 6 , 4 , 2 } ; int n = arr . Length ; Console . WriteLine ( CountTriplets ( arr , n ) ) ; } }