今日、弟が私に質問をしました。質問は次のとおりです。
Given a list of strings & string M28K, where M28K represents a string which starts
from M, ends with K and has 28chars in between . Find if M28K is unique in the
list of strings or not?
問題の解決策を見つけるために、次のアルゴリズムを思いつきました。
文字列ごとに:
find string length(L)
if(L==30) then
if(str[0]=='M' && str[L-1]=='K') then
verify rest of 28 characters are matching or not
このソリューションは、時間の複雑さの点で効率的ではないようです。誰かがこの問題を解決するためのより良いアルゴリズムを与えることができますか?