Data Structures & AlgorithmsHardTCS NQT · Infosys

Problem: Using shell-style wildcards (* matches any run of characters including empty, ? matches exactly one character), how many words in ["ab", "acb", "abcb", "axxbz", "abb"] match the pattern "a*b?"?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

The pattern requires a leading a, a later b, and exactly one trailing character after that b. Words whose last character is the b itself do not match, because ? must consume a character.

More Coding Interview Problems questions

Exams that ask this topic