In Hostel Visit why normal Queue won't work instead of PriorityQueue?

In the Hostel Visit problem, I’m having the doubt why normal won’t work and instead only PriorityQueue is working.

Like in normal queue we can keep checking if the queue size is greater than K than we remove the current head value.

hi @Jorvis priority queue will maintain the distances in a sorted order, ie the top element will always give you Kth nearest hostel, you cannot maintain this functionality with a normal queue.

Oh correct!

Thanks! I now understanding where I was making mistake in my thought process.

1 Like

@Jorvis please mark the doubt as resolved if you dont have any further queries :slight_smile: