Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Find the lexicographically smallest rotation of the string "dcbadcb". What is its starting index (0-based) in the original string, taking the smallest index if several rotations are equal?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Compare all rotations (or use Booth's algorithm in linear time). Taking the lexicographically largest rotation or the rotation starting at the first 'a' is a wrong heuristic.
More Coding Interview Problems questions
- Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?
- Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal…
- Problem: A stack-based reduction processes the string "abbaca" from left to right: if the current character equals the top of the stack…
- Problem: Bubble sort is run on [5, 2, 9, 1, 7, 3, 8, 6, 4] using the standard adjacent-swap pass (for i from 0 to n−2, swap a[j] and…
- Problem: A list starts as [1, 2, 3, 4, 5, 6, 7, 8]. Four operations are applied in order: rotate the list left by 3; reverse the first 4…
- Problem: XOR of all integers from l = 13 to r = 46 inclusive. Compute the result.