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)?

  1. A. 2
  2. B. 3
  3. C. 1
  4. 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

Exams that ask this topic