794. Remove Characters from First String Present in the Second String
You are given two strings str1 and str2. Your task is to remove all characters from str1 that are present in str2, and return the modified str1.
Characters in str2 can appear in any order and may repeat.
The relative order of characters in str1 must be preserved.
Example 1:
Input: str1 = "abcdef", str2 = "cefz"
Output: "abd"
Explanation: Characters 'c', 'e', and 'f' are in both strings, so removed from str1.
Example 2:
Input: str1 = "xyzpw", str2 = "lmno"
Output: "xyzpw"
Explanation: No characters are common, so str1 remains unchanged.
Now Your Turn!
Pick the correct output for the given inputInput: str1 = "hello", str2 = "aeiou"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= str1.length, str2.length <= 105
- Both strings contain only lowercase English letters