Given two strings s1 and s2, return true if s2 is a rotation of s1. A rotation is formed by taking some number of characters from the beginning of a string and moving them to the end. For example, "cdeab" is a rotation of "abcde" because moving "ab" from the front to the end produces "cdeab". Return false if either input is null or if the strings have different lengths.

Examples:

Input: s1 = 'abcde', s2 = 'cdeab' Output: true Explanation: 'cdeab' is formed by moving 'ab' from the front of 'abcde' to the end Input: s1 = 'abc', s2 = 'bca' Output: true Explanation: 'bca' is a left rotation of 'abc' by one position Input: s1 = 'abc', s2 = 'abcd' Output: false Explanation: The strings have different lengths so s2 cannot be a rotation of s1 Input: s1 = null, s2 = 'abc' Output: false Explanation: Null input returns false Input: s1 = 'abc', s2 = 'xyz' Output: false Explanation: 'xyz' is not a rotation of 'abc'
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 August 2026

Contest runs August 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