Consider the numbers between 1-10: 2,3,4,5,6,7,8,9
The fact that neither of them knows the other person's number so they cannot have the extreme values, that are, 2 & 9.
So we are left with 3-8.
If A can immediately guess the number when B doesn't have the solution that means A has a 3 or a 8 and B a 4 or a 7 respectively.
Answer: A=3, B=4
Case 2: Similarly A and B can interchange positions
So these are the four cases.
Hope it answers your question.