Using Programming Language Java Write Function Find Longest Common Prefix String Amongst A Q37176315

Using the programming language Java: Write a function to findthe longest common prefix string amongst an array of strings.


Answer


`Hey,

Note: Brother in case of any queries, just comment inbox I would be very happy to assist all your queries

public class Main {
  
// A Function to find the string having the
// minimum length and returns that length
public static int findMinLength(String arr[], int n)
{
int min = Integer.MAX_VALUE;
for (int i = 0; i <= (n – 1); i++)
{
if (arr[i].length() < min) {
min = arr[i].length();
}
}
return min;
}
  
static boolean allContainsPrefix(String arr[], int n,
String str, int start, int end)
{
for (int i = 0; i <= (n

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.