Today's Problem: leetcode.com/problems/merge-sorted-array/description/ Adjust playback speed according to your pace Don't forget to try solving "merge 3 sorted arrays", happy coding!
Hi akka, me explanation chala baga artam avutondi..meru ilage continue cheyandi...Me comfort bcoz ikada okokaru okolaga cheptunaru..okariki java lo o/p chupiyalanta inkokariki inko language..you can't match all of that.. Logic okate ga denikaina..we all will try..!!! Lots of love akka..keep Rocking!!!
write the code in java or else convert the same c++ code into java using chatgpt and show us please so that java devlopers can understand , your way of thinking is good .
First explanation ichi, tarwatha brute force lo chesi danni chinna ga efficient ga change cheste inka easy ga ardamavuthundi, okesari efficient ga raste ardam avvadhu
Hi srinidhi nenu c# language lo code chesthanu DSA ki meru cheppina gfg use chedam ani start chesanu but practicing purpose ki naku c# language chupinchatledu only c++,java,python ave vunnai.. other platforms emanna vunnaya lekapothe gfg lo c# practicing emanna option vunda help chesthara...
I searched but ala merge 3 sorted arrays ane question ledu specific ga anduke sample inputs outputs icha so that u can test. Purpose of giving that task is adi chesar antee idi question clarity ga ardaminattu
Hi sister, Nenu DSA with c++ nerchukuntunna, ippudu recursion topic daggara unnanu, na doubt enti ante 1:- recent ga konni articles chadivanu ila C++ ni US govt ban chayali ani order icchindhi ani as it not memory safe, so C++ tho DSA nerchukovadam better option eh na or else shall I move to another language. 2 :- inko doubt sis, as im learning DSA with C++, should i stick with it or move to Java with C++ ? 3:- Third doubt, product based companies like Microsoft, AMD, paytm , paypal, Google ivi DSA aa programming language tho prefer chesthayi, either JAVA or C++ Reply istharu ani aashisthunna sis🙌🏻🙏🏻
import java.util.Arrays; public class MergeThreeSortedArrays { public static void mergeThreeSortedArrays(int[] nums1, int m, int[] nums2, int n, int[] nums3, int o) { // Pointers for each array int i = m - 1; // Last index of valid elements in nums1 int j = n - 1; // Last index of nums2 int k = o - 1; // Last index of nums3 int writeIndex = m + n + o - 1; // Last index in nums1 // Merge nums1, nums2, nums3 in reverse order while (j >= 0 || k >= 0 || i >= 0) { int val1 = (i >= 0) ? nums1[i] : Integer.MIN_VALUE; int val2 = (j >= 0) ? nums2[j] : Integer.MIN_VALUE; int val3 = (k >= 0) ? nums3[k] : Integer.MIN_VALUE; if (val1 >= val2 && val1 >= val3) { nums1[writeIndex--] = val1; i--; } else if (val2 >= val1 && val2 >= val3) { nums1[writeIndex--] = val2; j--; } else { nums1[writeIndex--] = val3; k--; } } } public static void main(String[] args) { // Example 1 int[] nums1 = {0, 4, 8, 9, 0, 0, 0, 0}; int m = 4; int[] nums2 = {5, 6}; int n = 2; int[] nums3 = {2, 3}; int o = 2; mergeThreeSortedArrays(nums1, m, nums2, n, nums3, o); System.out.println(Arrays.toString(nums1)); // Example 2 nums1 = new int[]{0, 0, 0, 0, 0}; m = 2; nums2 = new int[]{1, 2}; n = 2; nums3 = new int[]{4}; o = 1; mergeThreeSortedArrays(nums1, m, nums2, n, nums3, o); System.out.println(Arrays.toString(nums1)); } }
@@TechStoriesOfSrinidhi akka above code lo oka array traverse cheyyadam ipothe manam inka first while loop ki vellama kada akka mari appudu while loop bayataki vastam pina code prakaram we are directly adding remaining elements into the array without comaparing the elements in the remaining two arrays appudu output will be wrong kada akka for example : take nums1 = {8,9,0,0,0}; nums2 = {3,5} nums3 = {4} final output should be {3,4,5,8,9} kada akka but above code prakaram getting it as {4,3,5,8,9} akka could you please clarify this ? once check this akka import java.util.Scanner; public class MergeThreeSortedArrays { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); int o = sc.nextInt(); int[] nums1 = new int[m+n+o]; int[] nums2 = new int[n]; int[] nums3 = new int[o]; for(int i=0;i= 0) { if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) { nums1[p--] = nums1[p1--]; } else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) { nums1[p--] = nums2[p2--]; } else { nums1[p--] = nums3[p3--]; } } while(p1 >= 0 && p2 >= 0) { nums1[p--] = (nums1[p1] > nums2[p2]) ? nums1[p1--]:nums2[p2--]; } while(p1 >= 0 && p3 >= 0) { nums1[p--] = (nums1[p1] > nums3[p3])? nums1[p1--]:nums3[p3--]; } while(p2 >= 0 && p3 >= 0) { nums1[p--] = (nums2[p2] > nums3[p3]) ? nums2[p2--] : nums3[p3--]; }
//Handle remaining elements in any single array while(p2 >= 0) { nums1[p--] = nums2[p2--]; } while(p3 >= 0) { nums1[p--] = nums3[p3--]; }
@TechStoriesOfSrinidhi hi sister for me the first code is working as expected but second one is not, pls review and tell me why topic: insert node in doubly linked list 1)--------------------------------------------------------------------- void insertNode(int k, Node* n) { Node* ptr = nodeExists(k); if (ptr == NULL) { cout prev = ptr; if (ptr->next != NULL) { // Handle insertion at the end ptr->next->prev = n; } ptr->next = n; cout
Today's Problem: leetcode.com/problems/merge-sorted-array/description/
Adjust playback speed according to your pace
Don't forget to try solving "merge 3 sorted arrays", happy coding!
nums1 = [0,4,8,9,0,0,0,0]
m = 4
nums2 = [5,6]
n = 2
nums3 = [2,3]
o = 2
p = (m+n+o) - 1
p1 = m - 1
p2 = n - 1
p3 = o - 1
while p1 >= 0 and p2 >= 0 and p3 >= 0:
if nums1[p1] > nums2[p2] and nums1[p1] > nums3[p3]:
nums1[p] = nums1[p1]
p1 -= 1
elif nums2[p2] > nums3[p3] and nums2[p2] > nums1[p1]:
nums1[p] = nums2[p2]
p2 -= 1
else:
nums1[p] = nums3[p3]
p3 -= 1
p -= 1
while p2 >= 0:
if nums1[p1] > nums2[p2]:
nums1[p] = nums2[p1]
p1 -= 1
else:
nums1[p] = nums2[p2]
p2 -= 1
p -= 1
while p3 >= 0:
if nums1[p1] > nums3[p3]:
nums1[p] = nums1[p1]
p1 -= 1
else:
nums1[p] = nums3[p3]
p3 -= 1
p -= 1
print(nums1)
Hi akka, me explanation chala baga artam avutondi..meru ilage continue cheyandi...Me comfort bcoz ikada okokaru okolaga cheptunaru..okariki java lo o/p chupiyalanta inkokariki inko language..you can't match all of that.. Logic okate ga denikaina..we all will try..!!! Lots of love akka..keep Rocking!!!
Thanks srinidhi 🎉🎉🎉 i wish these videos would have started early itself
write the code in java or else convert the same c++ code into java using chatgpt and show us please so that java devlopers can understand , your way of thinking is good .
First explanation ichi, tarwatha brute force lo chesi danni chinna ga efficient ga change cheste inka easy ga ardamavuthundi, okesari efficient ga raste ardam avvadhu
Yes
Thanks for continuing this series dear akka ❤
Excellent
Chala manchiga chepparu akkaa
thanks for doing this
super ga unnaye akka videos akka
dialy aiyena upload cheyanddi akka videos akka we will souprt you akka
nums1[m:] = nums2
nums1.sort()
return nums1
Ee DSA series yenni rojulaku complete avuthundhi akka vedio and vedio ki chala gap undhi.
Ardamyndhi 😊
Hi srinidhi nenu c# language lo code chesthanu DSA ki meru cheppina gfg use chedam ani start chesanu but practicing purpose ki naku c# language chupinchatledu only c++,java,python ave vunnai.. other platforms emanna vunnaya lekapothe gfg lo c# practicing emanna option vunda help chesthara...
Akka, DSA Coding solving lo "Logic ella bulid" cheyyelle cheppava
Akka videos upload cheyandi
If its possible, kindly try to solve blind 75 leetcode madam
Sub array equals to k optimal solution cheppandi
hii akka dsa python lo cheyyocha or java lone cheyyala for interview purpose akka
aptitude ki channel suggestion ivvandi akka
java,c++,python kakunda javascript lo kuda code cheyacha
Yes
can you share the link of leetcode problem (assignment problem) so that I can check all the test cases
I searched but ala merge 3 sorted arrays ane question ledu specific ga anduke sample inputs outputs icha so that u can test. Purpose of giving that task is adi chesar antee idi question clarity ga ardaminattu
Hi sister,
Nenu DSA with c++ nerchukuntunna, ippudu recursion topic daggara unnanu, na doubt enti ante
1:- recent ga konni articles chadivanu ila C++ ni US govt ban chayali ani order icchindhi ani as it not memory safe,
so C++ tho DSA nerchukovadam better option eh na or else shall I move to another language.
2 :- inko doubt sis, as im learning DSA with C++, should i stick with it or move to Java with C++ ?
3:- Third doubt, product based companies like Microsoft, AMD, paytm , paypal, Google ivi DSA aa programming language tho prefer chesthayi, either JAVA or C++
Reply istharu ani aashisthunna sis🙌🏻🙏🏻
import java.util.Arrays;
public class MergeThreeSortedArrays {
public static void mergeThreeSortedArrays(int[] nums1, int m, int[] nums2, int n, int[] nums3, int o) {
// Pointers for each array
int i = m - 1; // Last index of valid elements in nums1
int j = n - 1; // Last index of nums2
int k = o - 1; // Last index of nums3
int writeIndex = m + n + o - 1; // Last index in nums1
// Merge nums1, nums2, nums3 in reverse order
while (j >= 0 || k >= 0 || i >= 0) {
int val1 = (i >= 0) ? nums1[i] : Integer.MIN_VALUE;
int val2 = (j >= 0) ? nums2[j] : Integer.MIN_VALUE;
int val3 = (k >= 0) ? nums3[k] : Integer.MIN_VALUE;
if (val1 >= val2 && val1 >= val3) {
nums1[writeIndex--] = val1;
i--;
} else if (val2 >= val1 && val2 >= val3) {
nums1[writeIndex--] = val2;
j--;
} else {
nums1[writeIndex--] = val3;
k--;
}
}
}
public static void main(String[] args) {
// Example 1
int[] nums1 = {0, 4, 8, 9, 0, 0, 0, 0};
int m = 4;
int[] nums2 = {5, 6};
int n = 2;
int[] nums3 = {2, 3};
int o = 2;
mergeThreeSortedArrays(nums1, m, nums2, n, nums3, o);
System.out.println(Arrays.toString(nums1));
// Example 2
nums1 = new int[]{0, 0, 0, 0, 0};
m = 2;
nums2 = new int[]{1, 2};
n = 2;
nums3 = new int[]{4};
o = 1;
mergeThreeSortedArrays(nums1, m, nums2, n, nums3, o);
System.out.println(Arrays.toString(nums1));
}
}
Good deletion 🫠
i can edit the videos and i can create this content for you cuz ..Iam currently on job haunting and preparing dsa and LLD .recent graduate 2024
def merge_sort(n1, n2, m, n):
i, j = 0, 0
while j < m:
if i >= m:
n1[i:] = n2[j:]
return n1
if n1[i] >= n2[j]:
n2[j], n1[i] = n1[i], n2[j]
j += 1
elif n2[j] >= n1[i]:
i += 1
return n1
arr1 = [1,2,3,0,0,0]
arr2 = [5,5,6]
m, n = 3, 3
print(merge_sort(arr1, arr2, m, n))
I started dsa recently I want to study together anyone interested message me?
arr1=[3,4,0,0,0,0]
m=2
arr2=[8,9]
n=2
arr3=[5,6]
z=2
p1=m-1
p2=n-1
p3=z-1
p=m+n+z-1
while p1>=0 and p2>=0 and p3>=0:
if arr1[p1]>arr2[p2] and arr1[p1]>arr3[p3]:
arr1[p]=arr1[p]
p1-=1
elif arr2[p2]>arr1[p1] and arr2[p2]>arr3[p3]:
arr1[p]=arr2[p2]
p2-=1
else:
arr1[p]=arr3[p3]
p3-=1
p-=1
while p2>=0:
arr1[p]=arr2[p2]
p2-=1
p-=1
while p3>=0:
arr1[p]=arr3[p3]
p3-=1
p-=1
print(arr1)
Bro e program correct ga work avvadu okasari check chesko. First example okasari cheyy bro. Naku mistake vachindhi anduke chepthunna
@durgakarri-b8y 1st if lo
arr1[p]=arr1[p1]
Idi correct cheste sarpothundi, typo ankuntaa
@@TechStoriesOfSrinidhi 👍
@@TechStoriesOfSrinidhi akka above code lo oka array traverse cheyyadam ipothe manam inka first while loop ki vellama kada akka mari appudu while loop bayataki vastam pina code prakaram we are directly adding remaining elements into the array without comaparing the elements in the remaining two arrays appudu output will be wrong kada akka
for example :
take nums1 = {8,9,0,0,0};
nums2 = {3,5}
nums3 = {4}
final output should be {3,4,5,8,9} kada akka
but above code prakaram getting it as {4,3,5,8,9} akka
could you please clarify this ?
once check this akka
import java.util.Scanner;
public class MergeThreeSortedArrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int o = sc.nextInt();
int[] nums1 = new int[m+n+o];
int[] nums2 = new int[n];
int[] nums3 = new int[o];
for(int i=0;i= 0) {
if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) {
nums1[p--] = nums1[p1--];
} else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) {
nums1[p--] = nums2[p2--];
} else {
nums1[p--] = nums3[p3--];
}
}
while(p1 >= 0 && p2 >= 0) {
nums1[p--] = (nums1[p1] > nums2[p2]) ? nums1[p1--]:nums2[p2--];
}
while(p1 >= 0 && p3 >= 0) {
nums1[p--] = (nums1[p1] > nums3[p3])? nums1[p1--]:nums3[p3--];
}
while(p2 >= 0 && p3 >= 0) {
nums1[p--] = (nums2[p2] > nums3[p3]) ? nums2[p2--] : nums3[p3--];
}
//Handle remaining elements in any single array
while(p2 >= 0) {
nums1[p--] = nums2[p2--];
}
while(p3 >= 0) {
nums1[p--] = nums3[p3--];
}
for(int num:nums1) {
System.out.print(num+" ");
}
}
}
@TechStoriesOfSrinidhi
hi sister for me the first code is working as expected but second one is not, pls review and tell me why
topic: insert node in doubly linked list
1)---------------------------------------------------------------------
void insertNode(int k, Node* n) {
Node* ptr = nodeExists(k);
if (ptr == NULL) {
cout prev = ptr;
if (ptr->next != NULL) { // Handle insertion at the end
ptr->next->prev = n;
}
ptr->next = n;
cout
can someone pls help me