ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
def max3(a):
a = sorted(a)
return max(a[-1] * a[-2] * a[-3], a[0] * a[1] * a[-1])
print(max3([1, 2, 3, 4]), max3([-10, -10, 5, 2]))- A. 24 500
- B. 12 -100
- C. 60 500
- D. 24 100
Correct answer: A. 24 500
The largest product of three is either the three biggest values or two very negative values times the biggest. For [-10, -10, 5, 2] the pair -10 x -10 gives 100, and times 5 that is 500.
More Python Programming questions
- What is printed? python def g(): try: yield 1 yield 2 finally: print('cleanup') it = g() print(next(it)) it.close() print(list(it))
- What is printed? python print('hello world'.translate({ord('l'): None, ord('o'): 'O'}))
- What is printed? python class N: def init(self, v): self.v = v self.nxt = None def hascycle(h): slow = fast = h steps = 0 while fast and…
- What is printed? python print(hash(-1), hash(-2), hash(-1) == -2, hash(1) == hash(1.0))
- What is printed? python print(232, (23)2, -22, (-2)2, 2-12)
- What is printed? python print(float(254) + 1 == 254, 254 + 1 == float(254), 1e16 + 2 == 1e16 + 1)