Longest Common Ending

Published by Helen Yu in

Write a function that returns the longest common ending between two strings.

Examples

longest_common_ending("multiplication", "ration") ➞ "ation"

longest_common_ending("potent", "tent") ➞ "tent"

longest_common_ending("skyscraper", "carnivore") ➞ ""

Notes

Return an empty string if there exists no common ending.

Watch a quick demo on how Edabit works.