Tap here to switch tabs
Problem
Submissions

Problem: Match Substring After Replacement

Match Substring After Replacement asks whether sub can be changed using the given mappings, with each character changed at most once, to become a contiguous substring of s.

Statement

You are given two strings, s and sub, along with a 2D character array mappings, where mappings[i] = [old_i, new_i] indicates that any occurrence of the character old_i in sub can be replaced with new_i. Each character in sub may be replaced at most once, and characters in s cannot be replaced.

Return true if it is possible to make sub a substring of s after replacing zero or more characters in sub using the given mappings. Otherwise, return false.

Note: A substring is a contiguous non empty sequence of characters within a string.

Constraints:

  • 1≤1 \leq sub.length ≤\leq s.length ≤5000\leq 5000

  • 0≤0 \leq mappings.length ≤1000\leq 1000

  • mappings[i].length =2= 2

  • old_i ≠ new_i

  • s and sub consist of uppercase and lowercase English letters and digits.

  • old_i and new_i are either uppercase or lowercase English letters or digits.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Match Substring After Replacement

Match Substring After Replacement asks whether sub can be changed using the given mappings, with each character changed at most once, to become a contiguous substring of s.

Statement

You are given two strings, s and sub, along with a 2D character array mappings, where mappings[i] = [old_i, new_i] indicates that any occurrence of the character old_i in sub can be replaced with new_i. Each character in sub may be replaced at most once, and characters in s cannot be replaced.

Return true if it is possible to make sub a substring of s after replacing zero or more characters in sub using the given mappings. Otherwise, return false.

Note: A substring is a contiguous non empty sequence of characters within a string.

Constraints:

  • 1≤1 \leq sub.length ≤\leq s.length ≤5000\leq 5000

  • 0≤0 \leq mappings.length ≤1000\leq 1000

  • mappings[i].length =2= 2

  • old_i ≠ new_i

  • s and sub consist of uppercase and lowercase English letters and digits.

  • old_i and new_i are either uppercase or lowercase English letters or digits.