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

Method numSplits

findNumWaysToSplit.py:34–58  ·  view source on GitHub ↗
(self, s: str, k: int)

Source from the content-addressed store, hash-verified

32# Approach 3
33class Solution:
34 def numSplits(self, s: str, k: int) -> int:
35 def countSharedChars(arr1, arr2):
36 ans = 0
37 for i in range(26):
38 if arr1[i] > 0 and arr2[i] > 0:
39 ans += 1
40 return ans
41
42 def pos(char):
43 return ord(char) - ord('a')
44
45 left = [0] * 26
46 right = [0] * 26
47 for char in s:
48 right[pos(char)] += 1
49
50 ans = 0
51 for char in s:
52 left[pos(char)] += 1
53 right[pos(char)] -= 1
54 numSharedCate = countSharedChars(left, right)
55 if numSharedCate > k:
56 ans += 1
57
58 return ans
59
60obj = Solution()
61s = 'abbcac'

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected