The tvdenoising package provides an implementation of an efficient
linear-time dynamic programming algorithm for univariate total variation
denoising (also called fused lasso signal approximation), due to
Johnson (2013), which
computes the exact solution, for a given regularization level $\lambda$.
You can also find a concise explanation of the algorithm at this
link.

To install the released version from CRAN:
install.packages("tvdenoising")
To install the development version from GitHub:
# install.packages("pak")
# pak::pak("glmgen/tvdenoising")
install.packages("tvdenoising", repos = c('https://glmgen.r-universe.dev', 'https://cloud.r-project.org'))