As an undergraduate I too would frequently find that if, as I went to sleep, I concentrated on a problem I was having trouble solving that I would wake with the answer. This happened often enough that I began to rely on it.
Slightly strtanger was something that happened in high school. I was sitting in chemistry class looking straight ahead and day dreaming when suddenly I became aware of the teacher walking away from me. I asked the guy behind me what had happened and he told me the teacher had come up to me, asked me a question on what he had been lecturing (presumably to embarrass me for not paying attention) and that I had answered him, correctly. I was completely unaware of any of this transpiring. Similar sorts of things happened on a couple of other occasions.
One of my girlfriends would tell me that I had said such and such a thing to her first thing in the morning while we were still in bed... I'd have no recollection of these conversations and it turned out that we regularly had early morning conversations that, as far a I was concerned, had never occurred but that I knew, for various reasons, she wasn't just making up. I had to institute a "conversations don't count until I've had a cup of coffee rule"