Revision eb1bbe8c-182d-4835-825d-dda1944cfbaa - Code Golf Stack Exchange
# [Python 3.8], <sup><s>273</s> <s>303</s></sup> 297 bytes
Added 30 bytes to fix bugs kindly pointed out by [Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler).
<!-- language-all: lang-python -->
f=lambda a,b:(len(a)<len(b)and f(b,a))or len(a)>1and(len(b)>0and((a[0]==b[0]and f(a[1:],b[1:]))or(a[-1]==b[-1]and f(a[:-1],b[:-1]))or a[0]!=b[0]and a[-1]!=b[-1]and((x:=a[1:-1])==(y:=b[1:-1])or a[:-1]==y or a[1:]==y or a[:-1]==b[1:]or a[1:]==b[:-1]or x==b[:-1]or x==b[1:]or x==b))or b==''==a[1:-1])
[Try it online!][TIO-k8jthiw3]
[Python 3.8]: https://docs.python.org/3.8/
[TIO-k8jthiw3]: https://tio.run/##rZHJboMwEIbvPIV7si25UWjSJkJ1jn2C3pIcbCANEhgLnIWnpx6zBAiXSr14/vlmsz26Mudcrba6qOsTT0UmI4EEkwFJY0UE/QQjqVAROhHJBKV5gZrQzreUNPHdEjQR@@WRc2nPpkDs/eDIJJxQaP1X3yVY02UEVtsUMK459Hjpe7iKl76CkHvAoStkc06qgMvWc6WB618h59ipvQ7awZY9Ys1U69@nukkD6e4kOceY94Nrg6yPPSFDe8PIi9NYn4UyCIS1@ZichVbmOsPMg3XoQWQaZ04NkqbgCqphcJ@Ckws@XN426xCzRvkrTL0TPJlJlChEwkWp08QQjDBFEAgBm0VpikQT2kUPClMaeKjkdkdMUg/pIlEGNCtZsS85/y4u8ZF6o79Aq@kzrVhOnmmtP0T5TSi0nhI5RNkMm0fpFP207H3Moll2k@hjMPVvLBuxqoObIZxLBKafE59Zg7Zu1@1OWfjPW/0SaQlrrX8B "Python 3.8 (pre-release) – Try It Online"
**Linearity**
f=lambda a,b:
(len(a)<len(b) # linear lengths
and f(b,a)) # will only call recursively at most once
or len(a)>1and(len(b)>0 # linear lengths
and((a[0]==b[0] # test if the first characters are equal
and f(a[1:],b[1:])) # will only call recursively once for each character in prefix
or(a[-1]==b[-1] # test if the last characters are equal
and f(a[:-1],b[:-1])) # will only call recursively once for each character in suffix
or a[0]!=b[0]and a[-1]!=b[-1] # will only enter once after the prefix and suffix are removed
and(
(x:=a[1:-1])==(y:=b[1:-1])or # all that's left are linear tests for the
a[:-1]==y or a[1:]==y o # middle of the strings called at most once
a[:-1]==b[1:]or
a[1:]==b[:-1]or
x==b[:-1]or
x==b[1:]or
x==b))or
b==''==a[1:-1])