So assuming the answer exists, s1 will either be of form:
(s2a*), (a*bs2a*ba*), (a*ba*bs2a*ba*ba*),...
or of form
(a*s'2ba*), (a*ba*s'2ba*ba*),...
where s'2 is the reverse of s2
So your question reduces to finding whether the regular expression
s1 = [(a*b)n s2 (a*b)n a*] V [a* (ba* )n s'2 (ba*)n+1]
holds true. You could use a regex library to parse and check it
If have to write the parsing algorithm ground up, you wouldn't even have to check for a*. You could get away with merely counting the number of b's to either side of s2
A pseudocode would be something like
B1 = number of b's in s2 //O(n)
B2 = number of b's in s1 //O(n)
//Locate s2 in s1 and check b_left = b_right and character before s2 is b
b_to_left = 0
for i from 1 to (s1's length - s2's length): //O(n iteration)
if s2.length characters of s1 starting at index i DO NOT match s2: //At worse O(n to check)
if(s1[i] is b) b_to_left++
continue to next i
b_to_right = B1 - B2 - b_to_left
if(b_to_left == b_to_right) :
if(b_to_left == 0) RETURN TRUE
else if(s[i-1] is b) RETURN TRUE
if(s1[i] is b) b_to_left++
//Similarly run another round and parse for the second type involving reverse of s2
//I'm leaving that out as an exercise for you since you mentioned it's an interview problem
RETURN FALSE
Time: O(n2)
Space: O(1)