Goldman Sachs Interview Question for Developer Program Engineers






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

add addresses of the node in hast table and every time check the table when new node is accessed if address value all ready exist then there is loop in the list
/////============code
ptr=strat;
while(ptr!=NULL)
{
if(hash_has(ptr))
return "LOOP"
else
hash_insert(ptr);///insert into hash
ptr=ptr->nxt;
}
return "NO_LOOP"
=========================================

- rinku February 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

make to pointers..
increase the first one by 1 and the second one by 2 nodes..
where ever they are equal or fast pointer overtakes second one => loop detected.

while(fast->next==null)
{
 if(fast == slow || fast->next == slow)
  {//loop detected}
}

- RV May 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

initializing
slow = head;
fast = slow->next;

and forget to increment the pointers.
slow=slow->next;
fast=fast->next;

- RV May 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

This is incorrect and incomplete

- Sathishkumar February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Traverse a linked list with two pointers .. one immediately followed by other one. if ter is a loop , the condition mentioned above is met..cool :)

- Sathish_master June 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The eighth node pointing to the third node, can also be a loop. Then you 'two pointers' logic will not work. :)

- ramblersm July 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

walk through the linked list {

if current node exists in idSet{ return true;}
else idSet.add(current node's id)
}

should be o(n).

- Anonymous June 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use Floyd cyclic detection algorithm, Have two pointers one is slow and other is fast.
Here slow iterates with one step and fast iterates with two steps.
At any time, when slow is equal to fast, terminate the algorithm.

Worse case is - O(n)

- Hari July 27, 2012 | 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