FastPrepAll Longest Substrings Without Repeating Characters

All Longest Substrings Without Repeating Characters

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Given a string s, return every occurrence of a longest contiguous substring that contains no repeated character.

Return occurrences from left to right. If equal text appears at multiple maximum-length positions, include it once for each position. Return an empty array when s is empty.

Function

allLongestUniqueSubstrings(s: String) → String[]

Examples

Example 1

s = "abcabcbb"return = ["abc","bca","cab","abc"]

The maximum length is three. Four left-to-right occurrences reach that length; the text abc appears at two different positions and is returned twice.

Example 2

s = "bbbbb"return = ["b","b","b","b","b"]

Every one-character occurrence is a longest valid substring.

Example 3

s = ""return = []

An empty input has no nonempty substring occurrence.

Constraints

  • 0 <= s.length <= 100000.
  • s contains ASCII English letters, digits, spaces, and common symbols.
  • The returned occurrence strings preserve their original byte-for-byte text.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] allLongestUniqueSubstrings(String s) {
    // Write your code here.
}
s"abcabcbb"
expected["abc", "bca", "cab", "abc"]
Checking account…