Skip to content

Permutation palindrome solution is wrong.  #169

Description

@RoryKelly

This test will fail even though oooo is a valid palindrome and palindrome Permutation

    @Test
    fun `'oooo' a palindrome`() {
        isPermutationPalindrome("oooo") shouldBeEqualTo true
    }

solution should be

private fun isPermutationPalindrome(str: String): Boolean {
    val charCountMap = str.groupingBy { it }.eachCount()
    val oddCount = charCountMap.count { it.value % 2 != 0 }

    return if (str.length % 2 == 0) {
        oddCount == 0
    } else {
        oddCount == 1
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions