You are given a string s and a character ch. Your task is to remove all occurrences of the given character from the string. Loops or built-in replace functions are not allowed. Return the final string after removal.
Example 1
Input: s = "banana", ch = 'a'
Output: "bnn"
Explanation: All occurrences of 'a' are removed from the string.
Example 2
Input: s = "hello", ch = 'l'
Output: "heo"
Explanation: Both 'l' characters are removed.
Example 3
Input: s = "abc", ch = 'x'
Output: "abc"
Explanation: The character is not present, so the string remains unchanged.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
banana a
bnn
hello l
heo