We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Palindrome Index
- Discussions
Palindrome Index
Palindrome Index
Sort by
recency
|
1056 Discussions
|
Please Login in order to post a comment
python3
This is my solution in JS. But it does not pass every case, I tried to find what's wrong about it, but no idea. Any thoughts?
javascript
Hello, I still need to learn more about string splicing so I can understand other solutions. I have my own solution which passes test cases but was wondering if someone could show me a better way to handle this line I wrote that is bothering me: if s[i + 1] == s[j] and s[i + 2] == s[j - 1]: Before I added that, I built the function based off of my own string I made "rbacecar", and my logic on paper was basically this: 1. take off "r" from both sides of the string since they match 2. "b" and "a" don't match now. So, if we look just beyond "b", we see "a", which is a match. That means "b" is the problem. HOWEVER, that doesn't work with strings like "fcwnnwcwf" or any string with more repetition in the letter choices. So, I added "and s[i + 2] == s[j - 1]" to my line with "if s[i + 1] == s[j]" so my function would check a little farther beyond. However, I don't think that's ideal.
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star:) )