4 ms·
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
by rwem 7y 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?
- mcpherrinm 7y agoYes, 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.
- krackers 7y ago> Supposedly Google doesn't do "algorithmic" interviews like this anymore. That's not true. In fact if anything that's all they do now.
- ThePadawan 7y ago> 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.
- Infinitesimus 7y agoOh they do. Some ppl have had this exact question in recent times per leetcode tags
- lonelappde 7y agoIt'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.
- jdsully 7y agoPerhaps 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/RandomAccessIterator/ http://www.cplusplus.com/reference/iterator/RandomAccessIter...
- rwem 7y agoSee that’s the kind of information I want to surface in an interview: candidate thinks C++ doesn’t have random-access iteration. No hire.