Data Structures & AlgorithmsModerateCodeforces Div2 B · CRT
Problem: What is the smallest positive integer x with x ≡ 1 (mod 4) and x ≡ 2 (mod 5)? Run the code.
Problem: What is the smallest positive integer x with x ≡ 1 (mod 4) and x ≡ 2 (mod 5)? Run the code.
print(next(x for x in range(1, 100) if x % 4 == 1 and x % 5 == 2))What is printed?
- A. 6
- B. 17
- C. 12
- D. 22
Correct answer: B. 17
17 = 4 * 4 + 1 and 17 = 5 * 3 + 2, and 17 is the smallest such number.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] have non-decreasing decimal digits (for example 1245 or 3399, but 2 digits only here)? Run the…
- Problem: What is the spiral (clockwise from the top-left) traversal of the matrix [[1,2,3],[4,5,6],[7,8,9]]? Print the list produced by…
- Problem: How many swaps does insertion sort perform on [3, 2, 1]? Count the shifts in the code. python a = [3, 2, 1] swaps = 0 for i in…
- Problem: What is the minimum number of intervals from [[1,4],[3,7],[6,10],[9,10]] needed to cover the segment [1, 10]? Run the greedy…
- Problem: How many pairs (i < j) of [1, 2, 3, 4, 5] have a[i] XOR a[j] = 1? Run the code. python a = [1, 2, 3, 4, 5] print(sum(1 for i in…
- Problem: How many subarrays of [3, 4, 7, 2, -3, 1, 4, 2] have sum exactly 7? Run the prefix-sum hash code. python from collections import…