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 input

Input: 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
0
class Solution {
public:
string removeCommonCharacters(const string& str1, const string& str2) {
// Your code goes here
}
};
Test Case

Input:

Str1
Str2