Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: How many integers x with 0 ≤ x ≤ 99 satisfy x³ ≡ x (mod 7)?
- A. 43
- B. 30
- C. 15
- D. 44
Correct answer: D. 44
x³ ≡ x means x(x − 1)(x + 1) ≡ 0, so x ≡ 0, 1 or 6 (mod 7). In 0..99 that is 15 + 15 + 14 = 44. Starting at 1 gives 43, forgetting x ≡ −1 gives 30, and only x ≡ 0 gives 15.
More Coding Interview Problems questions
- Problem: Daily temperatures are [73, 74, 75, 71, 69, 72, 76, 73]. For each day, the wait is the number of days until a strictly warmer day…
- Problem: In the binary array [1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1] at most 2 zeros may be flipped to 1. What is the length of the longest run…
- Problem: Starting from the empty set, a process inserts the numbers 5, 3, 8, 1, 4, 7 into a binary search tree, and then deletes nothing…
- Problem: The array [4, 2, 5, 1, 3] is turned into a max-heap by sift-down from the last parent to the root (standard heapify, 0-indexed)…
- Problem: A string is "racecar" and we ask: how many substrings of length 2 or 3 are palindromes (counted by index ranges)?
- Problem: The array [6, 1, 9, 4, 4, 8] is scanned, and for each index the number of earlier elements that are strictly smaller is recorded…