MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / findNumWaysToSplit

Class findNumWaysToSplit

findNumWaysToSplit.java:2–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1// Approach 1
2class findNumWaysToSplit {
3 public static int solve(String s, int k) {
4 int[] prefix = new int[26];
5 int[] suffix = new int[26];
6 for(char c : s.toCharArray()) {
7 suffix[c-'a']+=1;
8 }
9 int categories = 0;
10 int ans = 0;
11 for(int i = 0; i < s.length(); i++) {
12 char cur = s.charAt(i);
13 int idx = cur - 'a';
14 suffix[idx]--;
15 prefix[idx]++;
16 if(suffix[idx] > 0 && prefix[idx] > 0) {
17 categories++;
18 } else {
19 categories--;
20 }
21 if(categories>k) ans++;
22 }
23 return ans;
24 }
25}
26
27
28// Approach 2

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected