solved using reduce and xor