Menu
Coddy logo textTech

Longest Common Prefix

Lesson 3 of 15 in Coddy's Recursion Challenges - Master The Recursive Thinking course.

challenge icon

Challenge

Easy

Write a function named lcp that gets an array of strings and returns the longest common prefix.

For example,

  • ["somehow", "somewhat", "something", "some"]  ->  "some"
  • ["maximum", "minimum"]  ->  "m"
  • ["llo", "lloon"]  ->  "llo"

Try it yourself

char* lcp(char** a, int n) {
    // Write code here
}

All lessons in Recursion Challenges - Master The Recursive Thinking