We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I completely understand this code and what it is accomplishing.
What I struggle with is seeing/finding a solution like this. What is your thought process? Can someone explain how one is supposed to just know to implement a solution like this? Is this just one of those problems where you just say "Hm, this smells like a prefix sum type of problem"? I didn't even know what a prefix sum was until doing this problem xD
I stared at this problem for some time, and I can tell you I would never have figured out this trick to solve the problem.
Just solve a lot of problems - make sure to really struggle with a problem for a while first before taking a peek at the comments/solutions. Make sure to understand the solution properly. Maybe add some comments to the code stating the invariants, and why they hold true throughout.
If the solution uses a new technique, read up on it. Search for other problems using the technique and solve those without peeking.
What we should be aiming at is deliberate practice - don't waste time solving easy problems, solve problems that are just hard enough where it may just be possible to solve it, but only after a lot of struggle
Almost everyone feels the same way, just with different levels of problems.
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
I completely understand this code and what it is accomplishing.
What I struggle with is seeing/finding a solution like this. What is your thought process? Can someone explain how one is supposed to just know to implement a solution like this? Is this just one of those problems where you just say "Hm, this smells like a prefix sum type of problem"? I didn't even know what a prefix sum was until doing this problem xD
I stared at this problem for some time, and I can tell you I would never have figured out this trick to solve the problem.
Any pointers would be much appreciated :D
It's just pattern matching, like any other skill.
Just solve a lot of problems - make sure to really struggle with a problem for a while first before taking a peek at the comments/solutions. Make sure to understand the solution properly. Maybe add some comments to the code stating the invariants, and why they hold true throughout.
If the solution uses a new technique, read up on it. Search for other problems using the technique and solve those without peeking.
What we should be aiming at is deliberate practice - don't waste time solving easy problems, solve problems that are just hard enough where it may just be possible to solve it, but only after a lot of struggle
Almost everyone feels the same way, just with different levels of problems.
Thank you for the help :)