Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Product of All Array Elements

Easy Acceptance 80.00% Points 20.00

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.

Examples
Example 1

Example 1

Input: arr[] = [1 2 3 4]

Output: 24

Explanation: 1 × 2 × 3 × 4 = 24

Example 2

Example 2

Input: arr[] = [5 2 0 6]

Output: 0

Explanation: Since one element is 0, the product becomes 0.

Example 3

Example 3

Input: arr[] = [-2 3 4]

Output: -24

Explanation: (-2) × 3 × 4 = -24

Hints
Hint 1
N/A
Constraints
  • 1 <N<105
  • -109 < arr[i] < 109
Companies
Microsoft DE Shaw Mastercard
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions