Hacker News new | ask | show | jobs
by rwem 2362 days ago
Is this the kind of thing they are asking in interviews these days? I guess it is nice that this author can prove the correctness of their solution, but what's up with that code? Why is what would otherwise be a perfectly good free function instead a member function of a class with no other functions? Why instead of the usual C++ style of a function taking start and end iterators as arguments does this function take a mutable ref to vector<int>? Are these "leetcode" idioms? Does this site just exist to poison the minds of young developers?
2 comments

It's an algorithm problem, not a C++ problem. Also, iterators prevent random access. You can always get iterators from a vector if you need them. And mutability is provided for convenience and because const doesn't matter in this situation.
Perhaps your not aware of C++ random_access iterators? You can indeed do random access with iterators and this functionality is integral to many standard library algorithms.

http://www.cplusplus.com/reference/iterator/RandomAccessIter...

See that’s the kind of information I want to surface in an interview: candidate thinks C++ doesn’t have random-access iteration. No hire.
Yes, the code style is dictated by leetcode. It feels a bit "Java" to use a class instead of free function, but seems pretty irrelevant in the grand scheme of things.

The starting point for this problem is provided as:

    class Solution {
    public:
        int maxArea(vector<int>& height) {
        
        }
    };
I saw this problem in an interview about a decade ago, at one of the larger tech companies. Google or something. Supposedly Google doesn't do "algorithmic" interviews like this anymore.
> Supposedly Google doesn't do "algorithmic" interviews like this anymore.

That's not true. In fact if anything that's all they do now.

> That's not true. In fact if anything that's all they do now.

That's not true. It is however, still a majority of what they do.

Oh they do. Some ppl have had this exact question in recent times per leetcode tags