PPractick

DSA interview question

Left Rotate an Array by One

Easy · Algorithms · Topics: array

The problem

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].

Function signature

void leftRotateByOne(vector<int>& a);  // in place

Test cases

Input aOutputExplanation
[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.)

How interviewers phrase it

Clarifying questions to ask

  1. Left or right rotation?
  2. In place, or can I return a new array?
  3. Can the array be empty?

Follow-ups to expect

  1. "Why save a[0] first?"
  2. "How would you rotate right by one?"
  3. "Is there a library function?"
  4. "What if you had to rotate by k?"
  5. "Complexity?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in