Insert Node in Doubly Linked List

Doubly Linked List: Fundamentals DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Insert a node at the end of a doubly linked list, Doubly Linked List, Node, Pointer, Time Complexity, Space Complexity, space complexity, linked list traversal, node operations, pointer operations, linked list, time complexity analysis, Linked List Operations.

Problem Statement Given the head of a doubly linked list and an integer k, insert a new node with value k at the end of the doubly linked list. Input Format: The first line contains the elements of the doubly linked list, represented as val1 < val2 < ... < valN. The second line contains an integer k, the value to be inserted. Output Format: Print the modified doubly linked list after inserting the node with value k at the end, in the format val1 < val2 < ... < valN < k. Examples Example 1: Input Format: Result: Explanation: A new node with value 6 has been inserted at the end of the doubly linked list after the tail node. Example 2: Input Format: Result: Explanation: A new node with value 40 is inserted after 30 which is at the end of the doubly linked list.