You are given an array of integers. Your task is to calculate the product of all elements present in the array and return the result.
Example 1
Input: arr[] = [1 2 3 4]
Output: 24
Explanation: 1 × 2 × 3 × 4 = 24
Example 2
Input: arr[] = [5 2 0 6]
Output: 0
Explanation: Since one element is 0, the product becomes 0.
Example 3
Input: arr[] = [-2 3 4]
Output: -24
Explanation: (-2) × 3 × 4 = -24
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
11 2
22
3 5 7
105