Statically Typed

because Hindley-Milner rocks

The Real solution to the last question

Hat tip Roger Pate.  Taken from the poster spong, in answer to the question:

size_t get_num_of_ints( const int* arr, size_t r, int N, size_t* first ){
    std::pair<const int *, const int *> range = std::equal_range(arr, arr+r, N);
    size_t count = range.second - range.first;
    if (count > 0 && first != 0){
        *first = range.first - arr;

    return count;

Wow, just wow.  I should have thought of this but I didn’t.  I got so excited to write a “better” solution that I didn’t stop to think if someone else hadn’t already come up with a solution of their own.  It’s like all those people who proudly show off their time conversion functions and then someone says, “Why don’t you just use Boost::Date_Time?”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


This entry was posted on March 19, 2010 by in C++, Intervew Questions.
%d bloggers like this: