簡単 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用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。