Backspace Apply

Backspace Apply

In a given string, replace character '#' with backspace. It means you need to remove the character before '#' (BS) and BS itself. The sequence of BSs shows how many chars should be removed before the sequence. If there is nothing to remove - only BS should be removed, so the final string has no BSs.

Input: String.

Output: String.

Example:

assert backspace_apply("name") == "name"
assert backspace_apply("name#") == "nam"
assert backspace_apply("na##me") == "me"
assert backspace_apply("nam#e#") == "na"
40