You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defgreater(a, b, i , j): # get the number which is lexiographically greater
15
-
whilei<len(a) orj<len(b):
16
+
whilei<len(a) orj<len(b):
16
17
ifi==len(a): returnFalse
17
18
ifj==len(b): returnTrue
18
19
ifa[i] >b[j]: returnTrue
19
20
ifa[i] <b[j]: returnFalse
20
21
i+=1# we increment until each of their elements are same
21
22
j+=1
22
-
23
+
23
24
defmerge(x_num, y_num):
24
25
n=len(x_num)
25
26
m=len(y_num)
26
27
i=0
27
28
j=0
28
29
s= []
29
30
whilei<norj<m:
30
-
a=x_num[i] ifi<nelsefloat("-inf")
31
-
b=y_num[j] ifj<melsefloat("-inf")
31
+
a=x_num[i] ifi<nelsefloat("-inf")
32
+
b=y_num[j] ifj<melsefloat("-inf")
32
33
33
34
ifa>borgreater(x_num, y_num, i , j):
34
35
# greater(x_num, y_num, i , j): this function is meant for check which list has element lexicographically greater means it will iterate through both arrays incrementing both at the same time until one of them is greater than other.
@@ -46,10 +47,9 @@ def merge(x_num, y_num):
46
47
second=maximum_num_each_list(nums2, k-i)
47
48
merged=merge(first, second)
48
49
# these two conditions are required because list comparison in python only compares the elements even if one of their lengths is greater, so I had to add these conditions to compare elements only if length is equal.
49
-
# Alternatively you can avoid this and convert them both to int and then compare, but I wanted to this as it is somewhat more efficient.
0 commit comments