Suppose we have a list of numbers, we have to find the largest product of two distinct elements.
So, if the input is like [5, 3, 7, 4], then the output will be 35
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, nums): curr_max = float('-inf') for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] * nums[j] > curr_max: curr_max = nums[i] * nums[j] return curr_max ob = Solution() print(ob.solve([5, 3, 7, 4]))
[5, 3, 7, 4]