- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find the product of three elements when all are unique in Python

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 −

- temp_set := a new set
- remove := a new set
- for each i in [x,y,z], do
- if i is in temp_set, then
- insert i into the set called remove

- insert i in to the set temp_set

- if i is in temp_set, then
- for each i in remove, do
- delete i from temp_set

- multiplied := 1
- for each i in temp_set, do
- multiplied := multiplied * i

- return multiplied

Let us see the following implementation to get better understanding −

## Example

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))

## Input

5, 4, 2

## Output

40

- Related Questions & Answers
- Program to find largest product of three unique items in Python
- Program to find sum of unique elements in Python
- Program to find a list of product of all elements except the current index in Python
- Program to find three unique elements from list whose sum is closest to k Python
- Program to find the largest product of two distinct elements in Python
- Python program to find common elements in three sorted arrays?
- Find the greatest product of three numbers in JavaScript
- Python program to find the maximum of three numbers
- Java Program to find Product of unique prime factors of a number
- Python – Test if all elements are unique in columns of a Matrix
- C/C++ Program to find the Product of unique prime factors of a number?
- Python program to find common elements in three lists using sets
- C program to find the unique elements in an array.
- Program to find length of longest consecutive sublist with unique elements in Python
- Program to check we can find three unique elements ose sum is same as k or not Python

Advertisements