Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
The block abc repeats, and n - pi[n-1] = 10 - 7 = 3 gives the smallest period. Periods 2, 4 and 5 fail on some position.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?
- What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?
- What is the minimum number of swaps of ANY two (not necessarily adjacent) elements needed to sort the permutation [4, 3, 2, 1] into…
- How many inversions (pairs i < j with a[i] > a[j]) does the array [2, 4, 1, 3, 5] contain?
- The array [5, 1, 6, 2, 7, 3, 8] must be made strictly increasing by deleting as few elements as possible. How many deletions are needed?
- How many pairs i < j in [2, 3, 4, 6, 9] have gcd(a[i], a[j]) = 1?