Incorrect Solution

I am fairly certain a solution for one of the algorithms problem set is incorrect. More specifically… (https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/find-the-symmetric-difference)

" ([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should return `[1, 4, 5]` ."

Seeing that the number 5 is in all three sets, it would not constitute a symmetrical difference.

I think you perhaps overlooked or misunderstood this part:

For example, for sets A = {1, 2, 3} and B = {2, 3, 4}, A △ B = {1, 4}.

Symmetric difference is a binary operation, which means it operates on only two elements. So to evaluate an expression involving symmetric differences among three elements ( `A △ B △ C` ), you must complete one operation at a time. Thus, for sets `A` and `B` above, and `C = {2, 3}` , `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}` .

In other words, the symmetric difference is only defined for 2 sets, so for the examples with more than 2 sets, you take symmetric differences in pairs from left to right, using the last calculated symmetric difference, as needed.

1 Like

You are correct I overlooked the definition of a symmetrical difference.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.