Remove Duplicates From Sorted Array | Brute | Optimal

preview_player
Показать описание

In case you are thinking to buy courses, please check below:

#dsa #leetcode #placements
Рекомендации по теме
Комментарии
Автор

Do leave a comment if you get the solution :) helps me a lot


Instagram: striver_79

takeUforward
Автор

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 😅

mohammadumaidansari
Автор

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.

alphonseprakash
Автор

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;

ghoshdipan
Автор

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

srishtikdutta
Автор

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.

pranjalchaplot
Автор

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

ranasauravsingh
Автор

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

jaskiratsinghosahan
Автор

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.

VandanaYadav-ypzv
Автор

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

kunalbahirat
Автор

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

akshatchaturvedi
Автор

Set<Integer> set = new HashSet<Integer>();
int k=0;
for(int i=0;i<nums.length;i++)
{
set.add(nums[i]); // nums is the int array

}
k=set.size();
return k;

why its not working??

adityakundu
Автор

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

adarshrai
Автор

Easy c++ approach
int k=1;
for(int i=1; i<nums.size(); i++)
if(nums[i]!=nums[i-1]) nums[k++] = nums[i];
return k;

nerduser
Автор

Happy new year bhaiya, jaldi theek hojao😊

rishabhbhagwati
Автор

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

wanderer_ankur
Автор

does hashsets are same as sets in Python ?

himanshu
Автор

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?

sumeetbisen
Автор

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

harshitbhalla
Автор

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

padmahegde