Try  HackMD Logo HackMD

Problem


https://leetcode.com/contest/weekly-contest-356/problems/shortest-string-that-contains-three-strings/

Optimal Space & Time Complexity
- Time complexity:
- Space complexity:


Solutions


Hao

YC

SOL

Supplement / Discussion

Hao

https://leetcode.com/problems/shortest-string-that-contains-three-strings/solutions/3840469/solving-shortest-string-that-contains-three-strings/

https://leetcode.com/problems/shortest-string-that-contains-three-strings/solutions/3836584/javascript-easy-and-clean-solution/

  1. Implement merge() helper function: merge(merge(a, b), c) with Array.prototype.includes(), Array.prototype.indexOf() to find substring
  2. 6 possible string combination: [a, b, c], [a, c, b]
  3. sort: smaller in length or lexicographically: sort((a, b) => a.length - b.length || a.localeCompare(b))

YC

SOL