def simplify_linux_dir_path(path): places = [p for p in path.split("/") if p != "." and p != ""] s = Stack() for p in places: if p == ".." and not s.is_empty(): s.pop() else: s.push(p) return "/" + '/'.join(s.get_list())
def build_lowest_number_removing_k_digits(num, k): s = Stack() l = len(num) - k for c in num: if not s.is_empty() and int(s.peek()) > int(c) and k > 0: s.pop() k -= 1 s.push(c) return ''.join(s.get_list()[:l])