FastPrepLongest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Infosys logoInfosys● MediumNEW GRADONSITE INTERVIEW

Problem statement

You are given a string s consisting of printable ASCII characters.

Return the length of the longest substring of s that contains no repeated character.

The empty string has length 0.

Function

lengthOfLongestSubstring(s: String) → int

Examples

Example 1

s = "abcabcbb"return = 3

The substring abc has length 3 and no repeated character. Longer windows such as abca repeat a.

Example 2

s = "bbbbb"return = 1

Every character is b, so the longest non-repeating substring has length 1.

Constraints

  • 0 <= s.length <= 5 * 10^4.
  • s contains only printable ASCII characters.

More Infosys problems

See Infosys hiring insights
Saved
public int lengthOfLongestSubstring(String s) {
  // Write your code here.
}
s"abcabcbb"
expected3
Checking account…