Problem · String
Ways to Split String
Learn this problemProblem 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) → intExamples
Example 1
s = "aaaa"return = 3We can get
a - aaa, aa - aa, aaa - a.Example 2
s = "bac"return = 0There 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 = 2We can get
ab - aba, aba - ba.Constraints
2 ≤ s.length ≤ 2 * 10^5scontains ASCII letters.- Both resulting substrings must be non-empty.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026