Remove Duplicates From Sorted Array | Brute | Optimal

Поделиться
HTML-код
  • Опубликовано: 22 янв 2025

Комментарии • 87

  • @takeUforward
    @takeUforward  4 года назад +12

    Do leave a comment if you get the solution :) helps me a lot
    C++ Code link: github.com/striver79/SDESheet/blob/main/removeDuplicatesC%2B%2B
    Java Code link: github.com/striver79/SDESheet/blob/main/removeDuplicatesJava
    Instagram: striver_79
    Join our telegram group: t.me/Competitive_Programming_tuf

  • @mohammadumaidansari5087
    @mohammadumaidansari5087 4 года назад +43

    Hats off to your effort in helping the students . It really means a lot that you're helping us and doing all the things that can be done from your side even after your health condition is not well.
    Thank you so much Sir!! 😄♥
    Going to watch the video now 😅

  • @alphonseprakash7459
    @alphonseprakash7459 2 года назад +9

    i solved the same question in O(log N) by using upper_bound in my Microsoft Interview and even interviewer was shocked... No one talks about the log solution but it will work like butter better find the upper_bound every time.

    • @virusnetic
      @virusnetic 2 года назад +2

      can you share the solution ?

    • @ThejusRao
      @ThejusRao 6 месяцев назад

      How did you get O(log N)? I do not think it is possible.

    • @gouravtharan9842
      @gouravtharan9842 4 месяца назад

      Liar

  • @ghoshdipan
    @ghoshdipan 4 года назад +34

    I'm following this SDE sheet and I can see the change.
    I just came to see the optimal solution and just after I saw the 2pointer technique I paused immediately and coded it self;

  • @srishtikdutta8946
    @srishtikdutta8946 4 года назад +19

    Thank You bhaiya, happy new year and get well soon❤️

  • @pranjalchaplot
    @pranjalchaplot 2 года назад

    Just and addition in the brute force that instead of hashset you can use stack and since the array is in ascending order you only need to insert in stack if the nums[i] is greater than stack.top() and at the end get the stack size and since the top element would be the largest you need to reverse traverse the given nums from stack.size()-1 to 0 and fill the elmenent and of course it is assumed that you have taken the size of array before reverse Traverse and at last send the size.

  • @jaskiratsinghosahan4638
    @jaskiratsinghosahan4638 4 года назад +4

    Very amazing and simple solution 👍👍
    Thank you for all you efforts ❣️
    Get well soon

  • @ranasauravsingh
    @ranasauravsingh 2 года назад +2

    UNDERSTOOD... !!!
    Thanks striver for the video... :)

  • @VandanaYadav-yp9zv
    @VandanaYadav-yp9zv 2 года назад +1

    Thanks for all your efforts and all the work you are doing ! just wanted to point out I executed this code and found that if array elements are {2,2,3,4,5,5,6,6} in this case the first 2 did not get printed(it gets skipped) code snippet.

  • @kunalbahirat7795
    @kunalbahirat7795 2 года назад

    we don't need to store elements in hashset bcoz array is already sorted in (naive).Instead we can store elements in another array or vector that will take only O(n) TC

  • @parikshitrathore1510
    @parikshitrathore1510 4 года назад +5

    Thank you!!get well soon!!❣️❣️

  • @adarshrai9516
    @adarshrai9516 4 года назад +2

    Happy new year bhai And thanks.
    U give content not gyaan on your channel .
    Following form starting 🙏

  • @adityakundu4363
    @adityakundu4363 2 года назад +1

    Set set = new HashSet();
    int k=0;
    for(int i=0;i

  • @wanderer_ankur
    @wanderer_ankur 4 года назад +1

    Bhai get well soon! Thanks for being an inspiration to many people like me :)

  • @rishabhbhagwati5013
    @rishabhbhagwati5013 4 года назад +4

    Happy new year bhaiya, jaldi theek hojao😊

  • @mainurrahat4099
    @mainurrahat4099 Год назад

    in this problem,
    if we insert all the element and return the size of the set,
    why don't accept it?

  • @kewaltakhellambam7710
    @kewaltakhellambam7710 Год назад

    1:56 method1
    5:42 method2

  • @roushanraj8530
    @roushanraj8530 4 года назад

    Feeling very very happy, to listen your voice bhya, after long time, aap jldi se thik hao jao bass, 💯💥💥💯

  • @padmahegde5457
    @padmahegde5457 2 года назад

    I am bit confused as the problem says we should not allocate extra space and need to only modify the existing array

  • @sumeetbisen9708
    @sumeetbisen9708 3 года назад +2

    I am a little new at coding, we are supposed to return an array, so how is returning(i+1) is giving a correct answer, since i is an integer and not a pointer, can anyone explain?

    • @shreyasshetty5051
      @shreyasshetty5051 3 года назад

      Custome judge will take your modified array and check if its correct or not. Array need not be returned for checking.

    • @akhilraghav7677
      @akhilraghav7677 3 года назад +2

      Here “i” returns index of current position and if you add 1 it returns the exact length

    • @collegematerial5348
      @collegematerial5348 2 года назад

      @@akhilraghav7677 how by adding one it will return correct length

  • @hari123priya
    @hari123priya Год назад

    Wow wonderful explanation as a beginner it's so helpfull

  • @rosonerri-faithful
    @rosonerri-faithful 3 года назад +1

    Thanks for the code and making us understand. you're the real help bhai

  • @himanshu4033
    @himanshu4033 4 года назад +6

    does hashsets are same as sets in Python ?

  • @harshitbhalla9274
    @harshitbhalla9274 Год назад

    We can use queue for O(1) insertion and deletion

  • @lokeshvikram6192
    @lokeshvikram6192 4 года назад

    thank u bro for ur efforts in helping the students.You deserve a lot

  • @shreymehrotra5408
    @shreymehrotra5408 4 года назад +1

    Thank you so much and get well soon!!

  • @smitpatel7153
    @smitpatel7153 3 года назад +4

    #include
    #include
    class Solution {
    public:
    int removeDuplicates(vector& nums) {
    int siz=nums.size();
    stack q;
    for(int i=0;i=0;n--){
    nums[n]=q.top();
    q.pop();
    }
    return a;

    }
    };
    new solution using stack

  • @nehamohammadniyaz848
    @nehamohammadniyaz848 3 года назад

    int count=0;
    for(int i=1; i

  • @joydeb8202
    @joydeb8202 4 года назад

    Sir, Great !! Love the approach !

  • @divyansh3266
    @divyansh3266 3 года назад

    best explanation of this problem ever !

  • @harshitsaluja3493
    @harshitsaluja3493 3 года назад +2

    Hi Nice explanation. Time Complexity will be O(n) but how can space complexity be o(n) will it not be O(1) as it is in place assignment ? Thanks in advance

  • @akshatchaturvedi7407
    @akshatchaturvedi7407 4 года назад +6

    Striver is back , started doing sde sheet,hope it will be completed in next 3 months

  • @kshitijpandey9376
    @kshitijpandey9376 3 года назад

    Great Explanation🙂

  • @LordRadhakrishnaa
    @LordRadhakrishnaa 11 месяцев назад

    Please tell the binary search approach

  • @animeshprasad5268
    @animeshprasad5268 4 года назад +1

    Happy new year Bro;

  • @Sweetydiaries12
    @Sweetydiaries12 Год назад

    Thank you for the grt explanation

  • @deep90402
    @deep90402 4 месяца назад

    Hasset doesn't store elements in a specific order

  • @sannidiashish2312
    @sannidiashish2312 2 года назад

    Thanks for the amazing explanation

  • @gowthamchokkalingam3090
    @gowthamchokkalingam3090 2 года назад

    what if the input is [1,2,3,3] this code wont work right?

  • @doyouknowyourcomputer
    @doyouknowyourcomputer 2 года назад

    Why do we return i+1, can u explain please?

    • @zawarudo6389
      @zawarudo6389 2 года назад

      i is pointer in the array nums pointing towards a index and currently it is pointing at i=2 index after the for loop terminates and in output of the test case required output is 3 thus this is a pattern and will work for all test cases

  • @anveshreddy1245
    @anveshreddy1245 4 года назад +2

    Striver bro please make a video on time and space complexities

  • @zyro9922
    @zyro9922 2 года назад

    Good explanation.

  • @amritanarang7305
    @amritanarang7305 4 года назад

    well explanained👍🏻

  • @yashpaunikar671
    @yashpaunikar671 Год назад +1

    Attendance in 2023😊❤

  • @oqant0424
    @oqant0424 4 года назад

    thanks a lot vaeya for this series

  • @nerduser1000
    @nerduser1000 2 года назад

    Easy c++ approach
    int k=1;
    for(int i=1; i

  • @cypher.hiphop
    @cypher.hiphop 2 года назад

    You deserve a like

  • @collegematerial5348
    @collegematerial5348 2 года назад

    can you please tell why you returned i+1
    anybody please tell

    • @theupsidedown9101
      @theupsidedown9101 2 года назад +1

      Coz i started from 0 and ended at 2
      so req. size of array=i+1=3

  • @Manishgupta200
    @Manishgupta200 Год назад

    Amazing 🔥🔥

  • @yeswanthh5068
    @yeswanthh5068 2 года назад +1

    Understood sir

  • @Girish415
    @Girish415 4 года назад

    welcome back🔥🔥

  • @niranjanaware5930
    @niranjanaware5930 2 года назад

    great sol👌👌

  • @kritikakashyap384
    @kritikakashyap384 4 года назад

    Thanks for this video

  • @sammohanty5507
    @sammohanty5507 4 года назад +3

    Love you bhai

  • @shahatearjun
    @shahatearjun 10 месяцев назад

    why i+1 can anyone explain ??

  • @anuranjansrivastava8543
    @anuranjansrivastava8543 4 года назад +1

    Nice video bhaiya

  • @youtubekumar8590
    @youtubekumar8590 2 года назад +1

    Thanks bhaiya

  • @Icelander00
    @Icelander00 Год назад

    Understood

  • @kidoo1567
    @kidoo1567 Год назад

    Int a =Arr[0];
    Int b = arr[1];
    For i in n
    If ( arra ==arrb)
    B++
    Else
    I++
    Arr[j] = arr [i]

  • @nikitasaha8399
    @nikitasaha8399 3 года назад

    u r great!!

  • @kingsman.blood1
    @kingsman.blood1 3 года назад

    Thank you bhaiya

  • @farheenfirdous6530
    @farheenfirdous6530 4 года назад

    Best and get well soon

  • @MouniaPrasad
    @MouniaPrasad Год назад

    nice video

  • @Manishgupta200
    @Manishgupta200 Год назад

    Rather than for loop i'm done with while loop

  • @SatyamKumar-dj3jo
    @SatyamKumar-dj3jo 3 года назад +1

    This can be a solution make counter to keep position. It worked perfectly on leetcode
    class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
    count=0
    for i in range(len(nums)-1):
    if(nums[i]!=nums[i+1]):
    count+=1
    nums[count]=nums[i+1]
    return count+1

  • @SatyamKumar-bw4vi
    @SatyamKumar-bw4vi 2 года назад

    Hare Krishna

  • @vanshikaagarwal98
    @vanshikaagarwal98 11 месяцев назад

    Why don't you start explaining why will a approach work, instead of just showing what the approach does

  • @rishitiwari6200
    @rishitiwari6200 4 года назад +1

    Hny

  • @sudesh2911
    @sudesh2911 4 года назад +2

    Bhai tu aise condition mei Video kyu banara 🥺🥺.. Take Rest Bro

  • @nishchaygupta9988
    @nishchaygupta9988 2 года назад +1

    Found this one line code :
    nums.erase(unique(nums.begin(),nums.end()),nums.end());
    return nums.size();
    Try this out.

  • @veeravallinitish9707
    @veeravallinitish9707 3 года назад

    Hey @striver in Brute force T.C- 0(NlogN) + O(NlogN)
    The last logN for removing an element from ordered set
    Am I right ?

  • @nikitasaha8399
    @nikitasaha8399 3 года назад

    u r great!!