FastPrepWays to Split String

Ways to Split String

Google logoGoogle● MediumFULLTIMEOA
Learn

Problem statement

Given a string S, we can split S into 2 strings: S1 and S2. Return the number of ways S can be split such that the number of unique characters between S1 and S2 are the same.

Function

numWaysToSplitString(s: String) → int

Examples

Example 1

s = "aaaa"return = 3

We can get a - aaa, aa - aa, aaa - a.

Example 2

s = "bac"return = 0

There are no ways to split the string such that the number of unique characters between S1 and S2 are the same.

Example 3

s = "ababa"return = 2

We can get ab - aba, aba - ba.

Constraints

  • 2 ≤ s.length ≤ 2 * 10^5
  • s contains ASCII letters.
  • Both resulting substrings must be non-empty.

More Google problems

See Google hiring insights
public int numWaysToSplitString(String s) {
    // write your code here
}
s"aaaa"
expected3
Checking account…