Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A pattern-matching task uses the string "abxcabcyabd" and the target "abc". How many length-3 windows of the text differ from "abc" in exactly one position (Hamming distance 1)?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Count windows by Hamming distance: exactly one mismatched position. Counting windows that contain the letters of the pattern in any order counts a different set.
More Coding Interview Problems questions
- Problem: Using shell-style wildcards ( matches any run of characters including empty, ? matches exactly one character), how many words in…
- Problem: Choose a subsequence of [2, 3, 5, 7, 8] with no two chosen elements at adjacent positions. How many such non-empty choices sum to…
- Problem: The egg-dropping puzzle with 2 eggs and a 10-floor building: what is the minimum number of drops needed in the worst case to find…
- Problem: How many ways can 10 be made using coins {1, 2, 5} where order does not matter (combinations of coin counts)?
- Problem: On a 3×3 matrix [[9,9,4],[6,6,8],[2,1,1]], a strictly increasing path moves up, down, left or right between adjacent cells with…
- Problem: The Collatz sequence starts at n = 27 and repeatedly applies: n → n/2 if n is even, n → 3n+1 if n is odd, until n = 1. How many…