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
s2 how will you check if
s1 is a rotated version of
s1 = "stackoverflow" then the following are some of its rotated versions:
"tackoverflows" "ackoverflowst" "overflowstack"
"stackoverflwo" is not a rotated version.
The answer he gave was:
s2and find the longest prefix that is a sub string of
s1, that will give you the point of rotation. Once you find that point, break
s2at that point to get
s2b, then just check if
concatenate(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