Quick actions

cmd+k|ctrl+k

Navigation

Languages

Merging Two Sorted lists 🔥

Snippet info

Language

Python

Visibility

public

Author

krishnakanth

Created

2023-08-22T02:01:24.843758Z

Updated

2023-08-22T02:01:24.843758Z

lis1 = list(map(int,input().split()))
lis2 = list(map(int,input().split()))

def MergeSorted(l1,l2):
    i,j = 0,0
    merge = []
    while i<len(l1) and j<len(l2):
        
        if l1[i] <= l2[j]:
            merge.append(l1[i])
            i+=1
        elif l1[i] > l2[j]:
            merge.append(l2[j])
            j+=1

    if i < len(l1):
        merge += l1[i:]
    elif j < len(l2):
        merge += l2[j:]

    return merge

print(MergeSorted(lis1,lis2))
INFO