Skip to content
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

Adding solve for 1400 #483

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NirBinyamin8
Copy link

Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise.

The Readme.md file has been updated.

Copy link

welcome bot commented May 3, 2024

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

@NirBinyamin8
Copy link
Author

issue #484

@crazyGru
Copy link

from collections import Counter

def can_construct_palindrome(s, k):
    # Count the frequency of each character in the string
    char_count = Counter(s)
    
    # Count the number of characters with odd frequency
    odd_count = sum(count % 2 for count in char_count.values())
    
    # If k is greater than or equal to the number of odd-count characters,
    # it's possible to construct k palindromic strings
    return k >= odd_count and k <= len(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants