We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Abbreviation
Abbreviation
Sort by
recency
|
610 Discussions
|
Please Login in order to post a comment
def _remove_unused(a, b): _set_b=set(b) return "".join(list([x for x in a if x.isupper() or x.upper() in _set_b]))
def _build_dp(a): _dp = collections.defaultdict(int) for _, x in enumerate(a): _dp[x.upper()]+=1 return _dp
def _precheck_check_dp(dp_a, dp_b): for x in dp_b: if dp_a[x] < dp_b[x]: return False return True
def abbreviation(a, b): a=_remove_unused(a, b) if len(a) if not _precheck_check_dp(_build_dp(a),_build_dp(b)): return "NO" if _check(a, b): return "YES" else: return "NO"
My version. Last three tests is timeout. Think how to avoid recursion. Thanks to sxb427 idea: 1. daBcdc ABC 2. f(daBcdc, ABC) = f(daBcd, AB) or f(daBcd, ABC) 3. Improvment - preremoved lower symbols from which are not in b * aBcc ABC * f(aBc, AB) or f(daBc, ABC) => f(aBc, ABC) => True
Trying crazy things to solve it in O(NlogN) My code failed in 3 tests, but i can't think of an small test which it fails, can someone help?
I've passed, so this is a moot point, but doesn't the problem statement say you can "delete all of the remaining lowercase letters in a"? This implies that if you start deleting, you have to keep deleting: "all", not "some". Yet this test case does not fail as it should:
{"abCd", "Cd", false},
Anyone have a non-code description of how to do this ? Nothing I've tried has worked.