Uber | OA 2020 | composeKPalindrome
Anonymous User
952

Given a string s, can you compose exactly K non-empty palindromes using all leters of s?

Note that you can use only letters from s. Each letter from s that you use has to appear exactly the same number of times in your palindromes as it does in s. Also note that you can rearrange string letters as you want.

Example:
s = 'abracadabra' and k = 3 output of composeKPalindrome(s, k) = true

The answer is true since you are able to compose 3 palindromes using each letter of 'abracadabra' once. 3 possible palindromes that fulfill this requirement for example can be: 'raaaaar', 'bcb' and 'd'.

For s = 'abracadabra' and k = 2, the output should be composeKPalindrome(s, k) = false

Any idea how to solve it?

Comments (2)