Google Interview Question for Software Engineer / Developers


Country: United States




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

if it's really about the space, you can just store coordinates of the head and the rest of the snake store as a linked list containing the 2bit flag: UP/DOWN/LEFT/RIGHT

then, when you move the head up, you need to calculate a new position of each "limb" of the snake starting from the head and going down to the tail. Then if it happens that the new position of the head coincides with that of one of the limbs, game is over..Otherwise, you just update 2bit flags in your linked list according to new positions

- 111 February 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 5 vote

just move the one on the tail to the square on top of the head? (if the square on the on top of the head is filled, then stop)

- Anonymous February 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

not enough. what about the tail?

- adam2008 February 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What about the tail?? Can u please explain.. I could not figure out the problem...

- Bevan February 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Anon is right, its just moving tail to head.

lets say snake is of size 3 at HEAD->(2,2)->(3,2)->(4,2)->NULL,
then on MoveUp we,
1) update 4,2 => 1,2
2) (1,2) points to (2,2)
2) (3,2) ->NULL

so new list is
HEAD ->(1,2) -> (2,2)->(3,2)->NULL

There will be check to see if snake reaches 0th row, in that case he will die.

Also seperate thread will be adding new elements at the end of LL after N seconds.

to implement moves across all directions it needs to be double LL.

- kasi.beck February 22, 2013 | Flag


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