Sign In
Mark Schmidt's Abode
On Programming, Writing, Gaming, Fitness, Life
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tags
.NET
animation
Avalon
BizTalk Server
C/C++
Cool Stuff
Humor
Misc
Pages
RosettaNet Accelerator
Technical Writing
WF Designer Hosting
Windows Workflow Foundation
WPF
Xml
Xslt
Archive
Archives
April 2009
(1)
March 2009
(1)
June 2008
(1)
February 2008
(1)
January 2008
(1)
December 2007
(4)
November 2007
(5)
October 2007
(1)
September 2007
(4)
August 2007
(4)
July 2007
(4)
June 2007
(2)
March 2007
(2)
February 2007
(1)
January 2007
(2)
October 2006
(1)
September 2006
(2)
August 2006
(2)
June 2006
(2)
March 2006
(2)
January 2006
(1)
October 2005
(4)
September 2005
(7)
August 2005
(1)
April 2005
(1)
March 2005
(1)
December 2004
(1)
November 2004
(1)
October 2004
(3)
September 2004
(2)
August 2004
(4)
Interview question. Do you know the answer? Is it too tough?
MSDN Blogs
>
Mark Schmidt's Abode
>
Interview question. Do you know the answer? Is it too tough?
Interview question. Do you know the answer? Is it too tough?
markhsch
22 Sep 2005 6:35 PM
Comments
20
I've written 2 books in my life and while writing my 2nd book a question popped into my head out of nowhere and consumed me for the better part of an hour or so. The book was a "cookbook" and so I had to think of problems and then give the solution. Here's the question:
Let's say you had a multidimensional array. For the purposes of the discussion, let's say it's int[,,] arr1 = new int[3,3,3]; If I were to write this array out, I would have something similar to the following (the numbers I'm writing out let's say are the actual values in that array):
1 2 3 10 11 12 19 20 21
mdArray = 4 5 6 13 14 15 22 23 24
7 8 9 16 17 18 25 26 27
If I give you a single integer representing the index of an item in that array if that array were flattened, return the dimension indicies that value is at in the original multidimensional array. In other words, if we flatten out the array represented above to:
flatArray = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
and I told you to return the indices of the value whose flattened array index is 12 (value would be the #13 above since it's at flatArray[12]) you would return the mdArray indices [1,1,0]. If I gave you a flat index value of 1, you would return [0,0,1] which is where the value #2 shows up in the multidimensional array. As a starter, here's the function declaration:
int[] GetDimensionalIndices( int flatIndex, Array mdArray )
{
// TODO
}
Couple of things to note here:
1. It doesn't have to a 3x3x3 array. It could be a 2x3x4 or a 4x3x2x2 or some other multidimensional array.
2. The Array class has some methods which may help you.
There you go. Reply with an answer or a comment along the lines of "you'd ask that on an interview. You crazy?" or "That's a good interview question".
-Mark
20 Comments
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 3 and 6 and type the answer here:
Post