------
## 最终结论
```python
def removeDuplicateLetters(s: str) -> str:
    last_occurrence = {c: i for i, c in enumerate(s)}
    stack = []
    seen = set()

    for i, c in enumerate(s):
        if c not in seen:
            while stack and c < stack[-1] and i < last_occurrence[stack[-1]]:
                seen.remove(stack.pop())
            stack.append(c)
            seen.add(c)

    return ''.join(stack)

# Example usage:
print(removeDuplicateLetters("bcabc"))  # Output: "abc"
print(removeDuplicateLetters("cbacdcbc"))  # Output: "acdb"
```