Longest Common Prefix

Everything old is new again.
  • Vertically: Look at all the 1st letters together, if they match, then all the 2nd letters, etc.
  • Divide and Conquer: compare common elements in the 1st half of the array, and separately in the 2nd half of the array. Then compare the 1st half results to the 2nd half.
// find the shortest string in my array(SMALLEST), since the common prefix can't be bigger than that.
// loop through the SMALLEST word in the array
// compare that to the nth letter in each word as we loop through the entire array
// if it matches, add it to our "answer string"
// if not, pull the brakes and return what we have
// Rinse. Repeat.
CONCATENATION. (i think that’s a word)
our finished project.
not all heroes wear capes

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store