Problema
Mostra originale (inglese)Ruota la lista verso destra di steps posizioni: l'ultimo elemento si sposta in testa, per steps volte.
Implementa rotate_right(numbers, steps).
Input
numbers: La lista di interi. steps: Quante posizioni ruotare.
Output
Restituisci la lista ruotata.
Vincoli
0 ≤ length ≤ 100.000; 0 ≤ steps ≤ 10⁹
Esempi
Input:
steps = 2
numbers = [1, 2, 3, 4, 5]
Output atteso:
expected = [4, 5, 1, 2, 3]
Input:
long long steps = 2;
std::vector<long long> numbers = {1, 2, 3, 4, 5};
Output atteso:
std::vector<long long> expected = {4, 5, 1, 2, 3};
Input:
long steps = 2;
long[] numbers = new long[] {1, 2, 3, 4, 5};
Output atteso:
long[] expected = new long[] {4, 5, 1, 2, 3};
Spiegazione
Due rotazioni a destra: [5, 1, 2, 3, 4], poi [4, 5, 1, 2, 3].
Input:
steps = 3
numbers = [1, 2, 3]
Output atteso:
expected = [1, 2, 3]
Input:
long long steps = 3;
std::vector<long long> numbers = {1, 2, 3};
Output atteso:
std::vector<long long> expected = {1, 2, 3};
Input:
long steps = 3;
long[] numbers = new long[] {1, 2, 3};
Output atteso:
long[] expected = new long[] {1, 2, 3};
Spiegazione
Ruotare per la lunghezza riporta la lista all'origine: [1, 2, 3].
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.