Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    Thank you for the great answer. I'm humbled to be beaten by a research engineer at Google :D After giving my answer, I was wondering about mathmatical approahces and how we could refactor and summarize the task to reduce TC. I would have never figured out such an answer as yours. Some of the parts of your approach are entirely new to me. I'm still trying to understand it lol. But I learned one thing (again). Write out simple examples. I was doing it in my head. I have experienced this time and again. But fail to do it most of the times. Thanks again. Commented Jan 26, 2022 at 8:33
  • I tried reading your answer several times but I am not able to understand how to come up with a program based on your answer, can you please help me with a java code or python code for this. Commented Feb 7, 2022 at 16:08