3. Merge Sorted Arrays || Arrays Problem Solving

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 42

  • @TechStoriesOfSrinidhi
    @TechStoriesOfSrinidhi  Місяць тому +7

    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!

    • @vinayreddy8675
      @vinayreddy8675 29 днів тому

      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)

  • @chandanavashistha8398
    @chandanavashistha8398 29 днів тому +1

    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!!!

  • @aishwaryaph524
    @aishwaryaph524 25 днів тому

    Thanks srinidhi 🎉🎉🎉 i wish these videos would have started early itself

  • @Saikumar_Miryala
    @Saikumar_Miryala Місяць тому +1

    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 .

  • @abhilash0122
    @abhilash0122 Місяць тому +6

    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

  • @kalyanamephraim4393
    @kalyanamephraim4393 Місяць тому

    Thanks for continuing this series dear akka ❤

  • @chandrababuRavi
    @chandrababuRavi Місяць тому +1

    Excellent

  • @harsa208
    @harsa208 27 днів тому

    Chala manchiga chepparu akkaa

  • @nazeertheofficial
    @nazeertheofficial Місяць тому +1

    thanks for doing this

  • @veerareddy5694
    @veerareddy5694 Місяць тому

    super ga unnaye akka videos akka
    dialy aiyena upload cheyanddi akka videos akka we will souprt you akka

  • @goo-pro5648
    @goo-pro5648 Місяць тому +1

    nums1[m:] = nums2
    nums1.sort()
    return nums1

  • @nagendramalli2742
    @nagendramalli2742 20 днів тому +1

    Ee DSA series yenni rojulaku complete avuthundhi akka vedio and vedio ki chala gap undhi.

  • @Mr.venky6539
    @Mr.venky6539 Місяць тому

    Ardamyndhi 😊

  • @madhavisfoodgallery8575
    @madhavisfoodgallery8575 20 днів тому

    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...

  • @yaswanthyadav893
    @yaswanthyadav893 17 днів тому

    Akka, DSA Coding solving lo "Logic ella bulid" cheyyelle cheppava

  • @sureshsurya5740
    @sureshsurya5740 4 дні тому

    Akka videos upload cheyandi

  • @sureshkumar-k8u5b
    @sureshkumar-k8u5b 19 днів тому

    If its possible, kindly try to solve blind 75 leetcode madam

  • @VinayKumariCloud
    @VinayKumariCloud 27 днів тому

    Sub array equals to k optimal solution cheppandi

  • @kavithajakkala8530
    @kavithajakkala8530 18 днів тому

    hii akka dsa python lo cheyyocha or java lone cheyyala for interview purpose akka
    aptitude ki channel suggestion ivvandi akka

  • @abcd-g2p4w
    @abcd-g2p4w Місяць тому +1

    java,c++,python kakunda javascript lo kuda code cheyacha

  • @Sathwiksouthphotos
    @Sathwiksouthphotos Місяць тому

    can you share the link of leetcode problem (assignment problem) so that I can check all the test cases

    • @TechStoriesOfSrinidhi
      @TechStoriesOfSrinidhi  Місяць тому

      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

  • @saikumargollapalli5080
    @saikumargollapalli5080 28 днів тому

    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🙌🏻🙏🏻

  • @g.upenderreddy
    @g.upenderreddy Місяць тому

    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));
    }
    }

  • @LMusicMagnet257
    @LMusicMagnet257 Місяць тому

    Good deletion 🫠

  • @baladurukunala
    @baladurukunala 7 днів тому

    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

  • @vamsipreetham6224
    @vamsipreetham6224 Місяць тому

    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))

  • @elisa3234
    @elisa3234 5 днів тому

    I started dsa recently I want to study together anyone interested message me?

  • @Durga_Naveen
    @Durga_Naveen Місяць тому

    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)

    • @durgakarri-b8y
      @durgakarri-b8y Місяць тому +1

      Bro e program correct ga work avvadu okasari check chesko. First example okasari cheyy bro. Naku mistake vachindhi anduke chepthunna

    • @TechStoriesOfSrinidhi
      @TechStoriesOfSrinidhi  Місяць тому

      @durgakarri-b8y 1st if lo
      arr1[p]=arr1[p1]
      Idi correct cheste sarpothundi, typo ankuntaa

    • @Durga_Naveen
      @Durga_Naveen Місяць тому

      @@TechStoriesOfSrinidhi 👍

    • @HemalathaAnumolu
      @HemalathaAnumolu 26 днів тому

      ​@@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+" ");
      }
      }
      }

  • @Itsme-kx1us
    @Itsme-kx1us 8 днів тому

    @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