Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many ordered triples (a, b, c) of positive integers satisfy a + b + c = 7? Run the code.
Problem: How many ordered triples (a, b, c) of positive integers satisfy a + b + c = 7? Run the code.
print(sum(1 for a in range(1, 8) for b in range(1, 8) for c in range(1, 8) if a + b + c == 7))What is printed?
- A. 36
- B. 15
- C. 4
- D. 21
Correct answer: B. 15
Positive solutions of a + b + c = 7: C(6,2) = 15. Allowing zeros gives C(9,2) = 36, unordered triples give 4, and C(7,2) = 21 uses the wrong stars-and-bars formula.
More Coding Interview Problems questions
- Problem: What is the largest possible value of gcd(a, b) when a + b = 60 and a != b with a, b positive? Run the code. python from math…
- Problem: What is the complexity of a single query in a sparse-table range minimum structure?
- Problem: What is the purpose of a 'suffix link' in Ukkonen's or Aho-Corasick's construction?
- Problem: Which property does an 'order statistics' tree support in addition to search?
- Problem: What is the time complexity of the 'Mo's algorithm with updates' (time dimension added) in terms of n and q?
- Problem: Which problem asks for the length of the shortest cycle in an undirected unweighted graph?