Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: D. 0
Compare each character with the one two positions ahead. Comparing neighbours (distance one) answers a different question.
More Coding Interview Problems questions
- 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…
- Problem: Josephus with step 3: 10 people numbered 1 to 10 stand in a circle. Starting from person 1, count 3 people and eliminate the…