# Check if the array has an element which is equal to product of remaining elements in Python

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Suppose we have an array called nums we have to check whether the array contains an element whose value is same as product of all other elements.

So, if the input is like nums = [3,2,24,4,1], then the output will be True, 24 = (3*2*4*1).

To solve this, we will follow these steps −

• mul := 1
• for i in range 0 to size of nums - 1, do
• mul := mul * nums[i]
• for i in range 0 to size of nums - 1, do
• if nums[i] is same as (mul / nums[i]), then
• return True
• return False

Let us see the following implementation to get better understanding −

## Example Code

Live Demo

def solve(nums):
mul = 1
for i in range(len(nums)):
mul *= nums[i]

for i in range(len(nums)):
if nums[i] == mul / nums[i]:
return True

return False

nums = [3,2,24,4,1]
print(solve(nums))

## Input

[3,2,24,4,1]

## Output

True