Remove Duplicates from Sorted Array 2 | Leetcode 80 | Top 150 Interview questions series

preview_player
Показать описание
Top 150 interview question series
Remove Duplicates from Sorted Array 2
Leetcode problem number 80

JAVA interview programming playlist:

Git Repo:
Рекомендации по теме
Комментарии
Автор

Hey Amrita can you please finish this playlist? Not sure why you stopped making videos on this 150 interview question series. But out of all the channels on youtube I found only this channel where I was able to understand the solutions easily. Please continue making more videos. 🙏 Thank you.

gurudassulebhavikar
Автор

class Solution {
public int removeDuplicates(int[] nums) {
int c=0;
for(int i=0;i<nums.length;i++){
if(i<nums.length-2 && nums[i]==nums[i+2]){

continue;
}
nums[c]=nums[i];
c++;
}
return c;
}
}

SandraSaade
Автор

Explanation is different from the code solution. If n == nums[i-2], 'i' doesn't increment in the code but in the explanation.

muhammadomersaleem
Автор

Great intuition and the approach was perfect comparing to the complex Leetcode editorial approaches.

dineshvasireddy
Автор

Wow, what a great explanation and a beautiful algorithm!

oxanasf
Автор

Amazing, very easy explanation, thank you

ShubhamKumar-yzyz
Автор

best explaination and clear mam, thank you so much mam

JackCoderr
Автор

Essentially this not in constant space. Because in the for loop, you are creating another copy for the array.

mayukh_
Автор

In interviews they are going to ask in place modification of the array.

vinayvardhanyt
Автор

Mam, it would be great if you give your linkedin profile in the description, and also tell your full name, it would help to make connection

codingbitsnbytes
Автор

Great explanation. the key point is nums[i] != num[i-2]. But why in the code it becomes n != nums[i-2] ?

jason-rvsp
Автор

if array is like that 1 2 3 4 4 4 5 5 6 in that what about 2 element

KRRSPORTS
Автор

mam why this solution not working

class Solution {
public int removeDuplicates(int[] nums) {
int j=0;
for(int i=0;i<nums.length;i++)
{
if(i<2||nums[i]!=nums[i-2])
{
nums[j++]=nums[i];
}
}
return j;
}
}

AyushTiwari-vvxk