I can\'t figure out if the following implementation is optimal in time. It returns correct answers BTW. I researched GeeksforGeeks\' implementation but I considered it stran