Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Remove All Occurrence of A Character

Easy Acceptance 75.00% Points 20.00

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.

Examples
Example 1

Example 1

Input: s = "banana", ch = 'a'

Output: "bnn"

Explanation: All occurrences of 'a' are removed from the string.

Example 2

Example 2

Input: s = "hello", ch = 'l'

Output: "heo"

Explanation: Both 'l' characters are removed.

Example 3

Example 3

Input: s = "abc", ch = 'x'

Output: "abc"

Explanation: The character is not present, so the string remains unchanged.

Hints
Hint 1
N/A
Constraints
  • 1 = length of s = 105
  • The string contains printable characters only
Companies
Apple Wipro Media.net
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions