Sliding-window averages yield non-optimal trimming. There are only two programs that I am aware of that currently implement optimal trimming, seqtk and BBDuk. Both use the Phred algorithm, which is provably optimal. I assume the original implementation exists somewhere, presumably here, but I have never tried it.
Anyway - if you want optimal quality-trimming, you should use BBDuk or seqtk. For example:
bbduk.sh in=reads.fq out=trimmed.fq qtrim=rl trimq=10
That will optimally trim reads such that leading or trailing portions with average quality below 10 will be removed, and therefore, will solve @Goutham Atla's problem. Actually, BBDuk supports window-average trimming as well, and it's much faster than Trimmomatic in doing so, but I don't recommend it, because it's provably inferior to optimal trimming; so, I won't disclose the flags, as it promotes bad science.
There are a lot of quality-trimming programs out there today. I have tested every one I could find, and they are all (apart from seqtk and BBDuk) empirically as well as theoretically inferior to optimal trimming.