Dsa
Queue
Easy
The Spice Leveler
A food critic is testing spicy dishes. The critic has an initial spice tolerance. Dishes are in a queue. If the dish at the front has a spice level less than or equal to the critic's current tolerance, they eat it, and their tolerance increases by 1. If the dish is too spicy, they move it to the back of the queue and wait. The process stops if the critic successfully eats all dishes, or if they have cycled through the entire remaining queue without being able to eat a single dish. Print the spice levels of the dishes eaten in order.
Example:
Input:
1
2 1 3
Output:
1 2 3
Key concepts
queuesimulationrotation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now