ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
from collections import Counter a = [1, 1, 2, 3, 3] c = Counter(a) print(sum(c[x] * c[4 - x] for x in c))
- A. 9
- B. 5
- C. 8
- D. 4
Correct answer: A. 9
The sum counts ordered pairs (i, j) whose values add to 4, including pairs of equal values. Value 1 pairs with 3 in 2 x 2 = 4 ways, value 2 pairs with itself in 1 way, and value 3 pairs with 1 in 4 more ways.
More Python Programming questions
- What is printed? python def nlis(a): n = len(a) L = [1] n C = [1] n for i in range(n): for j in range(i): if a[j] < a[i]: if L[j] + 1 >…
- What is printed? python print(bin(29 ^ 15).count('1'))
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def p(n, m): if n == 0: return 1 if n < 0 or m == 0: return…
- What is printed? python import math print(sum(map(int, str(math.factorial(10)))))
- What is printed? python x = 'abc' print(x.islower() and x.isalpha(), ''.isdigit())
- What is printed? python it = iter('ab') print(next(it), list(it), next(it, 'end'))