homerjay

homerjay homerjay

Niner since 2005

Comments

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Boy, oh boy, the presentors would never get a job in our company: poor reasoning process, bad solution.

    This problem is so simple that the whole solution is just one line of generic code (also with guaranteed complexity):

    template<typename StringType>
    inline bool is_palindrom(const StringType& str)

       return std::equal(str.begin(), str.begin() + str.size()/2, str.rend());
    }

    now you can instantiate the function on std::string, std::wstring, std::vector<char>, or whatever container is appropriate for your application, which has random access iterators. And if you need to make it case-insensitive, just add a corresponding binary predicate for std::equal, which is another one line of code for English, or can be non-trivial for other languages. You can even test for palindrom objects that are not strings, as long as they contain equality comparable types.