logo CodeStepByStep logo

longestUniqueString

Language/Type: Java algorithms interview strings
Related Links:

Write a method named longestUniqueString that accepts a string as a parameter and returns an integer representing the longest substring that can be formed from it without any repeated characters. For example, the call of longestUniqueString("abcabcab") should return 3 because its longest such substring is "abc". The call of longestUniqueString("aaaa") should return 1 because its longest such substring is "a". The call of longestUniqueString("abbbcbbbacddb") should return 4 because its longest such substring is "bacd". ("abcd" or "abcde" are not valid because they are subsequences, not substrings.)

If the string is empty, return 0. You may assume that the string contains only standard ASCII characters (no extended Unicode character values).

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.