I recently encountered a situation when のwas used and want to know if either of the terms can be used interchangeably. Thank you.
Not exactly replace.
の particle can be used for questions or answers, it means that you're either seeking explanation or explaining something.
The only grammar rule here is that if it is preceded by a NA-Adjective or a Noun you need to add な before the の.
どこ行くの？(doko iku no?) - Where are you going?(seeking explanation) - Informal.
どこに行くのですか？(doko ni iku no desu ka?) - Where are you going (seeking explanation) Formal.
どこ行くのか？(doko iku no ka?) - Where are you going (seeking explanation) informal but the か gives more emphasis to your question.
I often see people saying that ending answers and questions with の may sound a bit feminine, so in order to avoid it you should end your sentence with だ、です、ですか, depending if it's an answer or question.
Also you could abbreviate の to ん.
どんな車好きなんだ？(don'na kuruma suki nanda?) - What kind of car do you like? (seeking explanation) Informal.
速い車好きなんだよ！(hayai kuruma suiki nanda yo!) - I like fast cars! (Explaining) informal.
何をしてるんですか？(nani wo shiterun desuka?) - What re you doing?(seeking explanation) somewhat formal.