Data Structures & AlgorithmsModerateICPC regional · TCS NQT
Problem: Find the modular inverse of 7 modulo 26 (the value x with 0 ≤ x < 26 such that 7x ≡ 1 mod 26).
- A. 11
- B. 15
- C. 1
- D. 19
Correct answer: B. 15
Extended Euclid gives 1 = 3·26 − 11·7, so x ≡ −11 ≡ 15 (check: 7 · 15 = 105 = 4·26 + 1). Dropping the minus sign gives 11 (7 · 11 ≡ −1), applying Fermat's 7^(26−2) to the non-prime 26 gives 1, and 26 − 7 = 19 is the additive inverse.
More Coding Interview Problems questions
- Problem: A Gray code of 4 bits is generated as g = n XOR (n >> 1) for n = 0 to 15. What is the Gray code value of n = 11?
- Problem: The sum of the digits of 2^100 written in base 10 is computed. What is that sum?
- Problem: In a spiral traversal of a 5×5 matrix filled row-wise with 1 to 25, the traversal starts at the top-left and goes right, then…
- Problem: A bitmask DP problem: count the subsets of {1, 2, ..., 10} whose sum is a multiple of 5 (the empty set counts, since its sum 0 is…
- Problem: An 8-bit unsigned counter starts at 250 and is incremented by 7 each step, wrapping modulo 256. How many increments until the…
- Problem: The Pascal triangle rows are numbered from row 0 (single 1). What is the sum of all entries in row 12 that are odd?