We have all typed a long command and watched it die with permission denied. I used to press the up arrow and walk back to the start of the line. There is a shorter way.
In bash, !! expands to the previous command. Put sudo in front of it and the shell reruns the line as root.
$ apt update
E: Could not open lock file - Permission denied
$ sudo !!
sudo apt update
Bash prints the expanded line before it runs, so you see what you are about to do. If you are nervous, add :p (!!:p) and bash only prints the command and puts it in your history, without running it.
One caveat: it reruns exactly what you typed last, so be sure the last line is the one you mean. A destructive command with a sudo in front of it is still destructive. Zsh supports the same history expansion, so the habit travels.
This is the habit I would teach first to anyone new to the terminal. It costs nothing to learn and saves you a small irritation every day. Related shortcuts exist too: !$ gives you the last argument of the previous command, which is handy when you want to run something else on the same file.
Further reading: Bash manual: History Interaction, On this site: cd – takes you back to the last directory, On this site: sudo !! reruns your last command with sudo