phatboislym

Untitled

Aug 31st, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. A palindrome is a word, sentence, verse or number that reads the same backwards or forward. A typical palindrome class will accept a parameter such as a word or number and return true or false if the word is a palindrome. However, your task is to implement a cascading palindrome - a cascading palindrome in the context of this task means the following:
  2.  
  3. 1. The class takes a parameter with several components. The parameter could be a word, a sentence, multiple numbers, etc. The parameter contains various items separated by space.
  4. 2. The class determines the part of the parameter that is a palindrome and returns only the palindrome part of the parameter.
  5. For clarity, consider these examples:
  6.  
  7. a. 1230321 returns 1230321
  8. b. 1230321 09234 0124210 returns 1230321 0124210
  9. c. abcd5dcba 1230321 09234 0124210 returns abcd5dcba 1230321 0124210
  10.  
  11. You can assume that the example structure above will always be the case for this task. For example, this sentence: "A man, a plan, a canal – Panama" is a palindrome; however, you don't need to consider such a case in your implementation.
  12.  
  13. While implementing a palindrome or even a cascading palindrome could be considered easy, the difficulty is efficiency. Your code needs to consider the following:
  14.  
  15. 1. Efficiency: Use as little memory as possible
  16. 2. Speed: Ensure the fastest result regardless of how many components the parameter has
  17. 3. Validation: validation data given by users and return appropriate responses if invalid data is given
  18. 4. Error handling: return appropriate error messages when something goes wrong.
  19.  
  20. Hint:
  21. You'll see that for each word above, that is a palindrome. The letter in the centre forms the base of your check. If the letters on the right and to the left of the centre letter are not the same, then such a word is not a palindrome, and you'll not need to do any further checks.
Advertisement
Add Comment
Please, Sign In to add comment