Should be O(n) where n is the number of inputs.

Keep a displacement info for 4 directions ... strictly in this order: right,
down, left, up.  Starting from the top left corner/cell and current
direction is right ... continue putting the numbers one by one and advance
the cell based on your current direction.  If in any case you end up out of
bounds or visited an already visited cell, ... just use the next direction.

Or, probably I'm missing something here?


On 12/5/06, hijkl <[EMAIL PROTECTED]> wrote:
>
>
> this question was asked by Google..
> "Write a program of spiral matrix"
> ie. it takes inputs and puts in to matrix as a spiral..example.
> given : 3 X 4 matrix
> your input in this order : 1 5 8 9 10 7 4 8 0 2 3 6
> will generate following matrix
>
> 1  5  8  9
> 2  3  6  10
> 0  8  4  7
>
> and big O notation for this..
>
> i tried but my method seems senseless..anybody having idea how to solve
> this??
>
> ok njoy
>
>
> >
>


-- 
Fear of the LORD is the beginning of knowledge (Proverbs 1:7)


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to