Remove Duplicates from sorted Array

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.

Пікірлер: 198

  • @muthushankar570
    @muthushankar5703 жыл бұрын

    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 🙏

  • @madhukumar1238
    @madhukumar12386 жыл бұрын

    Thank you!!! very well explained!! wish we had a professor like you!!!

  • @sinebiinnazo7882
    @sinebiinnazo78822 жыл бұрын

    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.

  • @nandiniprakash5191
    @nandiniprakash51916 жыл бұрын

    Very much helpful and can understand by anyone as explanation is very simple . Expecting to see the videos for java collections problems.

  • @Ihabkhattab
    @Ihabkhattab4 жыл бұрын

    Thank you bro for your visualization of the problem and the solution is awesome. finally, I got it 🙏🏿

  • @azad1300
    @azad13004 жыл бұрын

    Your way of teaching is awesome. we need more problems solution on array, so update with some more problems.

  • @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 "

  • @tapanjeetroy8266
    @tapanjeetroy82665 жыл бұрын

    Thanks for uploading it.. You are doing a great great job.. Please please upload more of such programming questions.. We really need it

  • @jayashreeanitha4438
    @jayashreeanitha44383 жыл бұрын

    Nice explanation sir .. well done .. Thank u so much for crystal clear explanation👍

  • @FlavortownFreddy
    @FlavortownFreddy Жыл бұрын

    Very well explained, even small details are touched that others missed

  • @aayushsarna6017
    @aayushsarna60175 жыл бұрын

    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?

  • @SmartProgramming
    @SmartProgramming5 жыл бұрын

    awesome explanation sir, hats off, keep uploading, thank you 👍👍👍👍🙂🙂🙂🙂

  • @ManishaKumari-yv3nf
    @ManishaKumari-yv3nf3 жыл бұрын

    Your explanation technique is great 👍

  • @nitinfudani1552
    @nitinfudani15526 жыл бұрын

    Liked the way you explained! Really Helpful.

  • @PradeepSingh-ov3bt
    @PradeepSingh-ov3bt6 жыл бұрын

    make these kinds of tricky questions which provide best solution for a particular problem

  • @abhishek_singh512
    @abhishek_singh512 Жыл бұрын

    Nice lecture sir keeping uploading this type of conceptual video 🥰🥰🥰🥰🙏🙏🙏🙏🙏🙏 Maja aa gaya 🙂

  • @mr.unique4974
    @mr.unique4974 Жыл бұрын

    Thank you Sir for helping . I've been searching a lot for the logical explanation.

  • @jabraham1059
    @jabraham10594 жыл бұрын

    if we keep modifying the same array will the size of the array change?

  • @Devilsworld-d9l
    @Devilsworld-d9l Жыл бұрын

    We kept i

  • @satish040
    @satish0404 жыл бұрын

    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.

  • @bassantdiaaahmed5736
    @bassantdiaaahmed57364 жыл бұрын

    thank you so mush you are brilliant and you have such a beautiful method of teaching

  • @gurunatharudhbhandarkavath7781
    @gurunatharudhbhandarkavath77814 жыл бұрын

    sir If the duplicates are not in consecutive then what we have to do?

  • @avibm948
    @avibm9484 жыл бұрын

    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

  • @anilnkhsatriya9047
    @anilnkhsatriya90474 жыл бұрын

    Hi Vivek, pls explain, how to remove the eliments of linked list which is having sum is equals to zero

  • @mahideeptumati
    @mahideeptumati5 жыл бұрын

    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

  • @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

  • @vidhyapriyadharsinicoimbat4352
    @vidhyapriyadharsinicoimbat43525 жыл бұрын

    Awesome Explanation thank you sir

  • @Gaurav-bv6xr
    @Gaurav-bv6xr6 жыл бұрын

    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

  • @GG-hk5iz
    @GG-hk5iz5 жыл бұрын

    Very Well Explained .Thanks a lot

  • @JadeMelody08
    @JadeMelody086 жыл бұрын

    Great explanation. Thanks!

  • @Lucy-dh2wj
    @Lucy-dh2wj4 жыл бұрын

    Very clear and understandable! thanks!

  • @praveenpuri2208
    @praveenpuri22083 жыл бұрын

    what about 1,2,2,3,3,1,4,4.... can we apply this algo in situation?

  • @gawarivivek
    @gawarivivek4 жыл бұрын

    Thanks a lot, Sir!! Simplified explanation..:)

  • @laragarg
    @laragarg6 жыл бұрын

    Very helpful. Thank you very much.

  • @menkamenka661
    @menkamenka6616 жыл бұрын

    its really very helpful..Thanks

  • @ryanafzal4129
    @ryanafzal41299 ай бұрын

    Can anybody explain what is the time complexity of this algorithm?

  • @naboulsikhalid7763
    @naboulsikhalid7763 Жыл бұрын

    what a quality explanation!. big thanks for the effort

  • @lailasanthi7598
    @lailasanthi75985 жыл бұрын

    If last element and before element are equal what is the code sir

  • @xiangwingrace8672
    @xiangwingrace86726 жыл бұрын

    Very Good! Please discuss more complicated problems from GeeksforGeeks.

  • @Kumarvivek-uv5hf
    @Kumarvivek-uv5hf3 жыл бұрын

    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.

  • @jmba0522
    @jmba05224 жыл бұрын

    Can i see the whole program of this please?

  • @joelonix5326
    @joelonix53266 жыл бұрын

    Good work.really helpful

  • @kavithagorantla6000
    @kavithagorantla60002 жыл бұрын

    Sir output kuda print cheyyochu kadha sir

  • @amarjeetkurmi1302
    @amarjeetkurmi1302 Жыл бұрын

    Very simple explanation sir

  • @prasadmotupalli7638
    @prasadmotupalli76385 жыл бұрын

    in first case the last element is 4 o/p becomes----1 2 3 4 4??

  • @karthikr2186
    @karthikr21864 жыл бұрын

    Pre and Post increment only using bitwise operator In c can u Post

  • @godwincharan
    @godwincharan6 жыл бұрын

    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

    3 жыл бұрын

    @@tonmoyrakshit1717 Can u give the code to clea remaining elements

  • @user-youyoki9054
    @user-youyoki90545 жыл бұрын

    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

  • @mamuntheman6543
    @mamuntheman65432 жыл бұрын

    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.

  • @sunainagandra2924
    @sunainagandra29246 жыл бұрын

    thank you sir..please post more..we will be very thakfull sir

  • @sanjayd9675
    @sanjayd96753 жыл бұрын

    #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 if(a[i]!=a[i+1]){ a[j]=a[i]; j++; } } a[j]=a[n-1]; for(int i=0 ; 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 .

  • @harishdalmia6538
    @harishdalmia65385 жыл бұрын

    Hi Can you please share video on : Given a 2D plane with n points in it. Tell me the k closest points near to a given point.

  • @mohanrajg7254
    @mohanrajg7254 Жыл бұрын

    Vivekanand sir can i get java pgm for this ??

  • @caiomartins7807
    @caiomartins78075 жыл бұрын

    Very good lesson !!

  • @krishnareddyyerram4615
    @krishnareddyyerram4615 Жыл бұрын

    i++ j++ will not execute if duplicate found. Sort is required to place duplicate side by side.

  • @saadmanahmed860
    @saadmanahmed8606 жыл бұрын

    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

  • @ranjithparuchuri7326
    @ranjithparuchuri73266 жыл бұрын

    nicely explained.thanks

  • @RTX_valorant
    @RTX_valorant3 жыл бұрын

    Why can't we use just list(set(arr))???

  • @shubhamathawale7296
    @shubhamathawale72962 жыл бұрын

    Thank you sir 🙏 everything is clear now

  • @anchaldubey4217
    @anchaldubey42175 жыл бұрын

    Could you a make video on Chess Design

  • @deepak-lv4vn
    @deepak-lv4vn3 жыл бұрын

    you are completely ossum sir!!

  • @9441571873
    @94415718732 жыл бұрын

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

  • @dandanamado8785
    @dandanamado87854 жыл бұрын

    Thank you, I have a question sir what is the n-1 stands for inside the for loop? Thank you

  • @MrMarkgyuro

    @MrMarkgyuro

    4 жыл бұрын

    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

  • @wmpah
    @wmpah6 жыл бұрын

    very clear and good writing on whiteboard

  • @indianinvestor1301
    @indianinvestor13012 жыл бұрын

    sir really good and help me a lot

  • @Vithal_Nivargi
    @Vithal_Nivargi Жыл бұрын

    Thank you well explained

  • @MAHESHAITBECS
    @MAHESHAITBECS10 күн бұрын

    good explanation sir

  • @santhuravikanti4988
    @santhuravikanti49885 жыл бұрын

    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

  • @malia8693
    @malia86932 жыл бұрын

    great explanation!

  • @samiahmadkhan2865
    @samiahmadkhan28656 жыл бұрын

    You may want to slice of all the elements after j index, since you are doing in place replace.

  • @ganeshshetty8441

    @ganeshshetty8441

    Жыл бұрын

    correct, Even i have commented the same

  • @ramindersonu
    @ramindersonu3 жыл бұрын

    Very good explanation

  • @04.nehalsingh12
    @04.nehalsingh122 жыл бұрын

    awesome tutorial sir

  • @helloyou4233
    @helloyou42336 жыл бұрын

    good quality education.

  • @ramakrishnareddy2702
    @ramakrishnareddy27025 жыл бұрын

    please give me example code for your logic and i'm getting errors to your code

  • @Kidsgyan762
    @Kidsgyan7625 жыл бұрын

    Sir nice explanation

  • @manojnaidu
    @manojnaidu6 жыл бұрын

    what about the remaining elements in the original array after index 4?

  • @amirtim2007

    @amirtim2007

    6 жыл бұрын

    you are right , he needs to go every after the last j, and in every place to put '/0' , or null . depend of the type of the array.

  • @therealsayanroy

    @therealsayanroy

    6 жыл бұрын

    print upto j.. no need to print after that

  • @MohdSameer-rx9gj
    @MohdSameer-rx9gj3 жыл бұрын

    Thank you very much sir...

  • @aokreddy920
    @aokreddy9206 жыл бұрын

    Nice explain sir

  • @nidhisingh7802
    @nidhisingh78023 жыл бұрын

    Sir also tell complexity in each case .

  • @shivanikumari3142
    @shivanikumari31424 жыл бұрын

    in the first method of using extra space,temp has to be intialized.How we will intialize

  • @rajeshdevan6051
    @rajeshdevan60515 жыл бұрын

    Very nice Sir thank you

  • @janispaloma6060
    @janispaloma60605 жыл бұрын

    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.

  • @abhinandanmajumder844
    @abhinandanmajumder8444 жыл бұрын

    Sir, please tell how will u print the output as value of n decreases after removing duplicate

  • @jitendarsahani11

    @jitendarsahani11

    4 жыл бұрын

    You have value of j.. you can use it to iterate throught new array.and print the elements

  • @bishalrajbhattarai5482

    @bishalrajbhattarai5482

    4 жыл бұрын

    But that will be the contion j< upto what? To print the element

  • @RameshThota-ok6ct
    @RameshThota-ok6ct Жыл бұрын

    it is applicable onely numbers are followed some order. it is not work dis order array

  • @khimleshgajuddhur6892
    @khimleshgajuddhur68925 жыл бұрын

    can you give me the code in vb please...?

  • @mohammad-karbalaee
    @mohammad-karbalaee3 жыл бұрын

    you are the loveliest indian ever.

  • @akhint4379
    @akhint4379 Жыл бұрын

    Thank you so much sir❤

  • @ekramdayan3800
    @ekramdayan38004 жыл бұрын

    great video keep it up buddy

  • @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

  • @yasmeenkarachiwala9612
    @yasmeenkarachiwala96124 жыл бұрын

    Amazing!

  • @shahrukhshaikh9558
    @shahrukhshaikh95585 жыл бұрын

    I think we have to add arr[j++] =arr[n-1] if last two elements of array are same in constant space method

  • @moodswingsoflife
    @moodswingsoflife2 жыл бұрын

    Thanks sir .. really helpful

  • @vivekanandkhyade

    @vivekanandkhyade

    2 жыл бұрын

    Thanks a lot

  • @TheMihirpatel23
    @TheMihirpatel234 жыл бұрын

    Thank you so much sir

  • @zaheershaikh7982
    @zaheershaikh79826 жыл бұрын

    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!

  • @neelu5249
    @neelu52496 жыл бұрын

    NYC explanation..but very slow process

  • @avi-0985
    @avi-09855 жыл бұрын

    Sir but if all the elements are same this code will not work For example if array elements are:2 2 2 2 2

  • @ashwathbhat98

    @ashwathbhat98

    5 жыл бұрын

    It will work. Nothing will be added during the for loop since the elements are same. But we add the last element outside the for loop which is 2 in your case. Hope you understood. If not, try using a pen and paper for each i.

  • @hanschaudry808
    @hanschaudry8082 жыл бұрын

    shout out to you bro, I hope someone posted you on national boyfriend day

  • @nabilelassaad6086
    @nabilelassaad60865 жыл бұрын

    where is the code ?

  • @kanimozhiparivallal995
    @kanimozhiparivallal9955 жыл бұрын

    Super class....

  • @spiceto1188
    @spiceto11886 жыл бұрын

    Hi I really appreciated your video. But one question, what does n - 1 mean?

  • @therealsayanroy

    @therealsayanroy

    6 жыл бұрын

    Zohaib Shahzad n is total number of array elements if a[10] then n is 11 cause index of array starts from 0

  • @Lionelandresluis

    @Lionelandresluis

    5 жыл бұрын

    -1 the length of the array

  • @Hamlaww

    @Hamlaww

    5 жыл бұрын

    Can someone show how can we print the temp[j]...

Келесі