Ask HN: How to not fail on coding interview questions?
Several people have mentioned practicing on LeetCode problems. I&#x27;ve been doing LeetCode problems recently as exercises to refresh skills in languages I use infrequently but don&#x27;t want to forget too much of.<p>Here&#x27;s a tip that they either don&#x27;t tell you, or that I managed to overlook. You are allowed to mutate inputs.<p>I had assumed that inputs were read-only, and spent about three months trying to solve &quot;Given an array of N integers, find the smallest positive integer that is not in the array, in O(N) time and O(1) space&quot;. (It wasn&#x27;t three months of constantly working on it...it was more for three months it was one of my &quot;something to think about while falling asleep in bed or while sitting at a red light&quot; problems).<p>I then came across a site that talked about the problem and mentioned doing it in O(1) space involved overwriting the input. It was only a couple minutes to solve after that.<p>Possibly interesting variant of that problem: Can you still solve it in O(N) time and O(1) space if when your code returns the answer the input must be unchanged? You can still mutate the input while your code is running, but you have to undo any changes you make before returning.<p>I&#x27;m pretty sure that the answer to this is &quot;no&quot; in the general case, but if you are allowed to limit the size of the input so that N is not a significant fraction of MAXINT on your machine you can do it.