Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

SKAUL05
Copy link
Contributor

@SKAUL05 SKAUL05 commented Feb 4, 2020

This PR is about adding an algorithm which would find the second most repeated character in a sequence

Copy link
Collaborator

@onlinejudge95 onlinejudge95 left a 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

@SKAUL05
Copy link
Contributor Author

SKAUL05 commented Feb 19, 2020

How about generalizing the algorithm to find kth most repeated character in a sequence

@onlinejudge95 Changed to support nth repeated

@onlinejudge95 onlinejudge95 added the enhancement This PR modified some existing files label Feb 19, 2020
@SKAUL05
Copy link
Contributor Author

SKAUL05 commented Feb 29, 2020

@onlinejudge95 Changes done

@cclauss
Copy link
Member

cclauss commented Feb 29, 2020

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

@cclauss
Copy link
Member

cclauss commented Feb 29, 2020

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.

@cclauss cclauss closed this Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants