Problem: Given two string s1 and s2 how will you check if s1 is a rotated version of s2 ?
If s1 = “crazyforcode” then the following are some of its rotated versions:
“forcodecrazy”
“codecrazyfor”
Solution:
Steps:
First need to check if s1 and s2 are of the same length.
Then check, if s2 is a substring of s1 concatenated with s1.
boolean checkRotation(string s1, string s2) { if(s1.length() != s2.length()) return false; if( substr(s2,concat(s1,s1)) return true; return false; }