← Back to challenges

Word Overlapping

JavaScriptHardstringsloopsalgorithms

Instructions

Given two words, overlap them in such a way, morphing the last few letters of the first word with the first few letters of the second word. Return the shortest overlapped word possible.

Examples

overlap("sweden", "denmark") ➞ "swedenmark"

overlap("innokodakademija", "iterate") ➞ "innokodakademijaerate"

overlap("honey", "milk") ➞ "honeymilk"

overlap("dodge", "dodge") ➞ "dodge"

Notes

  • All words will be given in lowercase.
  • If no overlap is possible, return both words one after the other (example #3).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.