Erik
BAN USER- 1of 1 vote
AnswersImplement multithreaded rm -r <folder>, i.e recursively delete files/folder under <folder> by walking through it and assume there can be billions of files under folder and you can only delete folder if all contents in it are first deleted
- Erik in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm
Nodeptr ReverseN(Nodeptr head, int number) {
if(number < 2) return head;
Nodeptr pre_sub_list_tail = NULL, curr_ptr = head, reversed_list_head = NULL;
while(curr_ptr) {
Nodeptr prev_ptr = NULL, nxt_ptr = NULL, sub_list_tail = NULL, sub_list_head = NULL;
int count = number;
while(curr_ptr && count) {
if(number == count) sub_list_tail = curr_ptr;
nxt_ptr = curr_ptr->nxtptr;
curr_ptr->nxtptr = prev_ptr;
prev_ptr = curr_ptr;
curr_ptr = nxt_ptr;
--count;
if(curr_ptr == NULL) sub_list_head = prev_ptr;
else if(count == 1) sub_list_head = curr_ptr;
}
if(pre_sub_list_tail) {
pre_sub_list_tail->nxtptr = sub_list_head;
}else {
reversed_list_head = sub_list_head;
}
pre_sub_list_tail = sub_list_tail;
}
return reversed_list_head;
}
How about in this case?
- Erik July 26, 2017