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.
Append and Delete
Append and Delete
Sort by
recency
|
1377 Discussions
|
Please Login in order to post a comment
Here is my O(k) c++ solution, you can watch the explanation here : https://youtu.be/8ZOmXfo6k0Y
Can someone explain why test case 5 and 10 are a "No" as answare?
To me it should be a "Yes"
My solution in Java language, some variables' name may look weird.
C++ O(n) solution:
Not-ideal python3 math-based solution that accounts for exceptions: def appendAndDelete(s, t, k): # Write your code here s = list(s).copy() t = list(t).copy() if s == t: return "Yes" elif k >= (len(s) + len(t)): return "Yes" elif (len(set(s)) == 1) and (len(set(t)) == 1): return "Yes" else: common_values = set(s).intersection(t) idx_s = [s.index(x) for x in common_values] idx_t = [t.index(x) for x in common_values] if idx_s == idx_t: differences = ((len(s) - len(idx_s)) + (len(t) - len(idx_t))) k -= differences if k == 0: return "Yes" else: return "No" `