![]() |
VOOZH | about |
Given an array arr[] of positive integers. The task is to print the minimum product of any two numbers of the given array.
Examples:
Input: arr[] = [2, 7, 3, 4]
Output: 6
Explanation: The minimum product of any two numbers will be 2 * 3 = 6.
Input: arr[] = [198, 76, 544, 123, 154, 675]
Output: 9348
Explanation: The minimum product of any two numbers will be 76 * 123 = 9348.
Table of Content
The idea is to generate all possible pairs of elements in the array and compute their product. Keep track of the minimum product encountered during the traversal.
9348
Time Complexity: O(n ^ 2)
Auxiliary Space: O(1)
The idea is to find the smallest and second smallest elements in a single traversal of the array. Since all elements are positive, the minimum product will always be formed by the two smallest numbers.
9348
Time Complexity: O(n)
Auxiliary Space: O(1)