#9 Daily Problems -MergeTwoLinkedLists

Hi guys today is my 9th day of coding practice and solving one problem per day.

Problem:

Note: Your solution should have O(l1.length + l2.length) time complexity, since this is what you will be asked to accomplish in an interview.

Given two singly linked lists sorted in non-decreasing order, your task is to merge them. In other words, return a singly linked list, also sorted in non-decreasing order, that contains the elements from both original lists.

Example

  • For l1 = [1, 2, 3] and l2 = [4, 5, 6], the output should be
    mergeTwoLinkedLists(l1, l2) = [1, 2, 3, 4, 5, 6];
  • For l1 = [1, 1, 2, 4] and l2 = [0, 3, 5], the output should be
    mergeTwoLinkedLists(l1, l2) = [0, 1, 1, 2, 3, 4, 5].

Input/Output

  • [execution time limit] 3 seconds (java)
  • [input] linkedlist.integer l1
  • A singly linked list of integers.
  • Guaranteed constraints:
    0 ≤ list size ≤ 104,
    -109 ≤ element value ≤ 109.
  • [input] linkedlist.integer l2
  • A singly linked list of integers.
  • Guaranteed constraints:
    0 ≤ list size ≤ 104,
    -109 ≤ element value ≤ 109.
  • [output] linkedlist.integer
  • A list that contains elements from both l1 and l2, sorted in non-decreasing order.

My Solution:

Hey guys please see my solution help me to improve myself. Lets meet tomorrow with another problem solving things.

--

--

Android developer at FundsIndia, A time investor to learn new things about Android, street cricketer. Currently in a relationship with Green Bug(Android).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arun Pandian M

Android developer at FundsIndia, A time investor to learn new things about Android, street cricketer. Currently in a relationship with Green Bug(Android).