Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Erik Gutschmidt
Hmm. I think the test cases should be improved if what I wrote below is able to pass all of them...

Erik Gutschmidt

Jun 26, 2025

// This solution just checks if the first and last letters in the word are the same, which results in the Deque's size being smaller than the original length of the string. While this is certainly incorrect, it is still able to pass all test cases (as of 06/26/2025). If you try it with, for example, "snacks", the "if" statement will poll the ends of the Deque for each 's' on the ends of "snacks", causing myDeq.size() to shrink by 2. This results the return statement being true, even though "snacks" is not a palindrome. import java.util.*; public class Solution { public static boolean checkPalindrome(String s) { // ToDo: Write Your Code Here. Deque<Character> myDeq = new LinkedList<>(); for(int i = 0; i < s.length(); i++){ myDeq.addFirst(s.charAt(i)); } if(myDeq.peekFirst() == myDeq.peekLast()){ myDeq.pollFirst(); myDeq.pollLast(); } return myDeq.size() != s.length(); } }

0

0

Comments
Comments

On this page