Introduction
Common prefix between two strings means common substring starting with the beginning character of each given string. For example, the common prefix between ‘coding’ and ‘codingninjas’ is ‘coding’. Finding the longest common prefix is a very popular problem commonly asked in the interviews of top product-based companies.
This problem can be solved by various approaches, but here we will be only focusing on the divide and conquer approach.
Problem statement
You are given an array of strings. You need to find the longest common prefix among the given strings.
Input
arr[ ]={"coding","codingNinjas","codingSkill","codingEra"}
Output
coding
Explanation
coding is the common prefix part among the given strings. We can’t find any longer common prefix. So, it is the longest common prefix.
Note: Please try to solve the problem first and then see the solution below.