| 1 | class Solution { |
| 2 | int maxCount; |
| 3 | public int maxUniqueSplit(String s) { |
| 4 | maxCount=0; |
| 5 | HashSet<String>set = new HashSet<>(); |
| 6 | backtrack(s,set,0); |
| 7 | return maxCount; |
| 8 | } |
| 9 | // tc: n * 2^n |
| 10 | // sc: n substring |
| 11 | public void backtrack(String s, HashSet<String> set, int index){ |
| 12 | //base case |
| 13 | int n = s.length(); |
| 14 | if(index==n){ |
| 15 | maxCount = Math.max(maxCount,set.size()); |
| 16 | return; |
| 17 | } |
| 18 | //loop |
| 19 | for(int i=index;i<n;i++){ |
| 20 | //check if substring is present in set or not |
| 21 | String sub = s.substring(index,i+1); |
| 22 | if(!set.contains(sub)){ |
| 23 | set.add(sub); |
| 24 | backtrack(s,set,i+1); |
| 25 | set.remove(sub); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected