FastPrepWildcard Character Array Match

Wildcard Character Array Match

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Given pattern and target, determine whether the array can represent the target string.

Each pattern entry is either a one-character string that must match the target at the same index, or the empty string, which is a wildcard matching any one lowercase English letter. The lengths must be equal.

Function

matchesWildcardArray(pattern: String[], target: String) → boolean

Examples

Example 1

pattern = ["a","","c"]target = "abc"return = true

The empty middle entry matches b.

Example 2

pattern = ["a","b"]target = "ac"return = false

The literal b does not match target character c.

Example 3

pattern = []target = ""return = true

Two empty sequences match.

Constraints

  • 0 <= pattern.length,target.length <= 200000.
  • Each pattern entry is empty or one lowercase English letter.
  • target contains only lowercase English letters.

More Google problems

See Google hiring insights
public boolean matchesWildcardArray(String[] pattern, String target) {
    // Write your code here.
}
pattern["a","","c"]
target"abc"
expectedtrue
Checking account…