Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many indices i in "xyzxyzxyz" satisfy s[i] = s[i + 3]?
- A. 7
- B. 6
- C. 0
- D. 5
Correct answer: B. 6
A period-3 string matches itself at shift 3 everywhere the shift fits, so the count is length minus 3. The shift of 2 (the second option) has no matches here.
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
- A singly linked list holds 1..7. Using the slow/fast pointer method, the slow pointer reaches the middle node. How many nodes come after…
- What is the minimum number of elements to delete from [1, 1, 1, 2, 2, 2, 2, 3] so that every value appears at most twice?
- Group the values [1, 2, 4, 5, 6, 9, 10] so that consecutive sorted values with difference at most 1 share a group. How many groups result?
- How many ordered triples of positive integers (x, y, z) satisfy x + y + z = 10?
- Replacing at most one character, what is the length of the longest substring of "abcbbbcaa" that can be made into a single repeated letter?
- What is the smallest integer greater than 13 that has the same number of 1-bits as 13 in binary?