Wildcard Substring Match
Updated
Problem statement
Given two strings text and pattern, return true if pattern matches some substring of text, and false otherwise.
The pattern is read from left to right:
*matches any run of characters, including an empty run.- A backslash makes the next character plain:
\*matches one*character, and\\matches one backslash. - Every other character matches only itself.
A substring is a contiguous part of text. Characters in text are always plain, including * and backslashes.
Examples write strings as code literals, so "e\\*1" is the four characters e, \, * and 1.
Function
matchesSubstring(text: String, pattern: String) → booleanExamples
Example 1
text = "bankofamerica"pattern = "kof*ica"return = trueThe substring "kofamerica" matches: "kof" matches itself, * covers "amer", and "ica" matches itself.
Example 2
text = "bankofamerica"pattern = "ame*bank"return = false"bank" appears only at the start of text, before "ame". No substring starts with "ame" and later has "bank".
Example 3
text = "rate*10"pattern = "e\\*1"return = trueThe backslash makes the * a plain star, so the pattern matches only "e*1", which appears in text.
Example 4
text = "rate10"pattern = "e\\*1"return = falsetext has no * character, so "e*1" cannot be found. Without the backslash, the pattern "e*1" would match "e1".
Constraints
1 <= text.length <= 10001 <= pattern.length <= 1000textandpatternconsist of lowercase English letters, digits,*and backslashes.- Reading
patternfrom left to right, each backslash that is not itself escaped is followed by*or another backslash.
More Bank of America Online Assessment questions
- Return Exact Cash Register ChangeOA · Seen Aug 2026
- Sum Skipping Multiples of 7OA · Seen Nov 2025
- Maximum String BeautyOA · Seen Sep 2024
- Merge Point of Two Linked ListsOA · Seen Oct 2023
- Remove Duplicates from a ListOA · Seen Oct 2023
- Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
- Count Level-Order Traversals of a TreeOA · Seen Sep 2023
- Count Set BitsOA · Seen Sep 2023
- Count Pairs with Sum KOA · Seen Jun 2023
- Letter Pattern SumOA · Seen Sep 2022
Similar questions at other companies
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
- Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions