An Actually Easy, Easy Coding Interview Question | Remove Duplicates from Sorted Array - Leetcode 26

preview_player
Показать описание
dynamic programming, leetcode, coding interview question, data structures, data structures and algorithms, faang
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Hey Greg, just wanted to stop by and say these style of videos are beyond helpful — especially w the visual representation of the solution!! Keep killing it!

rileyfuller
Автор

I used brute force it worked too but was taking way too much time then I stumbled upon your video.Thanks Greg please keep sharing your knowledge and inputs.

codingcardio-nquc
Автор

I just recently re re- started my coding journey after taking about 2 months of out of frustration. Finally understand that it has to be challenging and have embraced it and pushing forward. Really appreciate the problems and the full code solutions, these are great for someone like me. Thank you.

rezahosein
Автор

Very helpful. Please don't stop making this videos

vascoguerreiro
Автор

What I thought to do was iterate through the array and append each value to a set, since sets don’t allow for duplicates we’re good, then set nums = list(newSet), linear time too

drip
Автор

For the parts on sets; the main reason that ain't gonna work (immediately) is that the sort has to be in-place --> tho it could be rectified using the .clear() and .extend() methods for lists and converting the set to a list. Sets also don't necessarily have to have an order to them; so when converting sets to lists best to sort the list afterwards

rikhilsingh
Автор

"the idea is to use two index approach..." No. Use set, add numbers to set and check if they are there, every loop you are able to write by hands worse than in built ones

knkn
Автор

class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
n1 = [] # Initialize the list to store unique elements
for i in nums:
if i not in n1:
n1.append(i)
return n1 # Return the list of unique elements

# Example usage:
nums = [1, 1, 2, 2, 3]
sol = Solution()
# Output: [1, 2, 3]
Is these code correct !!showing me runtime error

abhisknowledge
Автор

What if your list 0, 1, 2, 3.
0!=1
Then index 1 will equal 0
What happens if your list doesn't contain duplicates?

bronik
Автор

In place means you can't use sets right??

alext
Автор

Does this type of problem solving come natural to developers, or does this have to be learned?

gs
Автор

Can we do it using frequency. Like we get the frequency of the elements and the element that has the max frequency, we'll the value and delete it? If this makes sense. Could you please share the code

neilunavailable
Автор

Why j pointer is not started from 0th index what if a different element is lie on 0th index isn't it will fail test case

yashshiva
Автор

Can't we make the array a set, then make it an array back and fill it up with "_" until we get the same length as the first array?

syncflipper
Автор

I know most languages don't do this, but in js it's just new Set(arr)

ARKGAMING
Автор

Another approach. Since the array are sorted we can use index as actual value and array as miss matched values. Aggregating the min-value to the start of the index gives as a matching expected value in the key section while moving forward in the array. **This is Wrong** Read below.

nicdemai
Автор

Your function doesn't return a list of unique numbers

bronik
Автор

if passed an empty list, you are returning length of 1 for the new list

mazthespaz
Автор

Here we go, python kids in comment section already started talking about set which is a predefined thing.... The objective of the question is to solve using your brain 🧠, not with python predefined stuff.

lastwish