Alright so it looks good! Let me give a full rating
Correctness:
- For single words that are full palindromes it passes, for example "bob" "madam" "racecar" "clap" "alphabet" and so forth give the correct response.
- Palindromes within single word substrings are also correct, things such as "jerry" "banana" "bobby" and so forth give the correct palindrome as well as the largest one so good job! Single character strings also are not considered palindromes which is exactly what we specified so excellent!
- Problems occur when we start using multi word strings or strings that have non-alphanumeric characters in them (In the spec you were told strings may include non-alphanumeric characters but you should just ignore them), for example the string "race car" outputs with no palindrome when it should ignore the space, "hello how woh olleh" also gives an incorrect palindrome of "how woh" which is not the longest palindrome, it's interesting that it still ignored the space in this one. Most of my tests using multiword strings failed this one, so you might want to add special cases for when you encounter a space character
- The strings are not cap sensitive which is excellent, it doesn't preserve the case (so if I inputted "Madam" it'll output "madam") but I can definitely forgive that so well done.
I can't give you 10 because it doesn't handle the non-alphanumeric case but it handles every other case very well so I'll give it an 8/10
Efficiency:
- The worst case time complexity is around O(n
3) but that's a pretty standard efficiency for this kind of problem. There are some ways to make it more efficient but I'd give you a 10 for this one
- A problem is that you left some debugging functions in, it causes some unnecessary overhead for the final product and considering it's in a nested loop that debugging function (which does nothing when debugging is disabled) could be called n
2 times, so for large n this can give a large overhead. I'm forgiving it though cause it's super easy to remove.
10/10
Cleanliness:
- No comments (except the header)!
- I don't really like the initial for loop (which should be a while loop probably), if you used while(Scanner.hasNext()) instead of for(;
you could give support for file reading which would be beneficial for testing, otherwise your program will never terminate when reading a file unless the file contains "quit". I understand that the program will never terminate regardless of what you do when reading from stdin, but it's always good to allow for multiple uses of your program.
- Variable and method names are descriptive (with the exception of the debugger method) so it's pretty easy to follow that, indentation and spacing is well done so all of that is fine.
- It's interesting that you used Java but didn't really implement the modularity that Java offers, it would of been a better idea to separate the palindrome class away from the main method and have the palindrome class just accept a STRING rather than only accept from standard input. That way I could of tested it on some generated files easier and it would of been more compatible with other programs. Your palindrome class has side effects of printing some stuff which in general it shouldn't have, so making your method a bit more blackbox is a thing to think about as well.
It looks relatively nice but there are still quite a few niches to get out so 6/10 for cleanliness
So that's
8/10 for correctness
10/10 for efficiency
6/10 for cleanliness
For a total of
24/30 or 8/10 overall
So definitely a good solution! I'm impressed with it working pretty well, the only real problems is to make it add a bit more documentation and make it a bit cleaner and also include cases for when non-alphanumeric characters are involved in the inputted string. Other than that an excellent solution so well done!