Contains Duplicate - Leetcode 217 - Python

preview_player
Показать описание


0:00 - Read the problem
1:15 - Drawing Explanation
5:13 - Coding Explanation

leetcode 217

#microsoft #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

I utilized this course for MAANG prep and I could clear the Amazon interviews. Thank You !

ij
Автор

Another approach: convert the list to a set if the len(set)==len(list), return False else: return True

kavyagarikapati
Автор

I'm using this channel as my preparation kit. Thank you!

tanoybhowmick
Автор

Started my planned 3 months leetcode journey today using neetcode as guide. Hoping to come back to this comment sometime in December fully prepared for any coding interview 🙏

chigozie_jesse
Автор

This is the last question right? Kudos for completing it for us, your channel is an awesome resource :)

dumbnumbz
Автор

My 1st neetcode problem. Hopefully I am going to acheive something big by the end of this journey I started today

mtamjidhossain
Автор

T: O(nlogn) & S: O(1) --->

nums = [1, 2, 3, 1]

sortN = sorted(nums)
l, r = 0, 1

def containsDuplicate(l, r, s):
while l < len(s) and r < len(s):
if s[l] == s[r]:
return True
l += 1
r += 1
return False

print(containsDuplicate(l, r, sortN))

robogirlTinker
Автор

I got a simple one. Use set and check size of the set each time we insert an element and compare it to the size from the previous iteration.

Pseudo Code:

prevSize = 0;
for (i=0; i<len; i++){
set.add(nums[i]);
if(set.size == prevSize)
break;
prevSize = set.size;
}
if(prevSize != len)
return true;
return false;


Logic: If the set size remains same in two consecutive iterations, then there's duplicate.

innerlion
Автор

best approach ever : just two line of codes

bool nums) {
set <int> s {nums.begin(), nums.end()};

return s.size() == nums.size() ? false : true;
}

mohamedmuslim
Автор

just starting on neetcode website now. Will probably try one problem at a time every few days or more often once i have most of my concepts and basic syntax refreshed :P Hopefully, I can get to the point where I solve few problems a day and just be comfortable at mid-hard level questions. Long way to go, but at least the goal is clear.

HarimaKentaro
Автор

Thank you! I solved the problem with all these approaches on my own, but each time I couldn't achieve low consumption of both cpu and memory. Then I decided to look at the solutions, and was surprised that there is no ideal solution. Only compromises. Valuable lesson for me.

Boyarsskiy
Автор

I am sharing your videos and website with my 40 actively learning friends. Thank you for supporting us.

programmermainul
Автор

1st day of Leetcode. Graduation in 11 months. Let's go!

mohanvamsikrishna
Автор

Bro but please continue more questions in python. Please Please

sharemarketsher
Автор

@neetcode I have a question: will it be at 2:56 Complexity O(N*logN + N) because N*logN for sorting and then +N for comparison?

bogdanoleksyshyn
Автор

after watching your tutorial everyday for almost a month, finally i have started building logic like the way you do, BIG THANKS TO YOU!

_krutikamhatre_IT
Автор

I think we can also do this question by creating a set....if set's length== given list then we can say false otherwise true.

MrMukulpandey
Автор

Another approach would be to insert the array into the hashset, which would be O(logn) ... and compare the size of hashset with array, if they are equal return false else return true. This would be the fastest in terms of execution I suppose, but would require O(n) space more.

mustafasabir
Автор

What's the difference between hashmap and hashset? In this case, which one should use?

lch
Автор

Hey neetcode fam, got a technical assessment with microsoft today. Wish me luck.

robertoromanramirez