How do people come up with intuitive solutions?
2361

I have been practicing LC for a while now and have solved ~30 problems (not all solutions are novel or my own solutions). Please see this problem -
https://leetcode.com/problems/first-missing-positive/

There is this solution posted.
https://leetcode.com/problems/first-missing-positive/discuss/17080/Python-O(1)-space-O(n)-time-solution-with-explanation
At first, I didn't understand what OP was trying to do, but after spending 30 minutes and reading multiple replies, I understood his solution.

How can people come up with such solutions? How is it possible to know such techniques during interviews without seeing or knowing problem beforehand? Beyond core algorithms and data structures, there seems to be a lot tricks and hacks that are implemented with use of indexes, trees, recursion etc.

What are ways to master such tactics for coming up with a novel solution?

Comments (4)