2
def maximumProduct(self, nums: List[int]) -> int:3
# TC = O(NlogN) because sorting the array4
# SC = O(1); no extra space needed; sorting was done in place.6
# sorting the array in descending order7
nums.sort(reverse=True)9
# maximum product can only occur for:10
# 1. positive no * positive no * positive no11
# 2. negative no * negative no * positive no13
# one negative and two positives and all negatives wont give max product14
# case where all numbers in the array are negative15
# eg : [-4,-3,-2,-1] is covered in all positives17
return max(nums[0] * nums[1] * nums[2], nums[-1] * nums[-2] * nums[0])