4 ms·
To be fair, if you wanted to do a performant implementation, this is probably a more expensive implementation. The expected response is generally for you to ite
by Bahamut 8y ago
To be fair, if you wanted to do a performant implementation, this is probably a more expensive implementation. The expected response is generally for you to iterate over the string and construct a count map of how many times a character appears in a string, and then iterate over the keys of that object and have at most one odd number in the values of the count map.
The interviewer probably should have probed you about performance though if their intention was to judge you on that (they're both O(n) time complexity, but split, reverse, and join are generally more intensive).
- wheresvic1 8y agoErr I always thought that the expected performant response is to have two indexes 0 and length-1 and bring them to the middle checking that the values are equal :)
- glangdale 8y agoI'm very confused by this answer. Have I missed a joke? Wouldn't the expected response be to iterate over half the string comparing the characters to the other half (in reverse order)? The criteria you provide seems to suggest aabbc is a palindrome.
- Bahamut 8y agoAh sorry, I misunderstood the question - the one I've seen usually is if a string could be rearranged as a palindrome ha.
- dlgeek 8y agoYou're thinking of an anagram, not a palindrome.