Suppose we have three numbers, x, y, and z, we have to find their product, but if any two numbers are equal, they do not count.
So, if the input is like x = 5, y = 4, z = 2, then the output will be 40, as all three numbers are distinct so their product is 5 * 4 * 2 = 40
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, x, y, z): temp_set = set() remove = set() for i in [x, y, z]: if i in temp_set: remove.add(i) temp_set.add(i) for i in remove: temp_set.remove(i) multiplied = 1 for i in temp_set: multiplied *= i return multiplied ob = Solution() print(ob.solve(5, 4, 2))
5, 4, 2