teddy online judge |
|
|
teddy es un oso de peluche |
Limite de tiempo : 1 seg. Total runs : 180 Aceptados : 59
A friend of mine was asked the following question today at interview for the position of software developer:
Given two string s1
and s2
how will you check if s1
is a rotated version of s2
?
Example:
If s1 = "stackoverflow"
then the following are some of its rotated versions:
"tackoverflows"
"ackoverflowst"
"overflowstack"
where as "stackoverflwo"
is not a rotated version.
The answer he gave was:
Take
s2
and find the longest prefix that is a sub string ofs1
, that will give you the point of rotation. Once you find that point, breaks2
at that point to gets2a
ands2b
, then just check ifconcatenate(s2a,s2b) == s1
It looks like a good solution to me and my friend. But the interviewer thought otherwise. He asked for a simpler solution. Please help me by telling how would you do this ?
Thanks in advance.
A line with an integer N, which is the number of following test cases. Then 2N lines follow. Each test case conains a pair of strings, s1 and s2, each one on its own line. s1 and s2 can have lower, upper case letters and numberes. No spaces. The matches must be case sensitive.
For each test case, print a line containg 'Yes' if s1 is a rotated version of s2, print 'No' otherwise. When you are done with the test cases print the line "Do I get the job?"
2 stackoverflow tackoverflows stackoverflow stackoverflwo |
Yes No Do I get the job? |
Asked Mar 31 at 13:58 on StackOverflow by Webdev