While author indicates it should not be duplicates in the last searches, his code does.
The code seems working fine for me. Can you please give it a check again, or can you please elaborate on the problem again?
I think there is a discrepancy between how the task is stated vs what the solution is actually doing. The task makes it sound like should be no duplicates whatsoever displayed. In the solution, however, the task supposedly was to avoid consecutive duplicates. So the solution does what it’s supposed to do, but the task got switched.