Problem · String
Shortest Substring
Learn this problemProblem statement
Determine the length of the shortest contiguous substring that can be deleted from a string s so that the remaining string contains only distinct characters.
After deleting a substring, join the part before it with the part after it. If s already contains only distinct characters, return 0.
Function
findShortestSubstring(s: String) → intExamples
Example 1
s = "abcbbck"return = 3Deleting any one of three length-3 choices can leave abck, whose characters are all distinct. No shorter deletion works.
Example 2
s = "xabbcacpqr"return = 3Delete bca to obtain xabcpqr.
Constraints
1 <= s.length() <= 10^5scontains only lowercase English letters.
More Rippling problems
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Jul 2025
- Server Upgrade PlanningOA · Seen Jul 2025