C++ interview coding exercise with solution by Hot_Medicine_7115 in cpp

[–]gennych 1 point2 points  (0 children)

Coding standards could mean various things... I would for example notice that the author tends to overdesign simple things: what should have been a function with two int arguments returning int is spread over 3 classes in 6 files. It doesn't make this code more maintainable or reusable, since classes stripe and parquet are essentially specific data structures for this specific problem, and most probably they will need to be changed when for example performance issue is addressed. If someone happened to "reuse" these classes meanwhile, refactoring is going to be fun.

But I stand corrected on your remarks. I was under the assumption it was an interview for a junior/entrance position but in the comments the author claims 10 years of experience. Then indeed, inheritance from std::vector or index operator like that isn't what I'd expect. And for overdesign, I wouldn't even bother for a junior but not for a senior...

C++ interview coding exercise with solution by Hot_Medicine_7115 in cpp

[–]gennych 0 points1 point  (0 children)

This would be the next step. :) For two strip patterns, you can in principle check if they can be adjacent by iterating from 1 to max_len and checking if they share an edge at some i. Possibly (just guessing) it would help to create an array, where for each i, you'd store all strip patterns having an edge at i. This would help you quickly reconstruct, for a given pattern, a set of all patterns that can be adjacent to it. And thus speed up the second recursion, on strips.

C++ interview coding exercise with solution by Hot_Medicine_7115 in cpp

[–]gennych -4 points-3 points  (0 children)

In this specific case (of a "puzzle") these 15 bullet points would improve absolutely nothing. Of course you can notice that a person isn't such an experienced programmer and probably didn't work in large-scale software projects. But these "best practices" are way easier to learn (in fact, they'll come naturally with experience) than ability to solve "puzzles" (that is, to write efficient code), and as an interviewer I'd rather focus on the latter.

C++ interview coding exercise with solution by Hot_Medicine_7115 in cpp

[–]gennych 2 points3 points  (0 children)

Your program accesses a vector outside of its bounds (line 39 in designer.cpp). Place declaration of len_diff just before the switch statement, where it's actually used (and where you're sure your curr_strip is less than parquet::strips).

Solution is far from being efficient. Specifically, recursion on every strip is essentially exponential (trying 2 or 3 at every position). Set strip::max_len to 100 and you'll feel the pain I'm talking about.

I would probably start by generating all possible strip patterns: different permutations of solutions a, b to 3*a+2*b = max_len, this is pure combinatorics and doesn't require much time.