FazeelUsmani / Amazon-SDE-Preparation

This repository includes all the interview preparation questions for Amazon SDE role
https://practice.geeksforgeeks.org/batch/Amazon-Test-Series
1.12k stars 291 forks source link

07 Linked List --> 3. Insert in a Sorted List #82

Closed FazeelUsmani closed 3 years ago

FazeelUsmani commented 3 years ago

Given a sorted singly linked list and a data, your task is to insert the data in the linked list in a sorted way i.e. order of the list doesn't change.

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 <= 104 -99999 <= A[i] <= 99999, for each valid i

CoderS2020 commented 3 years ago

I would like to contribute

FazeelUsmani commented 3 years ago

Sure, @CoderS2020. Assigning this issue to you