class Solution:
def diStringMatch(self, S: str) -> List[int]:
"""tc O(N) sc O(N)
1. initialize left ptr and right ptr
2. go through S, check if s == 'D' or 'I'
3. if s == 'I', append left value; otherwise append right value
4. add the rest left ptr to the end
"""
res = []
n = len(S)
l = i = 0
r = n
while i <n :
if S[i] == 'I':
res.append(l)
l += 1
elif S[i] == 'D':
res.append(r)
r -= 1
i += 1
res.append(l)
return res