Programming Languages
Python
Subjective
Sep 30, 2025
Write a Python function to merge two sorted lists into one sorted list.
Detailed Explanation
def merge_sorted_lists(list1, list2):\n result = []\n i = j = 0\n while i < len(list1) and j < len(list2):\n if list1[i] <= list2[j]:\n result.append(list1[i])\n i += 1\n else:\n result.append(list2[j])\n j += 1\n result.extend(list1[i:])\n result.extend(list2[j:])\n return result
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts