DEV Community

Cover image for Day 73 of 100 days dsa coding challenge
Manasi Patil
Manasi Patil

Posted on

Day 73 of 100 days dsa coding challenge

Taking on a new challenge: solving GeeksforGeeks POTD daily and sharing my solutions! πŸ’»πŸ”₯
The goal: sharpen problem-solving skills, level up coding, and learn something new every day. Follow my journey! πŸš€

100DaysOfCode #CodingChallenge #ProblemSolving #GeeksforGeeks #DeveloperJourney

Problem:

https://www.geeksforgeeks.org/problems/check-if-strings-are-rotations-of-each-other-or-not-1587115620/1

Strings Rotations of Each Other

You are given two strings s1 and s2, of equal lengths. The task is to check if s2 is a rotated version of the string s1.
Note: A string is a rotation of another if it can be formed by moving characters from the start to the end (or vice versa) without rearranging them.

Examples :
Input: s1 = "abcd", s2 = "cdab"
Output: true
Explanation: After 2 right rotations, s1 will become equal to s2.
Input: s1 = "aab", s2 = "aba"
Output: true
Explanation: After 1 left rotation, s1 will become equal to s2.
Input: s1 = "abcd", s2 = "acbd"
Output: false
Explanation: Strings are not rotations of each other.
Constraints:
1 ≀ s1.size(), s2.size() ≀ 105
s1, s2 consists of lowercase English alphabets.

Solution:
class Solution:
def areRotations(self, s1, s2):
if len(s1) != len(s2):
return False
return s2 in (s1 + s1)

Top comments (0)