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?"?
- A. 3
- B. 2
- C. 1
- 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
- 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…
- Problem: For the same Collatz process starting at n = 27, what is the largest value that appears in the sequence?