Question bank › Queue
Dsa Queue Hard

The Bidirectional Pivot Conveyor

A conveyor belt is represented as a sequence of items. A robotic arm always picks the item at the 'Pivot' (index floor(length/2)). When an item is picked, the belt must be rebalanced: 1. If an 'L' command arrives, a new item is added to the left end. 2. If an 'R' command arrives, a new item is added to the right end. 3. If a 'P' command arrives, the robot removes the item at the current Pivot. 4. After removal, the remaining items shift to close the gap. If the new length is L, the next pivot is floor(L/2). Input: N commands. Each is `L item`, `R item`, or `P`. Output: For each `P`, print the item removed. Finally, print the items remaining on the belt from left to right. Example: Input: 6 L A R B L C P P R D Output: A C B D

Key concepts

dequesimulationindexing

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.