Ex: - "code" "odec" ( rotating "code" 1 time left gives "odec" ) Algorithm : To check for "code" and "deco" Choose a string and concatenate it to itself ( for ex:- here , we choose "deco" you can choose "code" also.) ==> ("deco" + "deco" =="decodeco") Now take another string and check whether it is present in the string generated in step 1. ( 2nd string is "code" we have to check whether "code" is present in "decodeco". if present print "YES" otherwise "NO". here "code" is present in "de code co" so the answer is "YES". The same approach is followed to solve this question See below. Java 1 2 3 4 5 6 7 8 9 10 11 12 13 import java.util.Scanner; public class CheckTwoStringRotation { public static void main (Strin...
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.