Given a list of integers and a rotation count, rotate the elements of the list to the right by that count. Elements at the end wrap around to the beginning. Return the rotated list. If the list is null or empty, return an empty list. If the rotation count is negative or zero, return the original list unchanged.

Examples:

Input: nums = [1, 2, 3, 4, 5], k = 2 Output: [4, 5, 1, 2, 3] Explanation: Rotating right by 2 moves the last 2 elements to the front Input: nums = [10, 20, 30], k = 5 Output: [20, 30, 10] Explanation: k=5 is equivalent to k=2 since k % 3 = 2, rotates by 2 positions Input: nums = [1, 2, 3], k = 0 Output: [1, 2, 3] Explanation: Zero rotation returns the original list unchanged
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay July 2026

Contest runs July 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In