Skip to content
ExamSpine

Lesson 5.6 · Write it

Move the first to the end

A functionPython or Java8 tests, 5 of them hidden

On a phone? Put the lines in order instead

Write a function that takes the first value out of a list of whole numbers, adds it to the end, and returns the list.

  1. The list has at least one value.
  2. Every other value moves down one index.
  3. A list of one value comes back unchanged.
  4. In Java, the list is an ArrayList<Integer>.

Only the list your function returns is checked.

def move_first_to_end(values: list[int]) -> list[int]

Examples

Your function is tested on 8 cases: the 3 examples below, and 5 hidden ones that check the rules above.

  • move_first_to_end([3, 8, 5]) should return [8, 5, 3]: the 3 leaves the front and joins the end (rule 2)
  • move_first_to_end([7]) should return [7]: one value (rule 3)
  • move_first_to_end([1, 2]) should return [2, 1]: two values change places (rule 2)

public static ArrayList<Integer> moveFirstToEnd(ArrayList<Integer> values)

Checking whether Java answers can run here.

Examples

Your function is tested on 8 cases: the 3 examples below, and 5 hidden ones that check the rules above.

  • moveFirstToEnd([3, 8, 5]) should return [8, 5, 3]: the 3 leaves the front and joins the end (rule 2)
  • moveFirstToEnd([7]) should return [7]: one value (rule 3)
  • moveFirstToEnd([1, 2]) should return [2, 1]: two values change places (rule 2)
solution.pySolution.java