Тёмный

Check If N and Its Double Exist - Leetcode 1346 - Solve with Sam in Python 

Sam Does Leetcode
Подписаться 599
Просмотров 223
50% 1

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 5   
@tinle6487
@tinle6487 4 месяца назад
My man I'm still waiting for that strong password checker hahah !! Keep up the good work
@samobot
@samobot 4 месяца назад
Speak of the devil ;) I actually finished recording the video recently! I have some other videos in the pipeline, but once I'm finished editing it I'll bump it up in the queue, ie it'll be public within the next 2-3 days :) What a fun problem by the way, thanks for sharing it!
@tinle6487
@tinle6487 4 месяца назад
Brighten me please lol. That was a hard one that I cannot understand even the solution haha
@nguyentuan1990
@nguyentuan1990 Месяц назад
i still dont understand why it would failed at 0
@samobot
@samobot Месяц назад
Hey! Let me know if I misunderstood you, but I think we need to check for 0 because the question rules are find two indices i and j, and specifically i != j , that satisfies arr[i] == 2 * arr[j] if we didn't have a special check for 0, then given an array with a single 0 arr = [0] and we've filled our dictionary d = {index 0: value 0} b = arr[i] = 0 a = 2*b = 2*0 = 0 so a == b as 0 == 0, so (a in dictionary, ie arr[i] == 2*arr[j] ) comes to true, so the algorithm would return True for arr = [0], which is incorrect by the rules because i == j in this case. As a result, we need a special check that the index of the value in the dictionary 'j' is not equal to idx 'i', hence the (d[a] != idx). If there's a trick here I'm missing let me know!
Далее
The LeetCode Fallacy
6:08
Просмотров 495 тыс.
Will A Guitar Boat Hold My Weight?
00:20
Просмотров 68 млн
Faster than Rust and C++: the PERFECT hash table
33:52
Просмотров 561 тыс.
Most Common Concepts for Coding Interviews
6:08
Просмотров 309 тыс.
Minimum Falling Path Sum II - Leetcode 1289 - Python
31:44
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36