Peter
(Moderator)
October 21, 2019, 4:24pm
#1
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") ➞ ""
Notes
Return an empty string if there exists no common ending.
3 Likes
Peter:
multiplication
this is working but as you can see it will return array type result can it be ok??
edit:
sorry i forget about if no similar end so here it is
it’s about 29 blocks
1 Like
Taifun
October 21, 2019, 5:20pm
#3
parmarparth996:
this is working
well, it is not working ;-)… try the words multiplication and noitac
Taifun
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
1 Like
should i delete my post??
Peter
(Moderator)
October 21, 2019, 5:52pm
#6
No, you gave it a try and came far. Good job.
1 Like
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 cation
Also if i’m wrong then please let me know…
2 Likes
Taifun
October 22, 2019, 2:31am
#10
@Hossein the solution to the last example shoulld be t
rather than *empty string*
Taifun
Taifun
October 22, 2019, 12:46pm
#12
Boban:
This seems to work
the solution for potent and tnet should be t rather than empty string…
Taifun
2 Likes
Hossein
(Hossein Amerkashi)
October 22, 2019, 1:28pm
#13
Not according to @Peter requirement. I think should be empty string. That’s why I was also returning empty string
1 Like
Boban
(Boban Stojmenovic)
October 22, 2019, 4:40pm
#14
You were right, I hope this one does the job
1 Like
Taifun
October 22, 2019, 6:25pm
#15
potent and pot , both words end with t… as well as potent and tnet … so isn’t that the longest common ending then?
Taifun
1 Like
Hossein
(Hossein Amerkashi)
October 22, 2019, 6:40pm
#16
Aha, then I think I misunderstood the full requirement