"Don't let it get personal" we've all watched a movie or read a book with this quote, it's usually said to a character that's going above and beyond what is necessary and sometimes crossing unethical lines. I believe this advice should also extend to software engineers. We need to learn to keep our work in the office, for those working remotely it simply means establishing working hours.
There are code challenges that drive software engineers nuts, the thing about these challenges is their ability to occupy our minds even when we're not coding. We need to understand that a code or algorithm challenge isn't an assault on our intelligence or skill, these impediments exist independently and are waiting to be solved. We all know a software engineer that's facing burnout, while we swear that it could never be us we still have to be conscious about our working hours. If you have no life outside of software programming then you're heading towards burnout.
There are times when you understand everything about a challenge, I can't tell you to stop and it's not like you'd listen to me then. There's nothing more euphoric than when you fully understand a problem and can solve it, every tap of the keyboard feels like you're creating your own symphony just like Mozart, it's beautiful and fulfilling. However, there are also times when you don't fully grasp what you're doing, you should avoid compounding your frustrations my obsessing over it. Let go, get some rest, interact with your loved ones and try again later.