K17

Merge Two Sorted Lists

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list.

Function Signature (Python)

merge_sorted_lists(d1: list, head1: int, d2: list, head2: int) -> list[list[int]]

Input & Output Contract

Output Rule:[[liste_no, indeks], ...] birleşik artan sırada. Eşit değerde liste 1 önceliklidir. İkisi de boşsa [].

System Constraints

0 <= her iki listenin düğüm sayısı, toplam <= 50
-100 <= değer <= 100
Her liste kendi içinde artan sıralıdır (eşitlere izin vardır)
bas == -1 ise o liste boştur

Example Execution Walkthrough

d1 = [[1,1],[2,2],[4,-1]] bas1 = 0
d2 = [[1,1],[3,2],[4,-1]] bas2 = 0
Değerler 1,1,2,3,4,4 ve eşitlikte liste 1 önde:
[[1,0],[2,0],[1,1],[2,1],[1,2],[2,2]]

Example Test Scenarios (3)

Example 1
Input:[[[1,1],[2,2],[4,-1]],0,[[1,1],[3,2],[4,-1]],0]
Expected Output:[[1,0],[2,0],[1,1],[2,1],[1,2],[2,2]]
Example 2: İkisi Boş
Input:[[],-1,[],-1]
Expected Output:[]
Example 3: Biri Boş
Input:[[],-1,[[0,-1]],0]
Expected Output:[[2,0]]
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      4,
      -1
    ]
  ],
  0,
  [
    [
      1,
      1
    ],
    [
      3,
      2
    ],
    [
      4,
      -1
    ]
  ],
  0
]
Expected Output
[
  [
    1,
    0
  ],
  [
    2,
    0
  ],
  [
    1,
    1
  ],
  [
    2,
    1
  ],
  [
    1,
    2
  ],
  [
    2,
    2
  ]
]