Amazon Interview Question
SDE-2sTeam: Product Details Page
Country: India
Interview Type: In-Person
Not Much different from last
void smartModify(list *head, int m, int n){
if (head == NULL) return;
list *cur = head;
while (cur != NULL){
list *mnode = NULL;
list *nnode = NULL;
int mnum = m;
int nnum = n;
while (cur != NULL && mnum > 0){
if (--mnum == 0) mnode = cur;
cur = cur->next;
}
while (cur != NULL && nnum > 0){
if (--nnum == 0) nnode = cur;
cur = cur->next;
}
if (mnode)
mnode->next = (nnode == NULL) ? NULL : nnode->next;
}
}
Only considere cases when m >= 1 and n >= 1
- hnatsu March 04, 2016