Interview Question


Country: United States




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

1402
Assuming a[y][x] = N*y+x (starting from 0)
a[5][5] = N*5+5 = 1000 => N=995/5=199

a[7][9] = N*7+9 = 199*7+9 = 1402

- Anonymous August 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

the odds of an array address starting from 0 is 0...You need to know the address of a[0][0] to normalize the address...even with this information, you are still dead without the type. Your calculations assume this is a char array, changing the type will change the calculations.

For example assume int (size 4).

a[5][5]=N*4*5+5*4=1000 => N=49
a[7][9]=49*7*4+9*4=1408

All in all I agree with your approach, but more agree with everyone else...you do not want to work here

- Anonymous August 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming it's int a[5][5] is equivalent to 5*5 = 25th int which would be 25*4 = 100 bytes from th e start. and with similar logic a[7][9] would be 63th int. difference between the two is 63 - 25 = 38 so 38 * 4 = 152. add that to 1000 so that address would be 1152.

- sameepsheth August 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Rubbish..

- teli.vaibhav August 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

I am teling you Vaibhav, you are right. Absolute Rubbish.

- Anonymous August 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

No need for any assumptions. Looks like the interviewer expects a cross question on this.

- kr.neerav August 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I also got curious and tried, my logic was right, its 24th element from [5][5] with int as 4 bytes it is +96 address of a[5][5]

Tried a C program for same and this is the address which verfies it

Address of a[5][5] is 1821490124
Address of a[7][9] is 1821490220

- Cleonjoys August 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How is it the 24th element from a[5][5] ? if the total size of the array was say a[50][50] ?

- shiv093 September 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is the maximum column size of the array a? Without that it is difficult to say.

- S August 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Agree...rubbish question.

- Mritunjay Kumar August 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The interviewer is testing your understanding of the lower-level implementation of these things. There's no way of knowing how to proceed without knowledge of the following:

1. Is the matrix notation implemented with a contiguously allocated backing array such that
a[][] = new matrix[5][5]; is structurally similar to a[] = new array[25]; but supports special matrix manipulation operators at the higher level?

2. What is the size of the elements in the matrix, including any alignment overhead etc.

3. Assuming address 0 is reserved for 'null' and the size of the elements has been given. Does the derived address seem valid or does it need further cross-examination.

- enzeart August 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BaseAddress + sizeof(typeofArray)*( TotalNoOfColumns*X + Y)
this is a 2D array formula where X & Y desire position rowth and column

- vishgupta92 July 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The answer is, "thank you for your time" (and walk out).

- Anonymous August 05, 2014 | 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