We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dfb968a commit 5b4fa96Copy full SHA for 5b4fa96
interview_query/Merge Sorted Lists.py
@@ -0,0 +1,26 @@
1
+Given two sorted lists, write a function to merge them into one sorted list.
2
+
3
+Bonus: What’s the time complexity?
4
5
+def merge_list(t1, t2):
6
7
+ p1 = 0
8
+ p2 = 0
9
10
+ res = []
11
12
+ while p1 < len(t1) and p2 < len(t2):
13
14
+ if t1[p1]< t2[p2]:
15
+ res.append(t1[p1])
16
+ p1+=1
17
+ elif t1[p1]>= t2[p2]:
18
+ res.append(t2[p2])
19
+ p2+=1
20
21
22
+ if p1 < len(t1):
23
+ res.extend(t1[p1:])
24
+ elif p2 < len(t2):
25
+ res.extend(t2[p2:])
26
+ return res
0 commit comments