-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Second most repeated character in a sequence #1727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about generalizing the algorithm to find kth most repeated character in a sequence
@onlinejudge95 Changed to support nth repeated |
@onlinejudge95 Changes done |
The algorithm is a one liner... def count_repeated(sequence: list, nth_repeated: int) -> str:
return "" if nth_repeated < 1 else Counter(sequence).most_common()[nth_repeated - 1][0] https://docs.python.org/3/library/collections.html#collections.Counter.most_common |
Sorry @ SKAUL05 but closing as this has now become a demonstration of how to use the Python Standard Library rather than an algorithm. Please do not be discouraged because this has been a learning experience. I hope you will make other submissions of algorithms in the near future. |
This
PR
is about adding an algorithm which would find the second most repeated character in a sequence