Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Maximum Product of Two Elements in an Array

Easy

Topics
ArraySorting

Given an array nums, choose two different indices i and j and return the maximum value of (nums[i]-1)*(nums[j]-1).

Example 1

Input:  nums = [3,4,5,2]
Output: 12

Example 2

Input:  nums = [1,5,4,5]
Output: 16

Constraints

  • 2 <= nums.length <= 500
  • 1 <= nums[i] <= 10^3
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access