Jupiter Money interview question

cumulative sum sql , with and without cte