Longest run with no repeats
Reported in interviews at (where)
You are given a string s. Find the longest piece of it (characters next to each other) in which no character appears twice.
Return the length of that piece. An empty string has none, so return 0 for it.
- Input
s = "pineapple"- Output
5
"pinea" has no repeat; every longer piece repeats a letter.
- Input
s = "zzzz"- Output
1
Any one "z" on its own.
- Input
s = "a b"- Output
3
The space counts as a character: "a", " " and "b" are all different.
Limits
0 <= s.length <= 50000s holds English letters, digits, symbols and spaces.
Hints
Hint 1
Keep a window that never holds a repeat, and slide its start past the last time a character was seen.
Where this was reported
- Salesforce, Intern on-campus interview, 2023 (GeeksforGeeks)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
