Ad
  • Custom User Avatar

    While this solution is intuitive, in practice it is costly!
    Keep in mind that strings are contiguous containers and its elements must always be laid out in memory one after another.
    Hence, every time you erase a character, the program will have to "move" (copy) elements that come after it to fill the gap.
    In a worst case scenario where all characters are same (i.e. "aaaaaaaaaaaaaaaaa") it will have to perform many iterations and copies,
    with a significant impact on code performance.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution