#K93117. Maximum Product of Two Numbers
Maximum Product of Two Numbers
Maximum Product of Two Numbers
Given an integer array with at least two elements, your task is to determine the maximum product obtainable by multiplying any two distinct numbers from the list. Note that the product of two negative numbers may yield a larger positive result. For instance, multiplying two large negative numbers might produce a higher product than multiplying two smaller positive numbers.
If the input array contains fewer than two elements, output At least two elements are required
.
Example:
- Input: 1 10 2 6 5
Output: 60 - Input: -10 -20 1 3 2
Output: 200
Mathematical formulation:
Given an array \(a_1, a_2, \dots, a_n\) with \(n \ge 2\), find \[ \max_{1 \le i < j \le n}\{a_i \times a_j\}. \]
inputFormat
The first line of input contains an integer (n) (where (n \ge 2)) representing the number of elements in the array. The second line contains (n) integers separated by spaces.
outputFormat
Output a single integer which is the maximum product obtainable by multiplying any two distinct numbers from the list. In case there are fewer than two numbers, output the string "At least two elements are required".## sample
5
1 10 2 6 5
60