ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
seen = {}
for i, x in enumerate([2, 7, 11, 15]):
if 9 - x in seen:
print((seen[9 - x], i))
break
seen[x] = i- A. (1, 2)
- B. (0, 2)
- C. (2, 3)
- D. (0, 1)
Correct answer: D. (0, 1)
For x = 7 the complement 9 - 7 = 2 is already in seen at index 0, so the pair is (0, 1).
More Python Programming questions
- What is printed? python print(len(bin(10 6)) - 2, len(bin(2 20)) - 2)
- What is printed? python print(max(range(10), key=lambda x: x % 4), min([], default=7))
- What is printed? python print(3 -1, 7 // 0.5, 2 0.5 2 0.5 == 2)
- What is printed? python print(float('%.2f' % 0.125), '%.3e' % 12345.678)
- What is printed? python print(int(str(2 70)[:5]), len(str(2 70)))
- What is printed? python print(list(range(10, 0, -4)), [sum(r) for r in [(1, 2), (3,)]])