Google Online Assessment (OA) 2021 | Split Strings

Given a string s with length n, how many ways can you split it into two substrings s_1 and s_2 such that the number of unique characters in s_1 and s_2 are the same?


  • s: A string with length n.


  • The number of ways you can split it into two substrings that satisfy the condition.


Example 1:

Input: s = "aaa"

Output: 2

Explanation: It can be split in two ways: "a", "aa" and "aa", "a".

Example 2:

Input: s = "bac"

Output: 0

Explanation: There is no way to split this string into two substrings with equal unique elements.


  • 0 <= n <= 10^5
  • Characters in this string may consist of any alphanumeric character. The characters are case sensitive. That is, same letters with different cases count as different characters.

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions