Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a linked list sorted in ascending order and an integer called data, insert data in the linked list such that the list remains sorted.

**Example 1:**

**Input:
**LinkedList: 25->36->47->58->69->80
data: 19
**Output: **19 25 36 47 58 69 80

**Example 2:**

**Input:
**LinkedList: 50->100
data: 75
**Output: **50 75 100

**Your Task:**

The task is to complete the function **sortedInsert**() which should insert the element in sorted Linked List and return the head of the linked list

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(1).

**Constraints:**

1 <= N <= 10^{4}

-99999 <= A[i] <= 99999, for each valid i

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Insert in a Sorted List

...