Hi Anish, this sounds like an interesting question to me! I have a lot to say but I'll try to be concise :) My answer here is just a personal opinion because everyone is unique.
I am, by no means, a successful developer or anything. In fact, I'm still learning and constantly trying to improve. Over the weekend, I read a book called "Mastery" by Robert Greene.
In that book, it tells the stories of exemplary people like Charles Darwin, Albert Einstein, Wolfgang Mozart and uncovers the reasons/processes on how these people can be so focused and dedicated in their craft to the point of mastery. Though I haven't finished the book, I can tell you that I learned that their focus comes from them pursuing fields they have a deep natural, instinctual inclination to. Basically, they found their calling and it naturally keeps them on the path to focus and mastery. I really enjoyed the book so far. I recommend anyone to read it!
Some tips I have to get started being more focused:
Thanks for the question. I hope my answer helps you a little!