This post is completed by 1 user

  • 1
Add to List
Beginner

Check if one string is Rotation of another string

Objective: Write an algorithm to check if one string is Rotation of another string. This question has been asked in the Amazon interview.

Example:

Input Strings : 'sumitjain' and 'tjainsumi'
Output : true

Input String : 'Jaain' and 'ainJ'
Output: false

Input: Two Strings

Output: True or false based on whether strings are rotation of each other.

Approach:

  • Make a new String by appending the appending the first string with itself
  • Check if second string is sub string of new String
Check if one string is Rotation of another string
Check if one string is Rotation of another string

Code:


Is 'sumitjain' and 'tjainsumi' are rotated?? : true



Also Read: