Longest Common Prefix (LeetCode)

Write a function to find the longest common prefix string amongst an array of strings.

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

Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"

Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

Installation

git clone https://github.com/kristabel-wong/longest-common-prefix.git
cd longest-common-prefix
npm i                # install the Jest test runner
npm run watch:first  # run this first while debugging
npm run watch        # to run in watch mode