Find unique substring of String s with given length
Clash Royale CLAN TAG#URR8PPP
Find unique substring of String s with given length
I am trying to solve this question. For example, the string equals "caaab" and the length K=2, the return substrings should be "aa","ab","ca" in an alphabetic order. I prefer the solution in python
1 Answer
1
Try this:
input_str = 'caaab'
k = 2
unique_substrings = set(input_str[i: i + k] for i in range(len(input_str) - k + 1))
sorted_substrings = sorted(unique_substrings)
print(sorted_substrings)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Might you prefer to think about the solution in python before posting here as well?
– domochevski
Aug 10 at 22:28