I had a really similar experience during college. I was trying to display a binary tree in the command line. I was not able to solve it while awake. I went to bed with that problem in my mind. Then I dreamt the solution. I woke up and the dream made sense. I couldn’t believe it so I tried in the code and it worked! That was a surreal experience.