Shortest Deletion for a Distinct Remainder
Updated
Problem statement
Given a case-sensitive printable-ASCII string, delete one contiguous substring so that every remaining character is distinct.
Return the minimum number of deleted characters. Deleting zero characters is allowed, and deleting the entire string is also a valid fallback.
Function
minDeletionForDistinct(text: String) → intExamples
Example 1
text = "abca"return = 1Deleting either occurrence of a leaves three distinct characters.
Example 2
text = "abc"return = 0The original string already contains no repeated character.
Constraints
0 <= text.length <= 10^5textcontains printable ASCII characters.
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
- K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
- Shortest SubstringRippling · OARippling interview questions
- Calculate Difference Value 🍧DoorDash · OADoorDash interview questions
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Reverse Words in a StringAgoda · PHONE SCREENAgoda interview questions
- Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions