友達が教えてくれたのと同じようにカレーライスを作ったら、とても美味しく出来た。
The sentence appears in my Japanese textbook. To me, it sounds natural to join くれた with と同じ directly, but I don't know if it's also correct:
友達が教えてくれたと同じように…
What is the function of this の here, and is it absolutely necessary?
よろしくお願いします