Data Structures & AlgorithmsHardCodeforces Div2 B · recurrence
Problem: What is the 1-indexed survivor when n = 6 people stand in a circle and every 3rd person is removed? Run the recurrence code.
Problem: What is the 1-indexed survivor when n = 6 people stand in a circle and every 3rd person is removed? Run the recurrence code.
J = 0
for i in range(2, 7):
J = (J + 3) % i
print(J + 1)What is printed?- A. 4
- B. 5
- C. 1
- D. 2
Correct answer: C. 1
The recurrence J(i) = (J(i-1) + 3) mod i gives 0 for n = 6, so the 1-indexed survivor is person 1.
More Coding Interview Problems questions
- Problem: What is the length of the longest run of equal consecutive characters in 'aabbbbcc'? Run the code. python s = 'aabbbbcc' best =…
- Problem: How many subsets of {1, 2, 3, 4} have a prime sum (the empty set has sum 0 and is not prime)? Run the code. python from itertools…
- Problem: How many ordered pairs (i, j) with i != j of [1, 2, 3, 4] have an even sum? Run the code. python a = [1, 2, 3, 4] print(sum(1 for…
- Problem: What does the following print? python from collections import Counter print(Counter('mississippi').mostcommon(1)) What is printed?
- Problem: What does the following print? python print(round(1.23456, 2), round(-2.5)) What is printed?
- Problem: What does the following print? python print(max([], default=-1), sum([]), divmod(-7, 3))