L&T Mindtree · Question 31 · Queues
Design Circular Queue
Problem
You are required to implement a circular queue with fixed size.
Approach
Track front, rear, size and capacity; wrap indices with modulo.
Time O(1)Space O(k)
How it works
- 1Rear advances on enqueue, front on dequeue, both modulo capacity.
- 2Size alone answers full/empty checks.
Sample input / output
Input: k = 3, ops = [enQueue(1), enQueue(2), enQueue(3), enQueue(4), Rear(), isFull(), deQueue(), enQueue(4), Rear()] Output: [true, true, true, false, 3, true, true, true, 4]
Constraints
1 <= k <= 1000; <= 3000 calls.
Solution — read it, then walk it
Time O(1)Space O(k)Branches 2Returns 2source · Java
Scroll sideways for wide charts — the view follows the active step.
- start / end
- statement
- condition
- loop
- returns
- definition
1/30
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits