A Simple Algorithm to Filter / Smooth / Denoise a Noisy Staircase Graph
Assuming you meant to produce something similar to the green line:
What about
$$\text{output}[n] = \max\{\text{input}[n-k], \text{input}[n-k+1], \ldots ,\text{input}[n]\}$$
i.e. you just find the maximum along a sliding window over the last $k$ input values?