Find the Minimum and Maximum Number of Nodes Between Critical Points - Leetcode 2058 - Python

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


0:00 - Read the problem
0:30 - Drawing Explanation
6:08 - Coding Explanation

leetcode 2058

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

After solving 171 questions with you i finally came up with same solutions as yours. Amazing channel! I became addicted to LC

JamesBond-mqpd
Автор

00:08 Bro offended the LeetCode today! 😁

Polly
Автор

This question is easy if you store all critical points in an array. Otherwise, its medium

tuandino
Автор

Gosh, neetcode is sooo good, how does he even solve problems so easily

fahimquicklife
Автор

It would be nice if you explain contest solutions too

nnkbrain
Автор

Split Array into Fibonacci Sequence. Solve and explain.

anirbanhossen
Автор

here 1:53 you see a funny lookin guy...Thank you bro, I have started doing these problems with more knowledge

loke_mc
Автор

my solution:
def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:
prev = head
cur = head.next
criticals = []
index = 2
minDist = float("inf")

def isCritical(prev, cur):
return (prev.val < cur.val > cur.next.val or
prev.val > cur.val < cur.next.val)

while cur.next:
if isCritical(prev, cur):
criticals.append(index)

if len(criticals) > 1:
minDist = min(minDist, criticals[-1] - criticals[-2])

index += 1
prev = cur
cur = cur.next

if len(criticals) < 2: return [-1, -1]
return [minDist, criticals[-1] - criticals[0]]

galkk
Автор

i also got ~400ms runtime even after multiple submissions tf is supposed to be faster ?

pastori