Fork me on GitHub

teddy online judge

teddy es un oso de peluche

78. Interview Question

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 of s1, that will give you the point of rotation. Once you find that point, break s2 at that point to get s2a and 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.

Input

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.

Output

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?"

Example input and output

2
stackoverflow
tackoverflows
stackoverflow
stackoverflwo
Yes
No
Do I get the job?


Asked Mar 31 at 13:58 on StackOverflow by Webdev

Hecho por Alan Gonzalez @_alanboy ; Concepto Luis Hector Chavez @lhchavez ; Infraestructura por Instituto Tecnologico de Celaya

contribuciones de los usuarios bajo la licencia cc-wiki con atribucion requerida