Ctrl K

Cuts With Equal Variety

Medium
You are given a string text of lowercase English letters. It is cut in one place into two non-empty parts, a left one and a right one. A cut is good if the left part contains as many distinct letters as the right part. Count the good cuts.
Example 1
text='banana' → 1

Of the five cuts only "ba" | "nana" works: two distinct letters on each side. For instance, "ban" | "ana" has three distinct letters on the left and two on the right.

Example 2
text='qq' → 1

The only cut gives "q" | "q", one distinct letter on each side.

Example 3
text='xyzx' → 1
Constraints
  • 1 ≤ len(text) ≤ 10⁵
  • text consists only of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSplit Into Dictionary Words MediumRecurring Gene Windows MediumWords Hidden in a Text MediumWord Growth Chain MediumPalindrome After a Few Fixes Medium
loading Python…
Input
text='banana'
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.