Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Maximum Product Of Two Numbers

Basic Acceptance 81.34% Points 10.00

You are given an array arr[] of non-negative integers, return the maximum product of two numbers possible.

Examples
Example 1

Example 1

Input: arr[] = [1, 4, 3, 6, 7, 0]

Output: 42

Explanation: 6 and 7 have the maximum product.

Example 2

Example 2

Input: arr[] = [1, 100, 42, 4, 23]

Output: 4200

Explanation: 42 and 100 have the maximum product.

Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Auxiliary Space: O(1)
Constraints
  • 2 <= arr.size <= 10^7
  • 0 <= arr[i] <= 10^9
Companies
Amazon
Topics
Array Sorting Algorithms
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