![]() |
VOOZH | about |
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 = ""
We use erase in C++, string slicing in Python, StringBuilder Delete in Java, substring in Java and slice in JavaScript.
Output: acde
Time Complexity: O(n)
Auxiliary Space: O(1)
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.
acde
Time Complexity: O(n)
Auxiliary Space: O(1)