text: Count of elements which are equal to the XOR of the next two elements | Function to return the count of elements which are equal to the XOR of the next two elements ; To store the required count ; For every element of the array such that it has at least two elements appearing after it in the array ; If current element is equal to the XOR of the next two elements in the array ; Driver code
code: function cntElements ( arr , n ) { let cnt = 0 ; for ( let i = 0 ; i < n - 2 ; i ++ ) { if ( arr [ i ] == ( arr [ i + 1 ] ^ arr [ i + 2 ] ) ) { cnt ++ ; } } return cnt ; } let arr = [ 4 , 2 , 1 , 3 , 7 , 8 ] ; let n = arr . length ; document . write ( cntElements ( arr , n ) ) ;