Hacker News new | ask | show | jobs
by masterof0 1584 days ago
Came here to say this, as far as LC questions go, this one is pretty straight forward. OP, the way you come up with a solution like this is practice and more practice, the same way you can solve an equation you never seen before, because you have a set of tools (patterns, "tricks", knowledge, ...) that allows you to come up with a solution. Keep practicing and you will see the progress.
1 comments

OP meant O(1) in time and space (forgot the space but it’s in the linked article). That solution is O(N) in space.