Longest Common Ending
Write a function that returns the
longest common ending between two strings. Examples
longestCommonEnding("multiplication", "ration") ➞ "ation"
longestCommonEnding("potent", "tent") ➞ "tent"
longestCommonEnding("skyscraper", "carnivore") ➞ ""
Return an empty string if there exists no common ending.
this is working but as you can see it will return array type result can it be ok??
sorry i forget about if no similar end so here it is
it’s about 29 blocks
this is working
well, it is not working ;-)… try the words
multiplication and noitac
hmm you are right it is not working there…
i quit this i don’t think i can trying for 45 minutes hard to do
should i delete my post??
No, you gave it a try and came far. Good job.
I have used linear and reverse loop to check & match the characters of Word A with Word B. In liner loop if the sreing is not empty it’ll display the result, else if the sreing is empty then it’ll run a reverse loop and check the charecters again… and then display the result.
with this method i tried these and i got the result as
Also if i’m wrong then please let me know…
@Hossein the solution to the last example shoulld be
t rather than
This seems to work
the solution for
potent and tnet should be t rather than empty string…
Not according to
@Peter requirement. I think should be empty string. That’s why I was also returning empty string
You were right, I hope this one does the job
potent and pot, both words end with t… as well as potent and tnet… so isn’t that the longest common ending then?
Aha, then I think I misunderstood the full requirement