FPEvalDataset/LeetCodeProblem
0302
1{2 "id": 2393,3 "name": "match_substring_after_replacement",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/match-substring-after-replacement/",6 "date": "1653696000000",7 "task_description": "You are given two strings `s` and `sub`. You are also given a 2D character array `mappings` where `mappings[i] = [oldi, newi]` indicates that you may perform the following operation **any** number of times: **Replace** a character `oldi` of `sub` with `newi`. Each character in `sub` **cannot** be replaced more than once. Return `true`_ if it is possible to make _`sub`_ a substring of _`s`_ by replacing zero or more characters according to _`mappings`. Otherwise, return `false`. A **substring** is a contiguous non-empty sequence of characters within a string. **Example 1:** ``` **Input:** s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]] **Output:** true **Explanation:** Replace the first 'e' in sub with '3' and 't' in sub with '7'. Now sub = \"l3e7\" is a substring of s, so we return true. ``` **Example 2:** ``` **Input:** s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]] **Output:** false **Explanation:** The string \"f00l\" is not a substring of s and no replacements can be made. Note that we cannot replace '0' with 'o'. ``` **Example 3:** ``` **Input:** s = \"Fool33tbaR\", sub = \"leetd\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]] **Output:** true **Explanation:** Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'. Now sub = \"l33tb\" is a substring of s, so we return true. ``` **Constraints:** `1 <= sub.length <= s.length <= 5000` `0 <= mappings.length <= 1000` `mappings[i].length == 2` `oldi != newi` `s` and `sub` consist of uppercase and lowercase English letters and digits. `oldi` and `newi` are either uppercase or lowercase English letters or digits.",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]",12 "output": "true "13 },14 {15 "label": "Example 2",16 "input": "s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]]",17 "output": "false "18 },19 {20 "label": "Example 3",21 "input": "s = \"Fool33tbaR\", sub = \"leetd\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]]",22 "output": "true "23 }24 ],25 "private_test_cases": [],26 "haskell_template": "matchReplacement :: String -> String -> [[String]] -> Bool\nmatchReplacement s sub mappings ",27 "ocaml_template": "let matchReplacement (s: string) (sub: string) (mappings: string list list) : bool = ",28 "scala_template": "def matchReplacement(s: String,sub: String,mappings: List[List[String]]): Boolean = { \n \n}",29 "java_template": "public static boolean matchReplacement(String s, String sub, List<List<String>> mappings) {\n\n}",30 "python_template": "class Solution(object):\n def matchReplacement(self, s, sub, mappings):\n \"\"\"\n :type s: str\n :type sub: str\n :type mappings: List[List[str]]\n :rtype: bool\n \"\"\"\n "31}