You are on page 1of 1

MAXIMIZINGUNIQUENESS

GivenaStringofNcharacters(1<=N<=500000)
youhavetofindthesubstringofitwhichcontainsthe
mostnumberofdistinctcharacters.Ifthereexists
multiplesuchsubstrings,youshouldconsiderthe
onewiththesmallestlength.Ifthereexistsmultiple
solutionsofthesamelength,choosetheonewhichis
lexicographicallysmallest.
Yourtaskistoprinttheoptimalsubstring.
SampleInputSampleOutput
ABBCABCABC
ABBBBBCABBBBBC
ExplanationofSampleCases:
Inthefirstcase,thesubstringABCistheshortest
substringthatconsistsofthreedistinctcharactersand
it'slengthisthree.NotethatCAB,BCAarealso
possiblebutABCshouldbeprintedasitis
lexicographicallysmallest
Inthesecondcase,theentirestringistheoptimal
substringconsistingofthreedistinctcharacters.

You might also like