Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Max Product of Two Integers

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Max Product of Two Integers. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A Tech Mahindra delivery analytics component receives an array of integer measurements and must identify the pair that produces the greatest product. Given an integer array nums, return the maximum product obtainable by multiplying two distinct elements.

The pair may contain negative values. Therefore, two very small negative numbers can produce the maximum result, so checking only the two largest values is insufficient.

Formal Specification

Implement max_product_pair(nums).

  • Input: nums, a list of at least two integers.
  • Output: An integer representing the maximum product of any two elements at different indices.
  • Elements may be selected in any order, but the same array position cannot be used twice.

Constraints

  • 2 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • The input contains integers only
  • The two selected values must come from distinct positions

Function Signature

def max_product_pair(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output