Prefix array doubt

What will be the prefixes of string “cobra”?

My doubt, is “cobra” itself can be a prefix of the string “cobra”…

hello @Kinjal
no bro . . . . . . . (btw in most of the questions problem setter will clear what exactly they mean by prefix)

1 Like

Okay. I noted.
Bhaiya, then tell me, what will be the unique prefix array for the array of string
{“cobra”,“cob”,“cobras”}

koi unique prefix nahi hai isme

1 Like

So possible prefixes of “cobra” can be like,
{“c”,“co”,“cob”,“cobr”} but not “cobra” itself, right!!
NULL or “” can be a prefix of “cobra”?

for this problem , u can consider complete string as prefix .

no bro , NULL cannot be a valid prefix

1 Like

So, for the string of array {“cobra”,“cob”,“cobras”}
we can write unique prefix of this array will be,
{“cobra”,“cob”,“cobras”} itself…
Right!!!

cob is not unique right?
it is present in all three strings.

1 Like

yes.
So for {“cobra”,“cobras”} then unique prefix will be {“cobra”,“cobras”}
Right!!

no cobra is again common in both

1 Like

Accha. Iska mtlb, prefix substrings of a string can’t have unique prefix if the string is also present in the array.
like, if the string is “dog” then prefix substrings are {“d”,“do”}
So, for {“cobra”,“cobras”}, unique prefix array will be like {-1,“cobras”} where -1 denotes no unique prefix for that particular string

ha …
tum isko roll no se samajh sakte ho.
17121000 // isko uniquely identify nahi kar sakte ki kis bacche ki baad ho rahi hai , kyunki ye kisi aur me bhi common hai
171210007 // yaha pe ye unique ha ,hum isko easily identify kar sakte hai
171210008 // same case iske liye

1 Like

A string x is called a substring of another string y if there are strings u and v such that y = uxv . Note that u and v may be an empty string. So a string is a substring of itself.

A string x is a prefix of another string y if there is a string v such that y = xv . v is called a suffix of y .

Bhaiya, iss definition se mera assumption wrong hai kya, ki “cobra” can be a prefix of itself…!!!

if v is empty then it holds right? (for this problem assume suffix v can empty)

then iska matlb, null string or empty string or “” can be a suffix of a string

no bro as per definition suffix cant be empty
( here we are considering prefix and not proper prefix)

A proper prefix of a string is a prefix that is not equal to the string itself

So, tell me if I’m wrong…
A string can be a substring of itself but can’t be a prefix or a suffix of itself.

for this to hold true use term proper prefix or proper suffix( this avoids ambiguity).

So, the difference is,

a prefix or a suffix of a string can be a empty string or the string itself.

But, a proper prefix or a proper suffix of a string can’t be a empty string or the string itself.

Right!

yeah this is correct.

prefix -> proper prefix + string itself
suffix-> proper suffix + string itself

1 Like