Problem · String
Longest Non-Repeating Substring
Learn this problemProblem statement
Given a string s, return a longest contiguous substring that contains no repeated characters.
For this exercise, assume that when several longest valid substrings exist, you must return the one with the smallest starting index. If s is empty, return the empty string.
Function
longestUniqueSubstring(s: String) → StringExamples
Example 1
s = "abcabcbb"return = "abc"The longest valid substrings have length 3. The earliest one is "abc", which starts at index 0.
Example 2
s = "pwwkew"return = "wke"Both "wke" and "kew" have length 3. The leftmost tie rule selects "wke".
Example 3
s = "bbbbb"return = "b"Every valid substring has length 1, so the first character is returned.
Example 4
s = ""return = ""The empty string has no non-empty substring, so return "".
Constraints
0 <= s.length <= 200000scontains lowercase English letters.
More Cisco problems
- Collect CoinsOA · Seen Jun 2025
- FizzBuzz ProblemOA · Seen May 2025
- Find Largest Sum Contiguous SubarrayOA · Seen May 2025
- Find Largest Sum of Continuous SequenceOA · Seen May 2025
- Find Palindrome Sub-stringOA · Seen May 2025
- Count Numbers with Digit SumOA · Seen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)OA · Seen Mar 2025
- Find Elements Largest in Row Smallest in ColumnOA · Seen Mar 2025