Ad
  • Default User Avatar

    Yes, sometimes such solutions look absurd. But they are needed to remind us that hardcoding is a powerful performance optimization tool.

  • Custom User Avatar

    For me this is legit thing.
    Writing code to generate list, properly process list
    and implement it requires much more
    work then just solving.

  • Custom User Avatar
  • Custom User Avatar

    Correct, it'll fail.
    The author should have added that to the list of test-cases earlier (perhaps to intentionally escape weird inputs).
    It's not hard to either use endsWith (if available) or implement a trivial linear (O(n)) solution that scans each character from the end of the string.
    The latter could be then optimized by splitting the ending into two halves and checking first and last characters for each half (that way it'll give negative response faster than a linear solution).
    Just for your information, 'abc' and 'c' are both incorrect string literals since they should end with an additional apostrophe.