# Top C Programming Interview Questions (2022) – InterviewBit

Merge two sorted linked lists and return them as a screen list. The list should be made by splicing together the nodes of the first two lists .Merging Two Sorted Linked List

`````` NodePtr merge_sorted (NodePtr head1, NodePtr head2)Reading: Top C Programming Interview Questions (2022) - InterviewBit  {

}  else  if (head2 ==  nullptr) {
}

}  else {
}

while (head1 !=  nullptr && head2 !=  nullptr Read more: Top 7 the who interview questions in 2022 ) {
NodePtr temp =  nullptr;
}  else {
}

mergedTail->next = temp;
mergedTail = temp;
}

}  else  if (head2 !=  nullptr) {
}

}``````

Runtime Complexity Linear, O ( molarity + north ) where molarity and normality are lengths of both linked lists. Memory Complexity Constant, O ( 1 ) Maintain a head and a tail pointer on the merged linked list. then choose the head of the merged linked list by comparing the first lymph node of both linked lists. For all subsequent nodes in both lists, you choose the smaller current node and link it to the tail of the unite tilt, moving the current cursor of that number one step forward. You keep doing this while there are some remaining elements in both lists. If there are hush some elements in only one of the lists, you link this remaining list to the tail of the blend list.

initially, the merged linked tilt is NULL. Compare the value of the first two nodes and make the node with the smaller value the point lymph node of the merged linked list. In this model, it is 4 from head1. Since it ’ s the first and alone node in the blend list, it will besides be the buttocks. then move head1 one step forward .

### Conclusion

C is the foundational language from which practically all early languages are built. C is the program language ‘s base. For writing system applications, it is a identical democratic and frequently used lyric. evening if fresh languages have surpassed it in popularity, it remains one of the most popular program languages. The C questions listed hera will aid you in interviews ampere well as improve your learn. I hope you found these to be helpful !