First, recognise that to exchange $2 notes for $5 notes, the amount of $2 notes must be exchanged in multiples of $10. Meaning, Stan exchanged 5 pieces of $2 notes for 2 pieces of $5 notes. Therefore, there is a reduction of 3 pieces of notes in the total quantity after each exchange.
Next, for the quantity of $2 notes and $5 notes to be equal in the end, Stan must have an even number of notes in the end. From the above, we know that each exchange reduces the total quantity by 3. Since the starting quantity was 15, Stan must have made the exchange 1 time (15 – 3 = 12), or 3 times (15 – 9 = 4).
The end quantity cannot be 15 – 9 =4 (2 pieces of $2 notes and 2 pieces of $5 notes) because if Stan had exchanged $2 notes for $5 notes 3 times, he should have minimally 6 pieces of $5 notes, not the 2 pieces computed.
So the only logical answer is 15 – 3 = 12 for 6 pieces each of $2 and $5 notes.
To present all the above mathematically….

$2 
$5 
Initial quantity 
u 
15 – u 
End quantity 
u – 5 
15 – u + 2 = 17 – u 
Since Stan had equal quantity in the end,
u – 5 = 17 – u
2u = 22
u = 11
Quantity of $5 notes in the end > 17 – u = 17 – 11 = 6