Insight
When the solution to a problem comes to you in an all-of-a-sudden manner, it can be considered insight. More specifically, insight can be defined as the sudden and often novel realization of the solution to a problem. This is the opposite type of solution to trial-and-error solutions.
Related Term: Insight Learning