Remove Duplicates from Sorted Array II | Leetcode 80 | Array

preview_player
Показать описание
Time Complexity : O(n)
Space Complexity : O(1)


Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)

#DataStructuresAndAlgorithms
#RemoveDuplicatesFromSortedArray
#interviewpreparation
Remove Duplicates from Sorted Array II solution
Remove Duplicates from Sorted Array II Leetcode
Remove Duplicates from Sorted Array II C++
Remove Duplicates from Sorted Array II Java
Remove Duplicates from Sorted Array II Python

🔥🔥🔥🔥👇👇👇

Checkout the series: 🔥🔥🔥
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
Рекомендации по теме
Комментарии
Автор

The code is :
class Solution {
public int removeDuplicates(int[] nums) {
int i=0;
for(int e=0;e<nums.length;e++)
{
if(i==0 || i==1 || nums[i-2]!=nums[e])
{
nums[i]=nums[e];
i=i+1;
}
}
return i;
}
}

debjeetmukherjee
Автор

Your explanation is good. Please explain constraint before you move on to the solution. Many people don't bother to see the constraint which will end up in TL. By doing these viewers Space and Time Complexity concepts gets cleared

adilkevin
Автор

class Solution {
public int removeDuplicates(int[] nums) {
int arraySize = nums.length;

/** Edge case */
if(arraySize <= 2)
return arraySize;

int head = 2;
int tail = 2;

while(head< arraySize){
if(nums[head]!= nums[tail-2]){
nums[tail]=nums[head];
tail++;
}
head++;
}

return tail;
}
}


3 conditions on the if block can be replaced with only one, Since we are only copying the first 2 elements, we can skip these directly by starting with 2nd index in array & add one edge case for the array of size <=2.

AjayGaulia
Автор

wow! well explained. I was not getting the approach to solve this. Thanks a lot!

dbm
Автор

Good Dry Run, Able to understand... Thanks

prithvi
Автор

Very well explained mam, it helped me a lot, pls continue making such type of videos, as it help a lot in problem solving ❤❤

KeshavSharma-uogi
Автор

thatks a lot mam....it helped me well....your explanation was nice and clear
thank you once again

AnandhS-lluu
Автор

Amazing that you've done it using a single loop! Good job!

basquiatttt
Автор

Thanks .. When you are in doubt with the problem and your video shows up.. perfect..

manishsahu
Автор

I use this Concept to solve LeetCode Problem -26, 27, 80

ashishkumarshawhitchem
Автор

Shouldn't it be returning i+1 because as we need the length

anjaliChaudhary-tucd
Автор

Thanks a lot for such a great explanation, Ayushi 😇

ChandraShekhar-bycd
Автор

Explanation and dry run is just so perfect...!!! 👌

Quasar-
Автор

Ohh.. thanks Aayushi, I came from LinkedIn! BTW very good explanation skills

AbhishekGupta-crmf
Автор

1:38 .. 2 is single only.. 😅 like many guys in india

abcdabcdabcd
Автор

Hi Ayushi
are we also required to change the given array

sagarbora
Автор

code will work, but this concept is or pseudocode explanation is not corect

me_npj
Автор

Ma'am I wasn't able to approach this question....so should I practise more questions on two-pointers tag?

girikgarg
Автор

Ma'am this was a sorted array.... so couldn't a binary search approach work here?

girikgarg
Автор

Great explanation ma'am . It was helpful for me😇

mdsahil
welcome to shbcf.ru