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
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 😅
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.
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;
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.
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.
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
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?
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
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
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
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
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 😅
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.
can you share the solution ?
How did you get O(log N)? I do not think it is possible.
Liar
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;
same here
why i didnt get this intuition in my head b4 the hashset one which i got :/
Thank You bhaiya, happy new year and get well soon❤️
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.
Very amazing and simple solution 👍👍
Thank you for all you efforts ❣️
Get well soon
UNDERSTOOD... !!!
Thanks striver for the video... :)
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.
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
Thank you!!get well soon!!❣️❣️
Happy new year bhai And thanks.
U give content not gyaan on your channel .
Following form starting 🙏
Set set = new HashSet();
int k=0;
for(int i=0;i
Bhai get well soon! Thanks for being an inspiration to many people like me :)
Happy new year bhaiya, jaldi theek hojao😊
in this problem,
if we insert all the element and return the size of the set,
why don't accept it?
1:56 method1
5:42 method2
Feeling very very happy, to listen your voice bhya, after long time, aap jldi se thik hao jao bass, 💯💥💥💯
I am bit confused as the problem says we should not allocate extra space and need to only modify the existing array
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?
Custome judge will take your modified array and check if its correct or not. Array need not be returned for checking.
Here “i” returns index of current position and if you add 1 it returns the exact length
@@akhilraghav7677 how by adding one it will return correct length
Wow wonderful explanation as a beginner it's so helpfull
Thanks for the code and making us understand. you're the real help bhai
does hashsets are same as sets in Python ?
Yeah
We can use queue for O(1) insertion and deletion
thank u bro for ur efforts in helping the students.You deserve a lot
Thank you so much and get well soon!!
#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
int count=0;
for(int i=1; i
int count=0;
if(nums.length>0)
for(int i=1; i
Sir, Great !! Love the approach !
best explanation of this problem ever !
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
Striver is back , started doing sde sheet,hope it will be completed in next 3 months
Great Explanation🙂
Please tell the binary search approach
Happy new year Bro;
Thank you for the grt explanation
Hasset doesn't store elements in a specific order
Thanks for the amazing explanation
what if the input is [1,2,3,3] this code wont work right?
yes it work check by dry run
Why do we return i+1, can u explain please?
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
Striver bro please make a video on time and space complexities
Good explanation.
well explanained👍🏻
Attendance in 2023😊❤
thanks a lot vaeya for this series
Easy c++ approach
int k=1;
for(int i=1; i
You deserve a like
can you please tell why you returned i+1
anybody please tell
Coz i started from 0 and ended at 2
so req. size of array=i+1=3
Amazing 🔥🔥
Understood sir
welcome back🔥🔥
great sol👌👌
Thanks for this video
Love you bhai
why i+1 can anyone explain ??
Nice video bhaiya
Thanks bhaiya
Understood
Int a =Arr[0];
Int b = arr[1];
For i in n
If ( arra ==arrb)
B++
Else
I++
Arr[j] = arr [i]
u r great!!
Thank you bhaiya
Best and get well soon
nice video
Rather than for loop i'm done with while loop
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
Hare Krishna
Why don't you start explaining why will a approach work, instead of just showing what the approach does
Hny
Bhai tu aise condition mei Video kyu banara 🥺🥺.. Take Rest Bro
Found this one line code :
nums.erase(unique(nums.begin(),nums.end()),nums.end());
return nums.size();
Try this out.
❤
Hey @striver in Brute force T.C- 0(NlogN) + O(NlogN)
The last logN for removing an element from ordered set
Am I right ?
u r great!!