Had interview today...stumped by a technical question

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: Descartes
Are you people flipping serious, or are you just not developers? If not then I understand, and that's ok...

Absolutely serious and I am a developer.
 

stan394

Platinum Member
Jul 8, 2005
2,112
0
76
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes

That's not a 2-d array.

int stupidarray[4][3];

stupidarray[0][0] = 3;
stupidarray[0][1] = 1;
stupidarray[0][2] = 6;
...
stupidarray[3][0] = 5;
stupidarray[3][1] = 3;
stupidarray[3][2] = 7;

Maybe I've been away from code for too long, my last programming course did not require us to write a single line of code. Instead it was dealing with proofs of big O and Omegas of things like quicksort and that crap.

That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

for i = 0 to 3
.. for j = 0 to 2
.... print stupidarray[ I ][ j ]
.. println

no?

argh. can't get the indentation working
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: DAGTA
Originally posted by: Descartes
Originally posted by: DAGTA
Originally posted by: xospec1alk
Originally posted by: Gibson486
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.

x and y, what more do you want?


it has more than two dimensions....


It does? I'm waiting for you or Descartes to explain.

Assuming each digit in the above examples represent a discrete item in the array I think it should be obvious. If they are not discrete then you have a one-dimensional array, and if they are discrete you have a four-dimensional.

Either way it's not a two-dimensional.


Wow... and to think... you make more money than me....

A lot more I'm sure. What's your point?
 

five40

Golden Member
Oct 4, 2004
1,875
0
0
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes

That's not a 2-d array.

int stupidarray[4][3];

stupidarray[0][0] = 3;
stupidarray[0][1] = 1;
stupidarray[0][2] = 6;
...
stupidarray[3][0] = 5;
stupidarray[3][1] = 3;
stupidarray[3][2] = 7;

Maybe I've been away from code for too long, my last programming course did not require us to write a single line of code. Instead it was dealing with proofs of big O and Omegas of things like quicksort and that crap.

That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

Being a developer for 15+ years...you have NO IDEA what a 2d array is. What everyone has said is a 2d array is a 2d array. What BlueFlamme input is a 2d array.
 

PingSpike

Lifer
Feb 25, 2004
21,758
603
126
I'm not advanced programmer or anything...but wasn't what stan394 posted a 2-D array? I can't see why it isn't. I've only taken intro c++ and done a lot of game scripting so don't take what I'm saying as some master level programming knowledge here.

And "use the compare function"? What does that mean...does that even do the sorting? Isn't that just a piece of the code you might use to sort it?

This almost sounds like a question like "Whats the best way to build a boat?". Without any other specifics or constraints it seems like the only answer you could offer is more of an opinion then a fact.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes

That's not a 2-d array.

int stupidarray[4][3];

stupidarray[0][0] = 3;
stupidarray[0][1] = 1;
stupidarray[0][2] = 6;
...
stupidarray[3][0] = 5;
stupidarray[3][1] = 3;
stupidarray[3][2] = 7;

Maybe I've been away from code for too long, my last programming course did not require us to write a single line of code. Instead it was dealing with proofs of big O and Omegas of things like quicksort and that crap.

That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

Actually I'd say the above is not how I would represent the original list. Above would be
3 1 6
5 3 7

To me. That sort of visualization is typical in academic discussions of arrays. In some languages it will actually be accurate, beacuse 2d arrays are really just arrays of arrays, so each row represents an array. In other languages it would look like this because it's all stored in consecutive memory:

3 1 6 5 3 7
 

DAGTA

Diamond Member
Oct 9, 1999
8,172
1
0
Originally posted by: Descartes
Originally posted by: DAGTA
Originally posted by: Descartes
Originally posted by: DAGTA
Originally posted by: xospec1alk
Originally posted by: Gibson486
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.

x and y, what more do you want?


it has more than two dimensions....


It does? I'm waiting for you or Descartes to explain.

Assuming each digit in the above examples represent a discrete item in the array I think it should be obvious. If they are not discrete then you have a one-dimensional array, and if they are discrete you have a four-dimensional.

Either way it's not a two-dimensional.


Wow... and to think... you make more money than me....

A lot more I'm sure. What's your point?

May I suggest you pick up a remedial first year college book that includes a chapter in programming arrays. I've taught this stuff, in a university, with a senior professor and a dept chair checking my work... neither of them found flaws in my understanding of two dimensional arrays.
 

imported_Tick

Diamond Member
Feb 17, 2005
4,682
1
0
Originally posted by: Descartes
Originally posted by: DAGTA
Originally posted by: xospec1alk
Originally posted by: Gibson486
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.

x and y, what more do you want?


it has more than two dimensions....


It does? I'm waiting for you or Descartes to explain.

Assuming each digit in the above examples represent a discrete item in the array I think it should be obvious. If they are not discrete then you have a one-dimensional array, and if they are discrete you have a four-dimensional.

Either way it's not a two-dimensional.

Ok, I get that if the elements are not discrete, it's one dimensional, but how could i be 4 dimensional? Engineering major here, so I see it as 2 dimensions, (x,y) four dimensions would be (x,y,z,t) or (x,y,z,z-not) etc. How does that array have 4??
 

BlueFlamme

Senior member
Nov 3, 2005
565
0
0
Originally posted by: Descartes
[That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

It it just in the vizualiation imo. If you consider the first array as a column and the second array as the row then you can print out the rows followed by an endl with some code like the following:

for(k = 0, k <2, i++){
for(j = 0, j < 3, j++){
cout<<stupidarray[j][k]<<' ';
}
cout<<endl;
}

would yield the original array he proposed. Yeah, i screwed up the typical ordering of row then column, just view it as similar to a poetic license for coding. And I put a ... in there to represent the other two columns that I didn't type up to shorten the post.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: five40
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes

That's not a 2-d array.

int stupidarray[4][3];

stupidarray[0][0] = 3;
stupidarray[0][1] = 1;
stupidarray[0][2] = 6;
...
stupidarray[3][0] = 5;
stupidarray[3][1] = 3;
stupidarray[3][2] = 7;

Maybe I've been away from code for too long, my last programming course did not require us to write a single line of code. Instead it was dealing with proofs of big O and Omegas of things like quicksort and that crap.

That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

Being a developer for 15+ years...you have NO IDEA what a 2d array is. What everyone has said is a 2d array is a 2d array. What BlueFlamme input is a 2d array.

Hello ignoramus, read my post. I didn't say what he presented was NOT a 2d array. I was referring to the printed example earlier.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
stan's example of a 2d array is correct.. It's a int[3][4] array..

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

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

I'm assuming the interviewer meant to ask what's a method that can be used in OO programming to help you sort an object? You'd use the compare method or whatever available method to compare one object to another. The way the question is phrased makes it horribly hard to understand what's going on.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: PingSpike
I'm not advanced programmer or anything...but wasn't what stan394 posted a 2-D array? I can't see why it isn't. I've only taken intro c++ and done a lot of game scripting so don't take what I'm saying as some master level programming knowledge here.

Edit: Wait I see. Its been awhile....:p

And "use the compare function"? What does that mean...does that even do the sorting? Isn't that just a piece of the code you might use to sort it?

This almost sounds like a question like "Whats the best way to build a boat?". Without any other specifics or constraints it seems like the only answer you could offer is more of an opinion then a fact.

In some languages you can write code inside of an object that defines how to compare it to another object of the same type (or different type). Then when something requests a sort of an array or list of those objects, the function that is used to do the actual sort will do its sorting algorithm and use the function you wrote to determine whether object1 > object2.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: BlueFlamme
Originally posted by: Descartes
[That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

It it just in the vizualiation imo. If you consider the first array as a column and the second array as the row then you can print out the rows followed by an endl with some code like the following:

for(i = 0, i <2, i++){
for(j = 0, j < 3, j++){
cout<<stupidarray[j]<<' ';
}
cout<<endl;
}

would yield the original array he proposed. Yeah, i screwed up the typical ordering of row then column, just view it as similar to a poetic license for coding.


Thank you for kind and very accurate reply. You have summarized my thoughts, what I attempted to convey, etc. without doing so condescendingly.

This is all I meant to say. Don't know why it incited such a riot. Guess a lot of people have it out for me.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
A four dimensional array would change over time without any manual intervention, or something.
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: PingSpike
I'm not advanced programmer or anything...but wasn't what stan394 posted a 2-D array? I can't see why it isn't. I've only taken intro c++ and done a lot of game scripting so don't take what I'm saying as some master level programming knowledge here.

And "use the compare function"? What does that mean...does that even do the sorting? Isn't that just a piece of the code you might use to sort it?

This almost sounds like a question like "Whats the best way to build a boat?". Without any other specifics or constraints it seems like the only answer you could offer is more of an opinion then a fact.

Yep. The interviewers question was terribly ambiguous and her answer was only one element of what would have been the final solution. I would question whether or not she could actually accomplish it herself, start to finish.

"Well sh*t... I called 'compare()', but all I got was this stupid useless int and nothing is sorted WTF"
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
Originally posted by: Descartes

Hello ignoramus, read my post. I didn't say what he presented was NOT a 2d array. I was referring to the printed example earlier.

What stan posted here?

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?

How is that not a 2-dimnesional array? 3 rows by 4 columns?
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: Howard
I stll don't understand how it's not a 2D array...

Because Descartes is choosing to ignore the obvious and interpret it in a way that he knows the person who posted it did not intend. He's nitpicking about the printed representation in an attempt to make himself look smarter.
 

five40

Golden Member
Oct 4, 2004
1,875
0
0
Originally posted by: Descartes
Originally posted by: five40
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes

That's not a 2-d array.

int stupidarray[4][3];

stupidarray[0][0] = 3;
stupidarray[0][1] = 1;
stupidarray[0][2] = 6;
...
stupidarray[3][0] = 5;
stupidarray[3][1] = 3;
stupidarray[3][2] = 7;

Maybe I've been away from code for too long, my last programming course did not require us to write a single line of code. Instead it was dealing with proofs of big O and Omegas of things like quicksort and that crap.

That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

Being a developer for 15+ years...you have NO IDEA what a 2d array is. What everyone has said is a 2d array is a 2d array. What BlueFlamme input is a 2d array.

Hello ignoramus, read my post. I didn't say what he presented was NOT a 2d array. I was referring to the printed example earlier.

Hello retard. Read your earlier posts where you have NO IDEA WHAT A 2D ARRAY IS. I guess reading the first quote in the post would suffice as well. Hey I've got a $1000 cup of coffee for sale. You not listening to the people in the thread is like people not listening to your very good opinion on coffee.
 

DAGTA

Diamond Member
Oct 9, 1999
8,172
1
0
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes
[That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

It it just in the vizualiation imo. If you consider the first array as a column and the second array as the row then you can print out the rows followed by an endl with some code like the following:

for(i = 0, i <2, i++){
for(j = 0, j < 3, j++){
cout<<stupidarray[j]<<' ';
}
cout<<endl;
}

would yield the original array he proposed. Yeah, i screwed up the typical ordering of row then column, just view it as similar to a poetic license for coding.


Thank you for kind and very accurate reply. You have summarized my thoughts, what I attempted to convey, etc. without doing so condescendingly.

This is all I meant to say. Don't know why it incited such a riot. Guess a lot of people have it out for me.


I don't think anyone has it out for you. Your condescending attitude certainly doesn't help, but the fact is you are wrong. It is a 2-dimensional array and most first year programming students could tell you that.
 

imported_Tick

Diamond Member
Feb 17, 2005
4,682
1
0
Originally posted by: Descartes
Originally posted by: BlueFlamme
Originally posted by: Descartes
[That's fine, now print and out and tell me what you expect it to look like. Perhaps I'm just looking at its printed representation differently than others in this thread, but I don't see how that's possible.

It it just in the vizualiation imo. If you consider the first array as a column and the second array as the row then you can print out the rows followed by an endl with some code like the following:

for(i = 0, i <2, i++){
for(j = 0, j < 3, j++){
cout<<stupidarray[j]<<' ';
}
cout<<endl;
}

would yield the original array he proposed. Yeah, i screwed up the typical ordering of row then column, just view it as similar to a poetic license for coding.


Thank you for kind and very accurate reply. You have summarized my thoughts, what I attempted to convey, etc. without doing so condescendingly.

This is all I meant to say. Don't know why it incited such a riot. Guess a lot of people have it out for me.


Please explain.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: BigJ
Originally posted by: Descartes

Hello ignoramus, read my post. I didn't say what he presented was NOT a 2d array. I was referring to the printed example earlier.

What Gibson posted here?

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?

How is that not a 2-dimnesional array? 3 rows by 4 columns?

Well technically it's just a big string with spaces and carriage returns.
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
Originally posted by: torpid
Originally posted by: BigJ
Originally posted by: Descartes

Hello ignoramus, read my post. I didn't say what he presented was NOT a 2d array. I was referring to the printed example earlier.

What Gibson posted here?

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?

How is that not a 2-dimnesional array? 3 rows by 4 columns?

Well technically it's just a big string with spaces and carriage returns.

Bastard ;)
 

imported_Tick

Diamond Member
Feb 17, 2005
4,682
1
0
Originally posted by: mugs
Originally posted by: Howard
I stll don't understand how it's not a 2D array...

Because Descartes is choosing to ignore the obvious and interpret it in a way that he knows the person who posted it did not intend. He's nitpicking about the printed representation in an attempt to make himself look smarter.

Please do explain.