Write a c program for the below given question Prefix of a word W=x1x2..xn are x1, x1x2, x1x2x3,...,x1x2...xn. The prefixes of the word: bear are
Write a c program for the below given question
Prefix of a word W=x1x2..xn are x1, x1x2, x1x2x3,...,x1x2...xn. The prefixes of the word: bear
are b, be,bea & bear which are of length 1,2,3,& 4 respectively. Longest common prefix
that occur in the words : good and god is go. Given n words, write a program to compute the
longest of the longest common prefix that occurs in the given sequence of words. Consider the
sequences of words: w1= good, w2=goose, w3=density, w4=deared, w5=dearest, w6=dearer.
Here: goo is a longest common prefix of w1 & w2. deare is the longest common prefix of w4,
w5 & w6. Among the longest common prefixes, goo & deare, deare is the longest of the
longest common prefix of the given sequence of words. For the sequence of words :read,
reading, reader, ready, blue, block, good,goose,goat, we have the longest common prefixes as :
read, bl, goo. Hence, read is the longest of the longest common prefix of the sequence. If there
are more than longest of the longest common prefix, your program should print the one which
comes first in the alphabetical order. If there are no longest of the longest common prefixes,
your program should output -1.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started