Data Structures & AlgorithmsModerateICPC regional · TCS NQT
Problem: The Euclidean algorithm is run on (1071, 462). How many division steps (a mod b operations) are performed until the remainder becomes 0?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Each step replaces the pair by (b, a mod b) and counts one division; the loop ends when the remainder is zero. Counting subtraction steps instead gives a far larger number.
More Coding Interview Problems questions
- Problem: Count the subarrays of [4, 2, 2, 4, 2] whose maximum equals the minimum (single elements count).
- Problem: Water is poured into the cells of a 1-dimensional array of heights [0,1,0,2,1,0,1,3,2,1,2,1]; each cell holds water up to…
- Problem: Starting at 0 on a line, a walker takes steps +3, −2, +3, −2, … alternating, with 12 steps in total. How many distinct integer…
- Problem: Count the sequences of length 5 over {0, 1, 2} with no two adjacent equal digits and whose first digit is 0.
- Problem: The sorted array [1, 4, 4, 9, 12, 12, 15, 20] (0-indexed) may contain repeated values. Using a lower-bound search, which returns…
- Problem: How many subarrays of [1, 2, 2, 3] have max minus min at most 1? Run the code. python a = [1, 2, 2, 3] print(sum(1 for i in…