Remove Duplicates From Sorted Array | Brute | Optimal

  Рет қаралды 134,256

take U forward

take U forward

Күн бұрын

Пікірлер: 87
@takeUforward
@takeUforward 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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;
@sameerakhatoon9508
@sameerakhatoon9508 2 жыл бұрын
same here
@lakshsinghania
@lakshsinghania Жыл бұрын
why i didnt get this intuition in my head b4 the hashset one which i got :/
@srishtikdutta8946
@srishtikdutta8946 4 жыл бұрын
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 жыл бұрын
Very amazing and simple solution 👍👍 Thank you for all you efforts ❣️ Get well soon
@ranasauravsingh
@ranasauravsingh 2 жыл бұрын
UNDERSTOOD... !!! Thanks striver for the video... :)
@VandanaYadav-yp9zv
@VandanaYadav-yp9zv 2 жыл бұрын
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 жыл бұрын
Thank you!!get well soon!!❣️❣️
@adarshrai9516
@adarshrai9516 4 жыл бұрын
Happy new year bhai And thanks. U give content not gyaan on your channel . Following form starting 🙏
@adityakundu4363
@adityakundu4363 2 жыл бұрын
Set set = new HashSet(); int k=0; for(int i=0;i
@wanderer_ankur
@wanderer_ankur 4 жыл бұрын
Bhai get well soon! Thanks for being an inspiration to many people like me :)
@rishabhbhagwati5013
@rishabhbhagwati5013 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 жыл бұрын
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 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 жыл бұрын
Thanks for the code and making us understand. you're the real help bhai
@himanshu4033
@himanshu4033 4 жыл бұрын
does hashsets are same as sets in Python ?
@takeUforward
@takeUforward 4 жыл бұрын
Yeah
@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 жыл бұрын
Thank you so much and get well soon!!
@smitpatel7153
@smitpatel7153 3 жыл бұрын
#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
@nehamohammadniyaz848
@nehamohammadniyaz848 3 жыл бұрын
int count=0; if(nums.length>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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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?
@collegematerial5348
@collegematerial5348 2 жыл бұрын
yes it work check by dry run
@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 жыл бұрын
Striver bro please make a video on time and space complexities
@zyro9922
@zyro9922 2 жыл бұрын
Good explanation.
@amritanarang7305
@amritanarang7305 4 жыл бұрын
well explanained👍🏻
@yashpaunikar671
@yashpaunikar671 Жыл бұрын
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 жыл бұрын
Coz i started from 0 and ended at 2 so req. size of array=i+1=3
@Manishgupta200
@Manishgupta200 Жыл бұрын
Amazing 🔥🔥
@yeswanthh5068
@yeswanthh5068 2 жыл бұрын
Understood sir
@Girish415
@Girish415 4 жыл бұрын
welcome back🔥🔥
@niranjanaware5930
@niranjanaware5930 2 жыл бұрын
great sol👌👌
@kritikakashyap384
@kritikakashyap384 4 жыл бұрын
Thanks for this video
@sammohanty5507
@sammohanty5507 4 жыл бұрын
Love you bhai
@shahatearjun
@shahatearjun 10 ай бұрын
why i+1 can anyone explain ??
@anuranjansrivastava8543
@anuranjansrivastava8543 4 жыл бұрын
Nice video bhaiya
@youtubekumar8590
@youtubekumar8590 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Hny
@sudesh2911
@sudesh2911 4 жыл бұрын
Bhai tu aise condition mei Video kyu banara 🥺🥺.. Take Rest Bro
@nishchaygupta9988
@nishchaygupta9988 2 жыл бұрын
Found this one line code : nums.erase(unique(nums.begin(),nums.end()),nums.end()); return nums.size(); Try this out.
@firozkamdar6735
@firozkamdar6735 11 ай бұрын
@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!!
Remove Duplicates from Sorted Array - Leetcode 26 - Python
10:38
Trapping Rainwater | Brute | Better | Optimal | with INTUITION
23:23
take U forward
Рет қаралды 283 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
L20. Remove duplicates from sorted DLL
12:53
take U forward
Рет қаралды 48 М.
4SUM | GOOGLE | AMAZON
22:02
take U forward
Рет қаралды 176 М.
Functional programming - A general introduction
11:47
Daedalus Community
Рет қаралды 122 М.
N meetings In One Room | Greedy Algorithm
18:00
take U forward
Рет қаралды 199 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 851 М.
Remove Duplicates from sorted Array
21:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 177 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,3 МЛН
Bitwise Operators and WHY we use them
8:41
Alex Hyett
Рет қаралды 99 М.
Longest Substring Without Repeating Characters | Amazon
24:00
take U forward
Рет қаралды 297 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН