Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
Check each adjacent pair against the two targets. Counting only 'ab' misses the reversed pairs 'ba' that also qualify.
More Coding Interview Problems questions
- Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?
- Problem: How many distinct strings are obtained from "abab" by cyclic rotations (including the rotation by 0)?
- Problem: What is the minimum number of character replacements needed to make "abcdba" a palindrome?
- Problem: In how many ways can 100 be made using coins 1, 5, 10, 25 (order does not matter)?
- Problem: How many binary strings of length 5 contain no three consecutive 1s?
- Problem: Stock trading allows unlimited transactions, but after selling you must wait one day before buying (cooldown). Prices are [1, 2…