Microsoft Interview Question: The coding question was how t... | Glassdoor

Interview Question

Software Development Engineer In Test (SDET) Interview Redmond, WA

The coding question was how to detect if a singularly

  linked-list is cyclic. Also discuss optimization of the solution and code it in any language of your choice.
Tags:
technical, behavioral, algorithm
Answer

Interview Answer

1 Answer

0

void cyclic(list *node){
    list *fast, *slow;
    slow = node->next;
    fast = node->next->next;
    while(slow != fast && fast != NULL && fast->next != NULL){
        slow = slow->next;
        fast = fast->next->next;
    }
    if(slow == fast){
        printf("\nCycle present\n");
    }
    else{
        printf("\nCycle not present\n");
    }
}

Anonymous on Dec 31, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.