DSA interview question
A digital signage screen cycles through a fixed list of adverts: every minute, the advert at the front moves to the back and everything else shifts forward one slot. Represented as an array, that's a left rotation by one: [A, B, C, D] becomes [B, C, D, A]. It has to happen in place, since the screen's controller has almost no spare memory. It's a tiny problem, but it sets up the "rotate by K" problem that follows and practises shifting elements without losing the one you overwrite first.
Example: [1, 2, 3, 4, 5] → [2, 3, 4, 5, 1].
void leftRotateByOne(vector<int>& a); // in place
Input a | Output | Explanation |
|---|---|---|
[1, 2, 3, 4, 5] | [2, 3, 4, 5, 1] | The first element moves to the end |
[1, 2] | [2, 1] | |
[3] | [3] | Nothing changes |
[] | [] | Nothing to rotate |
[9, 9, 1] | [9, 1, 9] | Duplicates are fine |
(Confirm: rotate in place with O(1) extra space.)
a[0] first?"On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in