Java: Find length of the longest substring of a given string without repeating characters
37. Longest Substring Without Repeats
Write a Java program to find the length of the longest substring of a given string without repeating characters.
Note:
1) Given string consists of English letters, digits, symbols and spaces.
2) 0 <= Given string length <= 5 * 104
Difficulty: Medium.
Company: Amazon, Google, Bloomberg, Microsoft, Adobe, Apple, Oracle, Facebook and more.
Input String : pickoutthelongestsubstring
The longest substring : [u, b, s, t, r, i, n, g]
The longest Substring Length : 8
Input String : ppppppppppppp
The longest substring : [p]
The longest Substring Length : 1
Input String : Microsoft
The longest substring : [M, i, c, r, o, s]
The longest Substring Length : 6
Sample Solution:
Java Code:
Sample Output:
Input String: pickoutthelongestsubstring The longest substring: ubstring The longest Substring Length: 8 Input String: ppppppppppppp The longest substring: p The longest Substring Length: 1 Input String: Microsoft The longest substring: Micros The longest Substring Length: 6
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to find the longest substring in a string that contains all unique characters.
- Write a Java program to determine the length of the longest substring with no repeating characters using a sliding window.
- Write a Java program to extract the longest substring without duplicates and then print its characters in sorted order.
- Write a Java program to find the longest unique-character substring and then count the number of vowels in it.
Go to:
PREV : Check Interleaving of Two Strings.
NEXT : Remove Duplicate Characters.
Java Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.