We will start by eliminating the position where Spy can be. There are two lines of thoughts we can go for. For simplification, take Truth-teller to be ‘T’, Liar to be ‘L’ and Spy to be ‘S’. Now lets assume, they are standing in a line in front of me as #1,#2,#3.
Q1.) Ask #1: Consider the one in the other two who do not answer randomly. If I were to ask him if #2 is Spy, would he answer ‘yes’?
Now, if the answer is ‘Yes’ then there are four possibilities: STL, SLT, TLS, LTS
Q2.) Ask #2 if he’s the Spy? If he says “Yes” then #2 is Liar( Two possibilities: SLT, TLS). If he says “No” then #2 is Truth-Teller (Two possibilities: STL, LTS)
Q3.) Ask #2 if #1 is Spy? Its answer will eliminate one possibility in both the questions.
If the answer to Q1 is “No”, then there are four possibilities: TSL, LST, SLT, STL. Now #3 is not the spy. Hence ask #3 the Q2. If he says “yes” he is a Liar (TSL, STL), If he says “no” he is Truth-teller(LST, SLT). Now, ask #3 the Q3. It will eliminate one possibility in each case.
Hence, I got to know each and every one by asking 3 questions only.
Thanks:) Nice question:)