Numeric Wildcard Dictionary Matching
Updated
Problem statement
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
0consumes 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 <= 200and0 <= patterns.length <= 50.- Each word has between
0and100lowercase ASCII letters. - Each pattern has between
0and100lowercase letters or decimal digits. A maximal digit run is either0or begins with1through9. - 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