This is the question that I asked. I want an answer that is based on the approach that I gave. It's not complete so I cannot post the solution on the question linked as a duplicate. I request for reopening of this post. Please no further downvotes for being duplicate since I had used Approach zero but it couldn't find any question.