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.
Calculate the length of the substing of s (starting at the beggining of s) which we do not need to change because it is the same as the corresponding substring of t.
Comment 2
If k >= len(t) + len(s) the answer is always yes because we can delete all the letters of s, continue deleting the empty string if k > len(t) + len(s) and then add the elements of t
Comment 3
min_ops = len(t) + len(s) - 2*i calculates the minimum number of operations needed to transform s to t. If min_ops > k the answer is no. If min_ops = k the answer is yes. If min_ops < k, the answer is yes if the remaining operations are an even number. In this case, after transforming s we would use the remaining number of operations to add and delete an item (or vice versa) until we use all of k.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Append and Delete
You are viewing a single comment's thread. Return to all comments →
Found a peculiar solution I though I would share:
Comment 1
Calculate the length of the substing of s (starting at the beggining of s) which we do not need to change because it is the same as the corresponding substring of t.
Comment 2
If k >= len(t) + len(s) the answer is always yes because we can delete all the letters of s, continue deleting the empty string if k > len(t) + len(s) and then add the elements of t
Comment 3
min_ops = len(t) + len(s) - 2*i calculates the minimum number of operations needed to transform s to t. If min_ops > k the answer is no. If min_ops = k the answer is yes. If min_ops < k, the answer is yes if the remaining operations are an even number. In this case, after transforming s we would use the remaining number of operations to add and delete an item (or vice versa) until we use all of k.