ECOO '16 R2 P1 - Palindrome Panic

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.5s
Memory limit: 256M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

A palindrome is a word that has the exact same sequence of letters when read forwards or backwards. The words noon and radar are palindromes, whereas the words noob and palindrome are not.

Patty loves palindromes, as she finds them soothing. Patty knows that you can turn any word into a palindrome by adding letters to the left and / or right. For example, you can turn ECOO into OOCECOO or ECOOCE or even DOOCECOOD. Patty loves palindromes so much that any time she sees a word written down somewhere, she immediately converts it to a palindrome in her head.

The input will contain 10 test cases. Each test case consists of a single line containing a string of lowercase characters of maximum length of 10^6. Your code should output the minimum number of letters Patty would need to add to the left and / or the right in order to convert the string to a palindrome.

Note that the sample input below contains only 3 test cases but the actual data files will contain 10.

Sample Input

ecoo
impala
anagram

Sample Output

2
3
4

Question Development Team

Sam Scott (Sheridan College)
Kevin Forest (Sheridan College)
Stella Lau (University of Cambridge)
Reyno Tilikaynen (University of Waterloo)
John Ketelaars (ECOO-CS Communications)
David Stermole (ECOO-CS President)

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org


Comments


  • -5
    Togohogo1  commented on Dec. 16, 2019, 10:54 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


  • 0
    mse387  commented on April 18, 2017, 9:07 p.m.

    Can somebody look at my solution please? I know my solution works but it is too slow.....I guess I should be using the "failed" palindrome tests to somehow optimize the future substrings that I need to check, but can't figure out how to do so.


    • -8
      Ken_Shi  commented on April 19, 2017, 12:14 p.m.

      This comment is hidden due to too much negative feedback. Click here to view it.


      • 4
        Kirito  commented on April 19, 2017, 5:30 p.m.

        Additionally, there are at least two distinct ways of doing the problem.


        • -3
          Ken_Shi  commented on April 20, 2017, 3:35 p.m.

          I can only think of one algorithm. Will learn more tho


      • 7
        wleung_bvg  commented on April 19, 2017, 4:55 p.m.

        It can be done with Java though


        • -4
          Ken_Shi  commented on April 21, 2017, 1:58 p.m.

          Just laughing at Java's speed tho, dont be serious.


  • 0
    bobhob314  commented on May 14, 2016, 2:08 p.m. edit 4

    Does anyone know what the error code: RTE(stopped (signal)) for my submission means?


    • 3
      Xyene  commented on May 14, 2016, 5:03 p.m.

      We recently made it so we translate signal codes into readable descriptions (so you can get feedback like "Segmentation fault" or "Floating point error" instead of just "RTE").

      "Stopped (signal)" is caused by SIGSTOP being received by your process.


      • 0
        root  commented on June 27, 2017, 9:48 p.m.

        Under what circumstances will that happen?


  • 3
    r3mark  commented on May 5, 2016, 9:56 p.m.

    Are the ECOO problems supposed to be ordered easiest to hardest?


    • 12
      Xyene  commented on May 5, 2016, 9:57 p.m.

      Not necessarily.