Problem Description
Create a function to simulate the process of clearing debris from a construction site represented as a string. The function should efficiently remove debris while following specific rules.
Requirements
Input
- A string
s representing the construction site
- Stars (
*) represent debris
- Non-star characters represent clear areas
Rules
- In each operation, you can remove:
- One piece of debris (star)
- The closest non-debris object (character) to its left
- The process continues until all debris is removed
- The function should maintain the relative order of remaining characters
Output
- Return the resulting string after all debris has been removed
- The output should only contain non-star characters
- Characters should maintain their relative positions from the input
Example
Input: "abc*de*fghi*jk!"
Output: "abdfghjk!"
Explanation:
1. First operation: Remove '*' and 'c' -> "abde*fghi*jk!"
2. Second operation: Remove '*' and 'e' -> "abdfghi*jk!"
3. Third operation: Remove '*' and 'i' -> "abdfghjk!"
Test Cases
# Test Case 1
input: "abc*de*fghi*jk!"
expected: "abdfghjk!"
# Test Case 2
input: "a*b*c*d"
expected: "d"
# Test Case 3
input: "abcd"
expected: "abcd"
# Test Case 4
input: "****"
expected: ""
Function Signature
def remove_debris(s: str) -> str:
pass
Constraints
- 1 ≤ s.length ≤ 10^5
- s consists of lowercase English letters, stars (*), and possibly other printable characters
- The input string will be valid according to the problem description
Notes
- Focus on efficiency in the implementation
- Consider edge cases like:
- String with no debris
- String with only debris
- String with alternating debris and non-debris
- String with multiple consecutive debris pieces
Problem Description
Create a function to simulate the process of clearing debris from a construction site represented as a string. The function should efficiently remove debris while following specific rules.
Requirements
Input
srepresenting the construction site*) represent debrisRules
Output
Example
Test Cases
Function Signature
Constraints
Notes