How to move Zeroes to end of an Array? | Implementation

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • ►Full DSA Course - • Data Structures and Al...
    ►Follow me on Instagram - bit.ly/intrvwk...
    ►Follow me on LinkedIn - bit.ly/fllwlkdn
    ►Enroll in the complete course: bit.ly/3W4qthg
    ►Source Code - github.com/din...
    ►Download DSA Animation Slides - techready.in/c...
    ►Click here to subscribe - www.youtube.co...
    Watch all my playlist here:
    ►Data Structures and Algorithms Course playlist: • Data Structures and Al...
    ►Mastering JUnit 5 - www.youtube.co...
    ►Mastering Mockito 3 - • Mockito 3 Tutorials
    ►Analysis of Algorithms - • Analysis of Algorithms
    ►Linked List Data Structures - • Linked List Data Struc...
    ►Array Data Structures - • Playlist
    ►Stack Data Structure - • Stack Data Structure
    ►Queue Data Structure - • Queue Data Structure
    ►Binary Tree Data Structure - • Binary Tree Data Struc...
    ►Graph Data Structure - • Graph Data Structure
    ►Binary Heap Data Structure - • Binary Heap Data Struc...
    ►Trie Data Structure - • Trie Data Structure
    ►Dynamic Programming Algorithms - • Dynamic Programming Al...
    ►Hashing Data Structures - • Hashing Data Structures
    ►Sorting and Searching - • Sorting and Searching
    ►String Algorithms - • String Algorithms
    Want to land a software engineering job in the IT industry? This course - 'Visualizing Data Structures and Algorithms' is here to help. The course walks you through multiple Java algorithms, data structures problems, and their solutions with step by step visualizations, so that you are actually learning instead of blindly memorizing solutions.
    The course covers in and outs of Data Structures and Algorithms in Java. Java is used as the programming language in the course. Students familiar with Javascript, Python, C#, C++, C, etc will also get to learn concepts without any difficulty. The implementation of various Algorithms and Data Structures have been demonstrated and implemented through animated slides. It covers many interview room questions on Algorithms and Data Structures. The questions and solutions are demonstrated by -
    1. Animated slide. (To make visualization of algorithms faster)
    2. Coding algorithm on IDE.
    The course covers topics such as -
    0. Algorithm Analysis
    1. Arrays
    2. Matrix
    3. Singly Linked List
    4. Doubly Linked List
    5. Circular Singly Linked List
    6. Stacks
    7. Queues
    8. Binary Tree
    9. Binary Search Tree
    10. Graphs
    11. Priority Queues and Heaps
    12. Recursion
    13. Searching
    14. Sorting
    15. Strings
    16. Trie Data Structure
    17. Dynamic Programming
    and many more ...
    #dsa #algorithms #coding

КОМЕНТАРІ • 28

  • @itsdineshvaryani
    @itsdineshvaryani  3 роки тому +1

    Please *Like* , *Comment* , *Share* , *Subscribe* and *Click Bell* 🔔🔔🔔 Icon for More Updates. To get *Data Structures and Algorithms* complete course for free please follow this link - ua-cam.com/play/PL6Zs6LgrJj3tDXv8a_elC6eT_4R5gfX4d.html

  • @ivelingachev6811
    @ivelingachev6811 3 роки тому +6

    I also tried moving all zeroes to the start of the array. Following your algorithm I played a little bit and changed the direction of for loop to read the elements in reverse order and the if(arr[j] != 0) { j--; }
    Here is the code:
    public void moveZeros(int[] arr,int n) {
    int j = n-1;
    for(int i = n-1; i >= 0; i--) {
    if(arr[i] != 0 && arr[j] == 0) {
    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    if(arr[j] != 0) {
    j--;
    }
    }
    }
    I am still beginner so I hope it works for everybody !!
    Thanks for the lesson!

  • @shubhamagarwal1434
    @shubhamagarwal1434 2 роки тому +4

    Best series for DS & Algo. I am also 10 yrs java exp guy. Was looking for DS & Algo free course over UA-cam with java implementation and found this. Hats Off To You Man....Excellent Work. GOD BLESS YOU :)

  • @ERDheerajmann
    @ERDheerajmann 2 роки тому +1

    You are most underrated channel,
    This question was asked to me for Amazon.

  • @soumyadipmajumder902
    @soumyadipmajumder902 Рік тому +1

    Enjoying your course

  • @thakurji8302
    @thakurji8302 3 роки тому +1

    It would be more easier if we check that whenever we have zero in our array if left shifts at that particular index and then assigning the last index value as 0

  • @AiyushSaini
    @AiyushSaini 3 роки тому +2

    Hi Sir,
    There's some issue with this algorithm, I tried this algorithm with 2 different values - 1st (int b[] = {0,1,2,0,4,0,5};) and 2nd ( int b[] = {0,1,0,2,1,0,3};). In both the cases the output was wrong,the last element of the array is not getting swapped with 0. where as your values are giving perfect output.

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      The code seems to be correct ... Can u check what value u passing for n ???

    • @AiyushSaini
      @AiyushSaini 3 роки тому

      @@itsdineshvaryani array length

    • @AiyushSaini
      @AiyushSaini 3 роки тому +1

      @@itsdineshvaryani My Mistake sir, found the error. Thanks for quick reply.

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому +1

      @@AiyushSaini please subscribe channel and share it with ur friends and colleagues as well ... Ask them to subscribe as well !!! Thanks

  • @AbdurahmonMirobidov
    @AbdurahmonMirobidov Рік тому +1

    Awesome!

  • @ChinnaKumarReddy
    @ChinnaKumarReddy Рік тому +2

    Hi Sir, Here Kumar from Andhra Pradesh I completed udemy course on DS but there i didn't See these type of solving and animations , I happy to see and I understand Better with Animations.
    The above problem is working well but some of the test cases it is not Working
    Ex test Case 1: 9,8,7,6,5,0,4,0,3,2,0,1 Expected Output :9,8,7,6,5,4,3,2,1,0,0,0 Actual Output:9,8,7,6,5,4,3,1,0,2,0,0
    Test Case 2: 0,1,0,2,1,0,3 Expected Output:1,2,1,3,0,0,0 Actual Output: 1,2,3,0,1,0,0
    Can You Please Check It Sir

  • @shikanderraja4956
    @shikanderraja4956 Рік тому

    I followed your DSA series and able to solve this problem in the following way. Please correct if am wrong.
    public static void main(String[] args) {
    int[] A = { 9,8,7,6,5,0,4,0,3,2,0,1 };
    int[] B = new int[A.length];
    int count = 0;
    for (int i=0; i

  • @Acousticanjali
    @Acousticanjali Рік тому

    sir can you please explain the part in which you called method moveZeroes to arraydemo

  • @DURGADEVIPRASANNAVETSA
    @DURGADEVIPRASANNAVETSA 8 місяців тому

    For 0,1,0,3,12...the output is wrong sir ,can you figure it out sir?

  • @godl_disaster611
    @godl_disaster611 Рік тому

    EASIEST SOLUTION :)
    int number = 0 ;
    for(int i = 0 ; i < arr.length ; i++){
    if(arr[i] != number){
    int temp = arr[i];
    arr[i] = arr[number];
    arr[number] = temp ;
    number++ ;
    }
    }

  • @sreddy8141
    @sreddy8141 3 роки тому +1

    Video is blurred totally, pls upload clearly visible one sir, thanks

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      You need to make sure u hv good internet connection and choose HD setting on youtube video !!!

    • @sreddy8141
      @sreddy8141 3 роки тому +1

      @@itsdineshvaryani yeah, sure , thanks sir, other vidoes are fine in the same series, but oly for this i experienced

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      Ohh ... Ok !!!

  • @subhankardash2278
    @subhankardash2278 6 місяців тому

    sir i am writing like this why it is not working
    ............................................................................
    package Array;
    public class MoveZeroIntoEndOfArray {

    static void printArray(int[]arr) {
    for(int i=0;i