Solved Rotate String problem in Java with simple observation

#100DaysOfCode – Day 72 Rotate String Task: Given two strings s and goal, check if s can become goal after some number of shifts. Example: Input: s = "abcde", goal = "cdeab" → Output: true My Approach: Checked if both strings have the same length. Concatenated the original string: s + s. Verified if goal exists as a substring in the doubled string. Time Complexity: O(N) Space Complexity: O(N) Sometimes, the simplest observation can make a problem effortless like checking if goal exists inside s + s. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #StringManipulation #CodeNewbie #DSA #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories