Problem Statement
You want to share this delicious chocolate bar with your best friend. At first, you want to give him the whole bar, but then you remembered that your friend only likes a chocolate bar without repeated letters. Therefore, you want to remove zero or more squares from the beginning of the bar, and then zero or more squares from the end of the bar, in such way that the remaining bar will contain no repeated letters.
Return the maximum possible length of the remaining chocolate bar that contains no repeated letters.
Definition
- Class:
- ChocolateBar
- Method:
- maxLength
- Parameters:
- String
- Returns:
- int
- Method signature:
- int maxLength(String letters)
- (be sure your method is public)
Constraints
- letters will contain between 1 and 50 characters, inclusive.
- Each character of letters will be a lowercase letter ('a' - 'z').
Examples
"srm"
Returns: 3
You can give the whole chocolate bar as it contains no repeated letters.
"dengklek"
Returns: 6
Remove two squares from the end of the bar.
"haha"
Returns: 2
There are three possible ways: Remove two squares from the beginning of the bar. Remove two squares from the end of the bar. Remove one square from the beginning of the bar and one square from the end of the bar.
"www"
Returns: 1
"thisisansrmbeforetopcoderopenfinals"
Returns: 9
"x"
Returns: 1
"abcabcabc"
Returns: 3
"cab"
Returns: 3
"cebad"
Returns: 5
"gcfbhjidea"
Returns: 10
"hognikedalcfjbm"
Returns: 15
"moqcpjnashriglefbdtk"
Returns: 20
"qaljvodxnwhstprbeuikgfmyc"
Returns: 25
"wfkgeszaxsjnepmtuobdvlycrusihq"
Returns: 19
"mgbgvxdvybnghapsfzguvjutwomdjckelyiwrckq"
Returns: 13
"wexkzhkhvdymowmunqallufucdcztqapsxojbgqikwxbr"
Returns: 13
"dxncubuorrnhtpifwgodfjmmoaxdostsamvhvmzxymcqfepykl"
Returns: 11
"bca"
Returns: 3
"daecb"
Returns: 5
"jaeiedbagf"
Returns: 7
"mcdmzehbanejdiq"
Returns: 9
"cpjndlzkgbqrkshataoi"
Returns: 12
"vaeimtxcggqndojylwbuhphsr"
Returns: 13
"utkeophsjijxxmllsknqcgqcmbyzha"
Returns: 10
"bsvvwqpgfpcghedmpeyujbmdzcjchokyxlpvmaen"
Returns: 14
"grqhxdndsurmybktixywtzdojfhkqtjcjnwamloyipvle"
Returns: 13
"pumnoccuwgvewspojtqrtneszgofifhyetnhtyzkexbatjihur"
Returns: 13
"ll"
Returns: 1
"vwwwwv"
Returns: 2
"quhwmlmwhuq"
Returns: 6
"wvchdneooendhcvw"
Returns: 8
"eyhnoorxdsusdxroonhye"
Returns: 6
"oosbklyshmfdkkdfmhsylkbsoo"
Returns: 9
"mnxsomwnvmbmfapypafmbmvnwmosxnm"
Returns: 7
"vdmngyygshtymbiaqftftftfqaibmythsgyygnmdv"
Returns: 11
"rurdxdjxshuxviftimmshkkkkhsmmitfivxuhsxjdxdrur"
Returns: 8
"ufabyhvrbovytgynpsmkcrdnfndrckmspnygtyvobrvhybafu"
Returns: 11
"pjvp"
Returns: 3
"zxhz"
Returns: 3
"nyaqaqacn"
Returns: 4
"jyvnvzcpyojvai"
Returns: 9
"ntcjvmcsrnjswmvjrtn"
Returns: 8
"haotjjpbzriuqrqspjvtkah"
Returns: 10
"iujagrjfjarzzktkuzvybfbkdajui"
Returns: 8
"qomcfwgjkwtdwmfqwghqsvwnfmwdnwkqnwfcvoq"
Returns: 9
"atjkzskpqzfjzgbjqfpsnhunapfjjbmzjfdqikszkjta"
Returns: 11
"psorariephxoycwhmkjvvuobhxyoulvakmhwcyoxhpeirwrosp"
Returns: 12
"ene"
Returns: 2
"eveuw"
Returns: 4
"tdwavazudm"
Returns: 6
"tmxcftlxcmeljky"
Returns: 8
"potwjsrootjosftgbhed"
Returns: 10
"mxplbdpmozmgohczzvnnozdhg"
Returns: 7
"ynhfrntqefrjwfywrgmbinadcqrbva"
Returns: 13
"iwordhezykgrucxsaqyotibwnemghjhpfxjlenke"
Returns: 19
"yqwsuvmxnmlhwndjtrpaaysivbtcqfioxeitbwqpicwer"
Returns: 11
"bpkshmufecdhxhyepobwzvzvlogpmmgpcshlheqnivvgevmwjo"
Returns: 11
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Returns: 1
"thisisansrmbeforetopcoderopenfinalsandmoreshitlol"
Returns: 12
"abcdefghijzabcdefghijklnmopqrsttsrqpomnz"
Returns: 21
"aabbcc"
Returns: 2
"deenglkk"
Returns: 5
"zxxyyz"
Returns: 2
"zzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: 1
"abbabbaa"
Returns: 2
"abcede"
Returns: 5
"abrakadabra"
Returns: 4
"aaaaaaaaaaaabb"
Returns: 2
"a"
Returns: 1
"abcad"
Returns: 4
"thisisaverylongstriagshbiccahamzawnwwhhdefqaymules"
Returns: 11
"thisisansrmbeforembiosubapbnsdaasdpanadsadtopcoder"
Returns: 9
"bba"
Returns: 2
"abbc"
Returns: 2
"abcdabcdabcdabcdabcdabcd"
Returns: 4
"xnmabcdabcdabcdabcdabcdabcduzy"
Returns: 7