FastPrepNumeric Wildcard Dictionary Matching
Problems/Numeric Wildcard Dictionary Matching

Numeric Wildcard Dictionary Matching

Headlands Technologies logoHeadlands Technologies● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Headlands Technologies phone screen, told by voice. The report gives the base matching rule, as in b2e: a number in the pattern stands for exactly that many arbitrary characters. It also asks how to prepare a set of words so matching is faster. Here you get a fixed dictionary and a batch of queries. We chose how runs of digits are read, how zero works, the rule for leading zeros, lowercase input, returning indices, and the limits. The report did not need real code in a shared editor or one specific preparation method. Our version is about 70% the same as the reported question.

You are given a dictionary words and a query batch patterns. Match each pattern against every complete word.

  • A lowercase letter matches that same letter.
  • Read each full group of consecutive decimal digits as one nonnegative integer. It matches exactly that many characters, whatever those characters are.
  • A token 0 consumes no characters. Multi-digit tokens have no leading zero. All patterns follow this valid grammar.

For example, b2e matches base, while 10 consumes ten characters. There is no star wildcard and no choice of skip length.

Return an integer array for each query, containing the zero-based indices of its matching words in increasing order. Preserve repeated word occurrences and repeated queries. An empty pattern matches only an empty word. If no word matches a query, its result is an empty array. Do not modify either input.

Implement both a direct dictionary scan and a method that preprocesses the dictionary once for the query batch.

Function

numericWildcardMatches(words: String[], patterns: String[]) → int[][]

Examples

Example 1

words = ["base","bake","be","basse","bee"]patterns = ["b2e","b1e","4"]return = [[0,1],[4],[0,1]]

b2e matches base. It also matches bake, because 2 consumes exactly two characters; b1e matches bee, and 4 matches exactly four-character words.

Example 2

words = ["","a","ab","a"]patterns = ["","0","1","a0","0a"]return = [[0],[0],[1,3],[1,3],[1,3]]

An empty pattern or zero skip matches only the empty word. Duplicate word occurrences keep their separate indices; zero skips consume no characters.

Example 3

words = ["abcdefghij","abcdefghijk","abxyzghij","abcdefghij"]patterns = ["10","ab3ghij","a9"]return = [[0,3],[2],[0,3]]

The consecutive digits 10 form one ten-character skip, not skips 1 and 0. Full-word length and literal offsets determine each result.

Constraints

  • 0 <= words.length <= 200 and 0 <= patterns.length <= 50.
  • Each word has between 0 and 100 lowercase ASCII letters.
  • Each pattern has between 0 and 100 lowercase letters or decimal digits. A maximal digit run is either 0 or begins with 1 through 9.
  • A numeric token may be larger than a machine integer. Such a query cannot match if its required length exceeds 100; do not overflow while parsing it.
  • All inputs are valid.

More Headlands Technologies Phone Screen questions

  • Integer Compression OffsetPHONE SCREEN · Seen Oct 2026
  • Market Order BookPHONE SCREEN · Seen Jun 2026
  • Gradient Descent on a Sinusoidal ObjectivePHONE SCREEN · Seen Apr 2026
  • Pearson Correlation CoefficientPHONE SCREEN · Seen Apr 2026
  • Top K Frequent ElementsPHONE SCREEN · Seen Apr 2026
  • Queue Mean from Corrective SnapshotsPHONE SCREEN · Seen Mar 2026
  • Queue Mean QueriesPHONE SCREEN · Seen Mar 2026
  • CPU Register Bitwise OperationsPHONE SCREEN · Seen Nov 2025
  • Merge K Sorted SequencesPHONE SCREEN · Seen Oct 2024
  • Top Trade Events by NotionalPHONE SCREEN · Seen May 2024

Similar questions at other companies

  • Repeated DNA SequencesNVIDIA · PHONE SCREEN
  • Spelling Bee Word FilterBloomberg LP · PHONE SCREEN
  • Password Clues and the Next CommandOpenAI · OA
  • Longest Substring with Even OccurrencesDeloitte · OA
  • Count Magical Adjacent Substring TripletsGoogle · ONSITE INTERVIEW
  • Palindrome-Rearrangeable PairsExpedia · OA
  • Palindrome PermutationRippling · OA
  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Linked Merchants Within Two HopsStripe · PHONE SCREEN
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEW
See Headlands Technologies hiring insights
Saved
class Solution {
    public int[][] numericWildcardMatches(String[] words, String[] patterns) {
        // write your code here
    }
}
Checking account…