Merge Two Sorted Arrays Leetcode GeeksforGeeks in java in telugu | DSA interview question
HTML-код
- Опубликовано: 7 сен 2024
- Join our Telegram group for daily assignments:
t.me/+oRkO0JQe...
Practice Link : www.geeksforge...
merge two sorted arrays,
merge two sorted arrays without extra space,
merge two sorted arrays in java,
merge two sorted arrays leetcode,
merge two sorted arrays in c,
merge two sorted arrays in python,
merge two sorted arrays without extra space leetcode,
merge two sorted arrays leetcode java,
merge two sorted arrays tamil,
merge two sorted arrays javascript,
merge k sorted arrays divide and conquer,
merge k sorted arrays love babbar,
merge two sorted arrays c++,
merge two sorted lists c++,
merge k sorted arrays c++,
merge two sorted lists cpp,
merge 2 sorted arrays c++,
merge k sorted lists c++,
merge two sorted linked lists c++,
merge k sorted lists leetcode c++,
c program to merge two sorted arrays,
merge two sorted arrays without extra space c++,
merge two arrays of same size sorted in descending order,
merge two sorted lists explained,
merge two sorted arrays without extra space java,
efficiently merging two sorted array with o1) extra space,
given two sorted arrays merge them without extra space,
merge k sorted arrays gfg,
merge k sorted linked lists gfg,
merge k sorted arrays heap,
merge k sorted lists heap,
merge k sorted arrays using heap,
merge two sorted linked lists hackerrank,
merge k sorted lists using heap,
merge k sorted lists min heap,
how to merge two sorted arrays,
how to merge two sorted arrays in java,
merge two sorted array with o1) extra space,
merge two sorted arrays in javascript,
merge two sorted arrays in leetcode,
merge two sorted array in place,
merge two sorted lists in java,
merge two sorted lists in python,
merge two sorted lists in c,
merge k sorted arrays in java,
merge two sorted arrays without extra space in java,
merge two sorted arrays java,
merge two sorted arrays js,
merge two sorted lists java
#1st approach code in python:
arr1 = [1, 2, 4, 5]
arr2 = [0, 3, 7, 8, 9]
ans = [] # Initialize an empty list to store the result
i, j = 0, 0
# Merge the two arrays
while i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
ans.append(arr1[i])
i += 1
else:
ans.append(arr2[j])
j += 1
# Append remaining elements of arr1, if any
while i < len(arr1):
ans.append(arr1[i])
i += 1
# Append remaining elements of arr2, if any
while j < len(arr2):
ans.append(arr2[j])
j += 1
print(ans)
#2nd approach code in python
arr1 = [1, 2, 4, 5]
arr2 = [0, 3, 7, 8, 9]
# Swap elements to balance the two arrays
i = len(arr1) - 1
j = 0
while i >= 0 and j < len(arr2):
if arr1[i] > arr2[j]:
arr1[i], arr2[j] = arr2[j], arr1[i]
i -= 1
j += 1
else:
break
# Sort both arrays
arr1.sort()
arr2.sort()
# Concatenate the sorted arrays
result = arr1 + arr2
print(result) # Output: [0, 1, 2, 3, 4, 5, 7, 8, 9]
Upload in english bro so it'll be useful for everyone
Bro dp topic nkaa problems chepandi
DSA with python beginners to pro level course chy broo
playlist create cheyu bro classes ani
Ok 👍