No-repeat Substring (hard)
Problem Statement
Given a string, find the length of the longest substring, which has all distinct characters.
Example 1:
Input: String="aabccbb"
Output: 3
Explanation: The longest substring with distinct characters is "abc".
Example 2:
Input: String="abbbb"
Output: 2
Explanation: The longest substring with distinct characters is "ab".
Example 3:
Input: String="abccde"
Output: 3
Explanation: Longest substrings with distinct characters are "abc" & "cde".
Try it yourself
Try solving this question here:
import java.util.*;class NoRepeatSubstring {public static int findLength(String str) {// TODO: Write your code herereturn -1;}}
Solution
This problem follows the Sliding Window pattern, and we can use a similar dynamic sliding window strategy as discussed in ...