- 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

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

- if nums[i] is same as (mul / nums[i]), then
- return False

Let us see the following implementation to get better understanding −

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

[3,2,24,4,1]

True

- Related Questions & Answers
- Check if the array has an element which is equal to sum of all the remaining elements in Python
- Element equal to the sum of all the remaining elements in C++
- Find an element which divides the array in two subarrays with equal product in Python
- Check if some elements of array are equal JavaScript
- Check if an array object is equal to another array object in C#
- Find if array has an element whose value is half of array sum in C++
- How to check if an element has a class in jQuery?
- Check if subarray with given product exists in an array in Python
- Check if product of digits of a number at even and odd places is equal in Python
- Given an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript
- JavaScript: Check if array has an almost increasing sequence
- Python – Check if elements index are equal for list elements
- Check if product of array containing prime numbers is a perfect square in Python
- Check if elements of array can be made equal by multiplying given prime numbers in Python
- Check if an array contains all elements of a given range in Python

Advertisements