Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

if they are fixed size a reference to an array of array of array ...
if readonly a const reference

void methode(std::array<std::array<int, n>, m>& array)

if all dimensions are variable, vector of vector which has the issue that each vector has its own size, so it's not necessarily a multidimensional array as we are used to and it's hacky to access the dimension's size

For a matrix I wouldn't use a built in STL type because it will force you to a data representation which might not be what you want e.g. if you want to represent sparse matrix in a memory efficient way.

implementing your own matrix class would be the most effective way to go (except for a coding contest where implementation speed matters more). There you would keep the dimensions and the data seperated and implement a getElement and setElement method. don't get tricked into implementiong something like "[][]-operator" which is a pain due to referencing etc...

what you can do, if you want to provide syntactical sugar is "T& operator() (int row, int col)"

You can as well study the problems of vector<bool> which is a specialized vector (bit-vector) and provides something like:

bool_proxy& operator []

where bool proxy contains conversion to bool ... etc. etc.

- ChrisK March 21, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More