You are viewing a single comment's thread. Return to all comments →
def merge_the_tools(string, k): """ This is a simple solution of O(N) time complexity First, we start iterating through the string at step k, this goes through each substring define each substring using string splicing using the fromkeys method which is a class method in pythons dict type. Creates a new dictionary from a sequence of keys or in this case chars, this assigns None to each key, and also removes duplicates, but still keeps the order. The alternative would have been to use some sort of set casting but I've come to find that that doesn't preserve order. Then we use the string method 'join' with an empty string as the delimiter (aka the string for which the method is called upon) to get our u """ for i in range(0, len(string), k): substr = string[i: i+k] shaved = "".join(dict.fromkeys(substr)) print(shaved)
Seems like cookies are disabled on this browser, please enable them to open this website
Merge the Tools!
You are viewing a single comment's thread. Return to all comments →