Skip to content

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

@bitsgorilla
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