• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Had interview today...stumped by a technical question

lonelyt

Member
Software engineering position.

The interview went well, but there was one technical question I didn't know the answer to.

"What is the Object-oriented way to sort a two-dimensional array?"

I said to use a double for loop (couldn't think of anything), but the interviewer said that way is more of an algorithm....and repeated "What's the best Object-oriented way?"

She told me the answer afterwards (which I still don't really understand), I'll add that in after some replies?

Edit:
The answer: "Use the COMPARE function."
 
"the way is more of an algorithm". What?

I don't even understand the question, to be honest.

Maybe they were referring to the use of a Strategy pattern. That is a pattern and not simply an "algorithm" though. The search algorithm itself varies (that in fact is the point of a Strategy).

Or maybe they were just referring to implementing a Sortable interface...
 
What exactly does she mean by "sorting" a two-dimensional array?

You can break a two-dimensional array into multiple linear arrays and sort each of those, but you will get different results depending on how you divide the array.
 
Sounds like a silly question to me. Were they asking about how from a design perspective, or how as in an actual sample implementation? Also, there's no best way to do anything.

I'm guessing they were looking for an answer similar to the following:

Each item in the array would have knowledge of its dimension, and the array would contain those items. When a request to Sort the array was made the items would be iterated and each item would be asked for its sorting order. This has the effect of allowing jagged arrays as well. The key is that this description introduces a level of polymorphism for both array and items contained.

Or I could be way off. Sometimes when someone says, "Tell me in OO" they're looking for more of a description of the design as there's no way to say "show me how you'd implement this in OO" as OO itself has no actual description beyond the language used to implement it.
 
Originally posted by: torpid
"the way is more of an algorithm". What?

I don't even understand the question, to be honest.

Maybe they were referring to the use of a Strategy pattern. That is a pattern and not simply an "algorithm" though. The search algorithm itself varies (that in fact is the point of a Strategy).

Or maybe they were just referring to implementing a Sortable interface...

Good suggestion. I agree that the question doesn't make much sense; ambiguous, at best.
 
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.
 
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y


1 2 3
4 5 6
7 8 9
 
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?
 
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.
 
I was pretty confused by the question too. The answer: "Use the COMPARE function." I pretended like it made total sense because I didn't want to seem like stupid.
 
Originally posted by: lonelyt
Software engineering position.

The interview went well, but there was one technical question I didn't know the answer to.

"What is the Object-oriented way to sort a two-dimensional array?"

I said to use a double for loop (couldn't think of anything), but the interviewer said that way is more of an algorithm....and repeated "What's the best Object-oriented way?"

She told me the answer afterwards (which I still don't really understand), I'll add that in after some replies?

Sounds like she just read a neat little tidbit in a book and couldn't wait to "use" it in the real world.
 
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

huh? why not?
 
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

hehe. Time to go to back $100 cups of coffee for you.
 
What the hell kind of question and answer is that? What kind of development did they do? What tools/langs did they use? I would of told her that question is too open ended to bother and went home. I've turned down a few jobs do to interviews I had. Of course maybe thats why i'm still only a level 2 programmer.
 
just be thankful you can do stuff like a quicksort. I have no idea how to do them. I remember they asked me that in an interview and i just gave them a blank stare. It was at that point i decided to be an EE and stick to minor script coding.
 
I'm guessing the answer they wanted would be...if the object being used has a two-dimensional array sort method, then use that method, otherwise you'd have to write a sort method into the object class
 
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

Oh really?
 
Back
Top