Remove White Spaces from a String
Explore how to remove all white spaces from a null-terminated string by applying a two-pointer technique. Understand how read and write pointers work together to skip spaces and build a continuous string, optimizing the process with linear time and constant space complexity. This lesson helps you grasp essential string manipulation skills useful for coding interviews.
We'll cover the following...
We'll cover the following...
Statement
Given a null-terminated string, remove all the white spaces (tabs or spaces) present in the string.
Example:
Sample input
All greek to me.
Expected output
Allgreektome.
Let’s visualize this below:
Try it yourself #
Solution
This problem can be solved with two pointers. Here is an overview:
- Initialize
readandwritepointers to the start of the string. - With the