FastPrepShortest Deletion for a Distinct Remainder

Shortest Deletion for a Distinct Remainder

Google logoGoogle● MediumNEW GRADPHONE SCREEN

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) → int

Examples

Example 1

text = "abca"return = 1

Deleting either occurrence of a leaves three distinct characters.

Example 2

text = "abc"return = 0

The original string already contains no repeated character.

Constraints

  • 0 <= text.length <= 10^5
  • text contains printable ASCII characters.

More Google Phone Screen questions

Similar questions at other companies

Interview reports that mention this question

Google interview experiences

All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minDeletionForDistinct(String text) {
        // Write your code here.
    }
}
Checking account…