Segregate 0's and 1's in an array(collect 0 and 1 together respectively)

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

КОМЕНТАРІ • 23

  • @anujsaluja5866
    @anujsaluja5866 7 років тому

    You can swap 1s with 0s as you are traversing. Follow the same algorithm that you have, but whenever you encounter 0 swap array[I] with array[counter] and then increment both i and counter. If you encounter 1, then only increment i

    • @vivekanandkhyade
      @vivekanandkhyade  7 років тому

      Thanks Anuj for the suggestion..>!

    • @santhuravikanti4988
      @santhuravikanti4988 6 років тому

      @@vivekanandkhyade hi if possible can u please share the code snippet for above logic

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

    Thankyou sir 🙏

  • @tridevthakur5397
    @tridevthakur5397 4 роки тому

    Plz keep on uploading data structure and algo video 😊 U r explanation is fabulous sir👌👌

  • @AMITKUMAR-ys4oe
    @AMITKUMAR-ys4oe Рік тому

    Can this be implemented same as segregating +ve and -ve values

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

    Why we not using sorting?

  • @anilchaudhry804
    @anilchaudhry804 6 років тому +1

    Great videos sir, please make videos on competitive programming, and every question from geeks for geeks

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

    Hello boss where is the program u just written only logic

  • @xof8256
    @xof8256 5 років тому

    What if I want to find the minimum number of swaps required?

  • @NitinRaathi
    @NitinRaathi 7 років тому

    sir aap itna achchha padhate ho,aap gate k liye videos banaiye.... students par bahot bahot ehsaan Hoga aapka

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

    Plz do videos on c Language chapter wise total 1 chapter in 1 r 2 videos if possible it is very useful to all type of students like part 1 part 2 that's it no more confusion for beginners
    And also evry chapter questions chapter wise make other video

  • @satyajeetjha1681
    @satyajeetjha1681 7 років тому +2

    this is not the best solution as it involves two times pass

  • @ashishsinha8893
    @ashishsinha8893 7 років тому

    bro make the videos on graph and tree questions..

  • @45_ritiksharma32
    @45_ritiksharma32 4 роки тому

    Make a vidio on pattern of "concentric square"

  • @ShivanshPandey-x3s
    @ShivanshPandey-x3s 4 місяці тому

    My approach
    public void shiftElements(int[] arr) {
    int i = 0;
    int j = 0;
    while (j < arr.length) {
    if (arr[j] == 0) {
    swap(arr, i, j);
    i++;
    }
    j++;
    }
    }

  • @AddieInGermany
    @AddieInGermany 7 років тому

    Sir please upload video on Merge Sort for a linked list. Please sir.

  • @MrVazanth
    @MrVazanth 7 років тому

    Please upload on sorting algoritham

  • @MrVazanth
    @MrVazanth 7 років тому

    Please upload videos on heap

  • @Jeetu0301
    @Jeetu0301 7 років тому

    I think this will take o(n*2) time? Can someone please verify this??

    • @nldanand
      @nldanand 6 років тому

      Yes its not O(N) and other blog I got simple and easy solution with O(N) complexity...
      javadiscover.blogspot.in/2018/04/segregate-0s-and-1s-in-array-by-looping.html

    • @tanishbansal
      @tanishbansal 5 років тому +1

      no ... it ll take O(n) only .... he is using loop two time but separately... when you calculate loop inside the loop then it cost O(n^2).