Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: The string "banana" has its longest repeated substring (a substring occurring at least twice, overlaps allowed) of length L. What is L?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Test each length from the largest down, checking whether any substring repeats (overlaps allowed). The repeat 'ana' overlaps itself inside 'banana', which is why overlaps must be permitted.
More Coding Interview Problems questions
- Problem: How many subsequences equal to the string "abc" are contained in "aabbcbcac" (a subsequence picks positions in increasing order…
- Problem: The string "aabcccccaaa" is run-length encoded (each run becomes its letter followed by its run length, e.g. "a2b1..."). What is…
- Problem: Find the length of the shortest substring of "xaybzcxyabc" that contains all the letters a, b and c at least once.
- Problem: A Conway's Game of Life grid on a 4×4 board with alive cells at (1,0), (1,1), (1,2), (0,2) is advanced by one generation…
- Problem: A list of 6 customers arrives at a bank counter with service times 4, 1, 3, 2, 6, 5 (in that arrival order). The counter serves…
- Problem: A linked list of 10 nodes is traversed with Floyd's tortoise and hare: the slow pointer moves 1 step and the fast pointer moves 2…