Back to Type Challenges

README

questions/35045-medium-longest-common-prefix/README.md

latest1.4 KB
Original Source
<!--info-header-start--><h1>Longest Common Prefix </h1><blockquote><p>by Tom Cleary <a href="https://github.com/thomcleary" target="_blank">@thomcleary</a></p></blockquote><p><a href="https://tsch.js.org/35045/play" target="_blank"></a> </p><!--info-header-end-->

Longest Common Prefix

Write a type, LongestCommonPrefix that returns the longest common prefix string amongst a tuple of strings.

If there is no common prefix, return an empty string "".

ts
type Common = LongestCommonPrefix<["flower", "flow", "flight"]>
//   ?^ "fl"

type Uncommon = LongestCommonPrefix<["dog", "racecar", "race"]>
//   ?^ ""

Inspired by LeetCode 14. Longest Common Prefix

<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/35045/answer" target="_blank"></a> <a href="https://tsch.js.org/35045/solutions" target="_blank"></a> <!--info-footer-end-->