skip to content
Faisal.Software

longestPrefix interview question solution

/ 1 min read

This is my attempt at solving the longestPrefix interview question from cassidoo’s weekly newsletter.


Question:

Write a function to find the longest common prefix string in an array of strings.
Example:
$ longestPrefix(["cranberry","crawfish","crap"])
$ "cra"
$ longestPrefix(["parrot", "poodle", "fish"])
$ ""

Solution (try using browsing from a laptop if it doesn’t load anything):

Comments and suggestions are welcome.