Remove Duplicates from sorted Array

  Рет қаралды 170,254

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Remove Duplicates from sorted Array. Remove multiple occurrences of an element from array. Keep only one occurrence of each element. No multiple copies. Write a program to do this.

Пікірлер: 201
@muthushankar570
@muthushankar570 3 жыл бұрын
I was searched this problem in many websites not get this problem..but i see this problem in ur channel to understand very easily and learn clearly... Thank u brother 🙏
@babarsk8784
@babarsk8784 Күн бұрын
jai bolo chatgbt 😅
@madhukumar1238
@madhukumar1238 6 жыл бұрын
Thank you!!! very well explained!! wish we had a professor like you!!!
@sinebiinnazo7882
@sinebiinnazo7882 2 жыл бұрын
I love how made the solution looked very simple. I wish you can treat more basic Java Algorithms so that i can understand several approaches to solving algorithms.
@SmartProgramming
@SmartProgramming 5 жыл бұрын
awesome explanation sir, hats off, keep uploading, thank you 👍👍👍👍🙂🙂🙂🙂
@Gaurav-bv6xr
@Gaurav-bv6xr 6 жыл бұрын
sir take all interview probelms from geeksforgeeks and dicuss their algorithm and complexity
@sahad_abd
@sahad_abd 2 жыл бұрын
Plz help me bro... I have to prepare for placements plz tell where should I refer
@Gaurav-bv6xr
@Gaurav-bv6xr 2 жыл бұрын
@@sahad_abd bro,i am not preparing for interview now😅
@sahad_abd
@sahad_abd 2 жыл бұрын
@@Gaurav-bv6xr plz suggest me brooo..just you know
@Gaurav-bv6xr
@Gaurav-bv6xr 2 жыл бұрын
@@sahad_abd prepare interview ques from geeksforgeeks
@tanujvishwakarma1967
@tanujvishwakarma1967 Жыл бұрын
wow i watched so many video but no buddy explained to butter and not cover to all every concept but u clear all the concept all and i"m surprise i means wow ; I"m say to thank u to u " sat sat naman app ko Hindi me bole to "
@azad1300
@azad1300 4 жыл бұрын
Your way of teaching is awesome. we need more problems solution on array, so update with some more problems.
@Ihabkhattab
@Ihabkhattab 4 жыл бұрын
Thank you bro for your visualization of the problem and the solution is awesome. finally, I got it 🙏🏿
@mr.unique4974
@mr.unique4974 Жыл бұрын
Thank you Sir for helping . I've been searching a lot for the logical explanation.
@godwincharan
@godwincharan 6 жыл бұрын
The last line causes ambiguous behaviour if there is no element in the array. i.e. the size of the array is zero. Also using constant space method the final array will be 1,2,3,4,3,3,4,4 as we are using the same array and we don't clear the memory for those.
@therealsayanroy
@therealsayanroy 6 жыл бұрын
it's for sorted array
@samiahmadkhan2865
@samiahmadkhan2865 6 жыл бұрын
You didn't get his point. He's right, you will need to remove the remaining elements from the array after Jth position
@mepsk
@mepsk 5 жыл бұрын
Exactly.. I have tried.. the last elements remain in array..
@tonmoyrakshit1717
@tonmoyrakshit1717 5 жыл бұрын
That's right! We need to run a loop from jth+ 1 index till the last (n-1) and clear the remaining elements of the array.
@sairamgamidi7786
@sairamgamidi7786 4 жыл бұрын
@@tonmoyrakshit1717 Can u give the code to clea remaining elements
@FlavortownFreddy
@FlavortownFreddy Жыл бұрын
Very well explained, even small details are touched that others missed
@mahideeptumati
@mahideeptumati 6 жыл бұрын
One doubt here. While using same array to avoid duplicates j ended up with 3 here , then what happened to elements present in index 4,5,6,7 of array arr as we didn’t remove them in that array
@gokulnathnallaiya7617
@gokulnathnallaiya7617 4 жыл бұрын
print array from 0 to j
@champion5946
@champion5946 2 жыл бұрын
@@gokulnathnallaiya7617 thanks buddy
@nandiniprakash5191
@nandiniprakash5191 6 жыл бұрын
Very much helpful and can understand by anyone as explanation is very simple . Expecting to see the videos for java collections problems.
@abhishek_singh512
@abhishek_singh512 Жыл бұрын
Nice lecture sir keeping uploading this type of conceptual video 🥰🥰🥰🥰🙏🙏🙏🙏🙏🙏 Maja aa gaya 🙂
@ManishaKumari-yv3nf
@ManishaKumari-yv3nf 3 жыл бұрын
Your explanation technique is great 👍
@tapanjeetroy8266
@tapanjeetroy8266 5 жыл бұрын
Thanks for uploading it.. You are doing a great great job.. Please please upload more of such programming questions.. We really need it
@naboulsikhalid7763
@naboulsikhalid7763 Жыл бұрын
what a quality explanation!. big thanks for the effort
@jayashreeanitha4438
@jayashreeanitha4438 3 жыл бұрын
Nice explanation sir .. well done .. Thank u so much for crystal clear explanation👍
@xiangwingrace8672
@xiangwingrace8672 6 жыл бұрын
Very Good! Please discuss more complicated problems from GeeksforGeeks.
@indianinvestor1301
@indianinvestor1301 2 жыл бұрын
sir really good and help me a lot
@samiahmadkhan2865
@samiahmadkhan2865 6 жыл бұрын
You may want to slice of all the elements after j index, since you are doing in place replace.
@ganeshshetty8441
@ganeshshetty8441 2 жыл бұрын
correct, Even i have commented the same
@nitinfudani1552
@nitinfudani1552 6 жыл бұрын
Liked the way you explained! Really Helpful.
@PradeepSingh-ov3bt
@PradeepSingh-ov3bt 6 жыл бұрын
make these kinds of tricky questions which provide best solution for a particular problem
@Vithal_Nivargi
@Vithal_Nivargi Жыл бұрын
Thank you well explained
@bassantdiaaahmed5736
@bassantdiaaahmed5736 5 жыл бұрын
thank you so mush you are brilliant and you have such a beautiful method of teaching
@caiomartins7807
@caiomartins7807 5 жыл бұрын
Very good lesson !!
@user-youyoki9054
@user-youyoki9054 5 жыл бұрын
I feel sorry to say, but I wasn't able to get the result as you explained on the video(even though I have written the code as yours).
@crodr001
@crodr001 4 жыл бұрын
There is an error in his explanation at least on the O(1). It should be a difference between the array his looping through AND a new array. He treating All as the same array.
@gavravdhongadi9824
@gavravdhongadi9824 3 жыл бұрын
You need to start the loop from I=0;I
@amarjeetkurmi1302
@amarjeetkurmi1302 2 жыл бұрын
Very simple explanation sir
@avibm948
@avibm948 4 жыл бұрын
Thanks for the video. Something is missing at the end for the "in memory" case , test [1,2,3,3] you need to add at the end while j
@NaturalPro100
@NaturalPro100 5 жыл бұрын
Great explanation sir ,but one small problem ,if the last element in the original array is duplicate to second last element in array ,then we have to check if arr[j] != original[n-1]
@algorithmsguide5076
@algorithmsguide5076 4 жыл бұрын
Agreed !!
@sdani9160
@sdani9160 4 жыл бұрын
No you are wrong if last 2 elements are duplicate it will not consider the 2nd last element and it will get out of the loop and finally insert the last element in new array
@vivekdongare2289
@vivekdongare2289 3 жыл бұрын
@@sdani9160 yes correct it will not take any of the duplicates from ending array
@shubhamathawale7296
@shubhamathawale7296 2 жыл бұрын
Thank you sir 🙏 everything is clear now
@MAHESHAITBECS
@MAHESHAITBECS 2 ай бұрын
good explanation sir
@GG-hk5iz
@GG-hk5iz 5 жыл бұрын
Very Well Explained .Thanks a lot
@04.nehalsingh12
@04.nehalsingh12 2 жыл бұрын
awesome tutorial sir
@aayushsarna6017
@aayushsarna6017 5 жыл бұрын
Hi Vivek, What is the total time complexity for both the solutions. I believe that initially sorting the array will also take some time. So in this case can you please explain?
@Lucy-dh2wj
@Lucy-dh2wj 4 жыл бұрын
Very clear and understandable! thanks!
@saadmanahmed860
@saadmanahmed860 6 жыл бұрын
sir...in constant space method, u churn out output to be [ ]{ 1, 2 ,3 ,4}... but according to your expounded algorithm, output comes out to be [ ]{1,2,3,4, 3,3,4,4 } as deletion of redundant 3,3,4,4 never undergoes....plz explain???????????
@algorithmsguide5076
@algorithmsguide5076 4 жыл бұрын
same doubt
@shalinsitwala
@shalinsitwala 4 жыл бұрын
Since you know j=3, which means first 4 are distinct elements. So you can use your unique values in the array by for(int i = 0; i
@Abhaykumar-lw7nr
@Abhaykumar-lw7nr Ай бұрын
thanks brother amazing...
@gawarivivek
@gawarivivek 4 жыл бұрын
Thanks a lot, Sir!! Simplified explanation..:)
@deepak-lv4vn
@deepak-lv4vn 4 жыл бұрын
you are completely ossum sir!!
@laragarg
@laragarg 6 жыл бұрын
Very helpful. Thank you very much.
@ramindersonu
@ramindersonu 3 жыл бұрын
Very good explanation
@sanjayd9675
@sanjayd9675 4 жыл бұрын
#include void main(){ int n=8; int a[8]={1,2,2,3,3,3,4,4}; int j=0; for(int i=0 ; i < n-1 ; i++){ if(a[i]!=a[i+1]){ a[j]=a[i]; j++; } } a[j]=a[n-1]; for(int i=0 ; i < j+1 ; i++){ printf("%d" , a[i]); } } i think this works fine while printing we have to go till j+1 and not n when we do so we get the correct output but is there anyother method .
@vidhyapriyadharsinicoimbat4352
@vidhyapriyadharsinicoimbat4352 5 жыл бұрын
Awesome Explanation thank you sir
@wmpah
@wmpah 6 жыл бұрын
very clear and good writing on whiteboard
@mohammad-karbalaee
@mohammad-karbalaee 3 жыл бұрын
you are the loveliest indian ever.
@GLTALES
@GLTALES Жыл бұрын
We kept i
@babarsk8784
@babarsk8784 Күн бұрын
i
@akhint4379
@akhint4379 2 жыл бұрын
Thank you so much sir❤
@JadeMelody08
@JadeMelody08 6 жыл бұрын
Great explanation. Thanks!
@menkamenka661
@menkamenka661 6 жыл бұрын
its really very helpful..Thanks
@sunainagandra2924
@sunainagandra2924 6 жыл бұрын
thank you sir..please post more..we will be very thakfull sir
@malia8693
@malia8693 3 жыл бұрын
great explanation!
@hanschaudry808
@hanschaudry808 2 жыл бұрын
shout out to you bro, I hope someone posted you on national boyfriend day
@hariprasad1744
@hariprasad1744 Жыл бұрын
In the first approach zeros will be added at the end of the temp array as we are creating with the same size of the actual array. and int he second approach you didnt explain how to remove the last elements. Can you please add the code for the above in your git
@suryanshtaragi794
@suryanshtaragi794 2 жыл бұрын
// use j++ to store last element //c programe to remove the duplicates elements #include void remove_duplicate(int arr[],int n) //n=number of elements in an array { int j=0; //traversing element in an array for(int i=0; i
@maheshAkkili
@maheshAkkili Жыл бұрын
Thank you
@MohdSameer-rx9gj
@MohdSameer-rx9gj 3 жыл бұрын
Thank you very much sir...
@prasadmotupalli7638
@prasadmotupalli7638 5 жыл бұрын
in first case the last element is 4 o/p becomes----1 2 3 4 4??
@mamuntheman6543
@mamuntheman6543 2 жыл бұрын
if the arr is 1 2 3 1 2 3 then its not able to find the duplicate that you discussed in the every last moment.
@Vishal-yp3ol
@Vishal-yp3ol 3 жыл бұрын
nice video thanks
@dandanamado8785
@dandanamado8785 5 жыл бұрын
Thank you, I have a question sir what is the n-1 stands for inside the for loop? Thank you
@MrMarkgyuro
@MrMarkgyuro 5 жыл бұрын
In this case we can not go to the last index. Because we can not compare it to the next index after it, that is a not existing index. We have to break out from the loop before we get to the last index. But we can handle the problem with transferring the last index's element to the new array. the basic method: the length of the array is represented by n. in this case n = 9, it means we have 9 elements. this helps us beacuse as you see indexes in the array are starting from 0 to n - 1. In our case, 0, 1, 2, 3, 4, 5, 6, 7, 8, note that 8 = 9 - 1 (n - 1). and this means that if we are the 8th iteration, we will go inside the if conditions body, but after the 8th (again, n - 1) we break from the loop.
@jitendarsahani11
@jitendarsahani11 4 жыл бұрын
Second last elements
@Aaqibkhan-oy9fr
@Aaqibkhan-oy9fr Жыл бұрын
Thank you sir
@moodswingsoflife
@moodswingsoflife 2 жыл бұрын
Thanks sir .. really helpful
@vivekanandkhyade
@vivekanandkhyade 2 жыл бұрын
Thanks a lot
@zaheershaikh7982
@zaheershaikh7982 6 жыл бұрын
Good explanation buddy, a just one quick question to you. What if the last value is 4 instead of 5 then?
@dev_manish
@dev_manish 6 жыл бұрын
there is something wrong with this algo.... use arr[j++]=arr[i] and arr[j++]=arr[n-1]
@doviche
@doviche 5 жыл бұрын
​@@dev_manish​, the algo is wrong!
@joelonix5326
@joelonix5326 6 жыл бұрын
Good work.really helpful
@krishnareddyyerram4615
@krishnareddyyerram4615 Жыл бұрын
i++ j++ will not execute if duplicate found. Sort is required to place duplicate side by side.
@ganeshshetty8441
@ganeshshetty8441 2 жыл бұрын
Hi Vivek, Here one more step is needed to remove other elements from array from Jth position,
@satish040
@satish040 4 жыл бұрын
Hi Vivek, Can you do the same using hash tables. I am interested in known how to effectively create the hash function so that we dont have a large hashvalue. also how to avoid clash. Ex 0%20 is 0 and 20%20 is 0so using modulo is not that effective way of creating hash.
@ranjithparuchuri7326
@ranjithparuchuri7326 6 жыл бұрын
nicely explained.thanks
@Kidsgyan762
@Kidsgyan762 5 жыл бұрын
Sir nice explanation
@rajeshdevan6051
@rajeshdevan6051 5 жыл бұрын
Very nice Sir thank you
@SubhashisDuttahere
@SubhashisDuttahere 3 жыл бұрын
thanks a lot
@techfusionwithamit
@techfusionwithamit 5 жыл бұрын
thanks'
@Kumarvivek-uv5hf
@Kumarvivek-uv5hf 3 жыл бұрын
the Solution does not work for constant space arr= [1,1,2] as J value remains 1 and hence when we want to print the array form 0 to j it will fail.
@shubhamvds9697
@shubhamvds9697 2 жыл бұрын
Very nice
@TheMihirpatel23
@TheMihirpatel23 4 жыл бұрын
Thank you so much sir
@kanimozhiparivallal995
@kanimozhiparivallal995 5 жыл бұрын
Super class....
@ryanafzal4129
@ryanafzal4129 11 ай бұрын
Can anybody explain what is the time complexity of this algorithm?
@praveenpuri2208
@praveenpuri2208 3 жыл бұрын
what about 1,2,2,3,3,1,4,4.... can we apply this algo in situation?
@jabraham1059
@jabraham1059 4 жыл бұрын
if we keep modifying the same array will the size of the array change?
@anilnkhsatriya9047
@anilnkhsatriya9047 4 жыл бұрын
Hi Vivek, pls explain, how to remove the eliments of linked list which is having sum is equals to zero
@helloyou4233
@helloyou4233 6 жыл бұрын
good quality education.
@aokreddy920
@aokreddy920 6 жыл бұрын
Nice explain sir
@gurunatharudhbhandarkavath7781
@gurunatharudhbhandarkavath7781 5 жыл бұрын
sir If the duplicates are not in consecutive then what we have to do?
@diptiranjanrout7119
@diptiranjanrout7119 Жыл бұрын
thanks sir
@makkerere4734
@makkerere4734 2 жыл бұрын
well done
@ekramdayan3800
@ekramdayan3800 5 жыл бұрын
great video keep it up buddy
@nidhisingh7802
@nidhisingh7802 4 жыл бұрын
Sir also tell complexity in each case .
@9441571873
@9441571873 3 жыл бұрын
//Remove duplicates from Array let arr = [1,2,3,2,4,3,5]; let res = getResult(arr); function getResult(arr){ let obj = {}; let res = []; for(let i=0;i
@yogeshsomasundaram4187
@yogeshsomasundaram4187 6 жыл бұрын
Thank you. But one doubt In using extra space, what if the last element is 4 ( instead of 5 in the original array). Then the temp array would end up having 4 twice - pls correct me if I am wrong. Thank you for your help.
@venkataramana7272
@venkataramana7272 6 жыл бұрын
replace i
@thalabloods2514
@thalabloods2514 Жыл бұрын
sir I tried it was awesome but getting array elements from user input is not working please upload video from getting user input and then remove duplicate
@susannaventafridda430
@susannaventafridda430 5 жыл бұрын
correct in place solution: def remove_duplicates(nums): j = 0 for i in range(len(nums) - 1): if nums[i] != nums[i + 1]: nums[j + 1] = nums[i + 1] j += 1 return j + 1
@janispaloma6060
@janispaloma6060 5 жыл бұрын
What if the duplicate of 2 is place on the last place on array list
@durjaarai7737
@durjaarai7737 4 жыл бұрын
Janis Paloma - hi, the question n solution is on sorted array.
@dipankarpal686
@dipankarpal686 4 жыл бұрын
Your explanation is nice. But you are not checking for last element. if Last element is unique , your program will not work..
@shahrukhshaikh9558
@shahrukhshaikh9558 5 жыл бұрын
I think we have to add arr[j++] =arr[n-1] if last two elements of array are same in constant space method
@RTX_valorant
@RTX_valorant 3 жыл бұрын
Why can't we use just list(set(arr))???
@santhuravikanti4988
@santhuravikanti4988 5 жыл бұрын
but if we use same array after filling the elements into array ,still will get duplicates after the loop in above example after filling the elements the index j is point to 3 and elements are filtered ,but if we display the array will get all elements after index 3 also,is this expected behavior
@kavithagorantla6000
@kavithagorantla6000 2 жыл бұрын
Sir output kuda print cheyyochu kadha sir
@yasmeenkarachiwala9612
@yasmeenkarachiwala9612 4 жыл бұрын
Amazing!
@lailasanthi7598
@lailasanthi7598 5 жыл бұрын
If last element and before element are equal what is the code sir
Find maximum element in an array (Largest element)
5:42
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 148 М.
Segregate 0's, 1's and  2's together in an array[O(n)](Dutch National Flag Problem)
17:27
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 61 М.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Modus males sekolah
00:14
fitrop
Рет қаралды 21 МЛН
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 24 МЛН
Remove Duplicates from Sorted Array - Leetcode 26 - Python
10:38
Remove Duplicate Elements from Sorted and Unsorted Array in Java (Hindi)
38:52
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,2 МЛН
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 851 М.
Leader in an Array (Code / Algorithm)
15:24
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 21 М.
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 223 М.
Merge two sorted Arrays into a third Sorted array
9:31
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 116 М.
Remove Duplicate Elements from Unsorted Array - Java Code
13:50
Programming Tutorials
Рет қаралды 104 М.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН