Remove a Given Character From a String

Problem

Remove all occurrences of a given character c from a string s, producing the string with every c deleted and the remaining characters in their original order. Aim to do it in a single pass; discuss doing it in place where the language allows a mutable character buffer.

Input / Output

  • Input: a string s and a character c.
  • Output: s with all occurrences of c removed.

Constraints

  • 0 ≤ |s| ≤ 10^5
  • In languages with immutable strings, "in place" means operating on a mutable char array / buffer, not the string object.

Example

removeChar("banana", 'a') -> "bnn"
removeChar("aaaa", 'a')   -> ""     // empty result
added …
LeaderboardSalaryAccount