Data Structures & AlgorithmsHardICPC regional · string round
Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for s = 'banana'? Run the code.
Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for s = 'banana'? Run the code.
s = 'banana' sa = sorted(range(len(s)), key=lambda i: s[i:]) print(sa[2])What is printed?
- A. 1
- B. 3
- C. 0
- D. 4
Correct answer: A. 1
The sorted suffixes are a, ana, anana, banana, na, nana, so position 2 holds the suffix 'anana' starting at index 1. Sorting by start index instead of suffix text gives the trap 0.
More Coding Interview Problems questions
- Problem: How many topological orders does the DAG with edges 0->2, 1->2, 2->3 on vertices 0..3 have? Run the brute-force code. python from…
- Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row…
- Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code. python print(sum(100 // 3…
- Problem: How many collinear triples of points does the 3 x 3 grid {0,1,2}^2 contain? Use the cross-product test below. python from…
- Problem: How many integers x in [1, 60] satisfy x ≡ 2 (mod 3) and x ≡ 3 (mod 4)? Run the code. python print(sum(1 for x in range(1, 61) if…
- Problem: How many unordered pairs from {1, 2, 3, 4, 5, 6} have XOR equal to 7? Run the code. python from itertools import combinations…