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
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
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
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
Thanks Anuj for the suggestion..>!
@@vivekanandkhyade hi if possible can u please share the code snippet for above logic
Thankyou sir 🙏
Plz keep on uploading data structure and algo video 😊 U r explanation is fabulous sir👌👌
Can this be implemented same as segregating +ve and -ve values
Why we not using sorting?
Great videos sir, please make videos on competitive programming, and every question from geeks for geeks
Hello boss where is the program u just written only logic
What if I want to find the minimum number of swaps required?
sir aap itna achchha padhate ho,aap gate k liye videos banaiye.... students par bahot bahot ehsaan Hoga aapka
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
this is not the best solution as it involves two times pass
bro make the videos on graph and tree questions..
Make a vidio on pattern of "concentric square"
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++;
}
}
Sir please upload video on Merge Sort for a linked list. Please sir.
Please upload on sorting algoritham
Please upload videos on heap
yes sure Vasanthan..!
I think this will take o(n*2) time? Can someone please verify this??
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
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).