FIND PEAK ELEMENT | LEETCODE # 162 | PYTHON BINARY SEARCH SOLUTION

  Рет қаралды 3,635

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 5
@lepakshiagarwal6118
@lepakshiagarwal6118 8 ай бұрын
This solution gives a time limit exceeded on leetcode but was really easy to understand. Thank you for explaining
@aminebesbes6202
@aminebesbes6202 2 жыл бұрын
The solution could be more simplified as this (Easy Binary Search with no need to check boundaries): class Solution: def findPeakElement(self, nums: List[int]) -> int: left, mid, right = 0, 0, len(nums)-1 while leftnums[mid+1]: right = mid else: left = mid +1 return left
@rdnetala
@rdnetala Ай бұрын
easy recursrive sol: class Solution: def findPeakElement(self, nums: List[int]) -> int: def bs(left, right): if left == right: return left # Base case: single element, so it’s a peak mid = (left + right) // 2 # Compare middle with the next element to decide which side to search if nums[mid] > nums[mid + 1]: # Peak is in the left half return bs(left, mid) else: # Peak is in the right half return bs(mid + 1, right) return bs(0, len(nums) - 1)
@rsKayiira
@rsKayiira 2 жыл бұрын
Good solution, Could you do LC 987?
@subee128
@subee128 10 ай бұрын
Thanks
BS-9. Find Peak Element
32:53
take U forward
Рет қаралды 199 М.
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 12 М.
Find Peak Element - Leetcode 162 - Python
11:02
NeetCodeIO
Рет қаралды 48 М.
Binary Search in Python: Find Bitonic Peak
14:17
LucidProgramming
Рет қаралды 4,2 М.
MAKING A LARGE ISLAND | LEETCODE # 827 | PYTHON SOLUTION
22:09
Cracking FAANG
Рет қаралды 8 М.
Search in rotated sorted array - Leetcode 33 - Python
13:28
NeetCode
Рет қаралды 364 М.
NEXT PERMUTATION | LEETCODE # 31 | PYTHON OPTIMAL SOLUTION
18:50
Cracking FAANG
Рет қаралды 13 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
DOT PRODUCT OF TWO SPARSE VECTORS - 3 SOLUTIONS EXPLAINED [PYTHON]
31:06
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН