Легко Решено: 0 Процент решений: 0%

Rotate Array

Rotate a list to the right by some steps.

Rotate the list to the right by steps positions: the last element moves to the front, steps times.

Implement rotate_right(numbers, steps).

Input

numbers: The list of integers. steps: How many positions to rotate.

Output

Return the rotated list.

Ограничения

0 ≤ length ≤ 100,000; 0 ≤ steps ≤ 10⁹

Примеры

Пример 1
Ввод:
steps = 2
numbers = [1, 2, 3, 4, 5]

Ожидаемый вывод:
expected = [4, 5, 1, 2, 3]
Ввод:
long long steps = 2;
std::vector<long long> numbers = {1, 2, 3, 4, 5};

Ожидаемый вывод:
std::vector<long long> expected = {4, 5, 1, 2, 3};
Ввод:
long steps = 2;
long[] numbers = new long[] {1, 2, 3, 4, 5};

Ожидаемый вывод:
long[] expected = new long[] {4, 5, 1, 2, 3};

Пояснение

Two right rotations: [5, 1, 2, 3, 4], then [4, 5, 1, 2, 3].

Пример 2
Ввод:
steps = 3
numbers = [1, 2, 3]

Ожидаемый вывод:
expected = [1, 2, 3]
Ввод:
long long steps = 3;
std::vector<long long> numbers = {1, 2, 3};

Ожидаемый вывод:
std::vector<long long> expected = {1, 2, 3};
Ввод:
long steps = 3;
long[] numbers = new long[] {1, 2, 3};

Ожидаемый вывод:
long[] expected = new long[] {1, 2, 3};

Пояснение

Rotating by the length brings the list back: [1, 2, 3].

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.