VOOZH about

URL: https://www.geeksforgeeks.org/dsa/remove-a-character-from-a-given-position/

⇱ Remove a Character from a Given Position - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Remove a Character from a Given Position

Last Updated : 23 Jul, 2025

Given a string and a position (0-based indexing), remove the character at the given position.

Examples:

Input : s = "abcde", pos = 1
Output : s = "acde"

Input : s = "a", pos = 0
Output : s = ""

Approach - By Using Built-In Methods

We use erase in C++, string slicing in Python, StringBuilder Delete in Java, substring in Java and slice in JavaScript.


Output
Output: acde

Time Complexity: O(n)
Auxiliary Space: O(1)

Approach - By Writing Your Own Method

We move all characters after the given position, one index back. To do this we mainly do s]i] = s[i+1] for all indexes i after p.


Output
acde

Time Complexity: O(n)
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: