Search Insert Position (LeetCode 35) | Full solution with examples animations | Study Algorithms

preview_player
Показать описание
Binary Search is a fabulous concept that can be used to narrow down the search range. One such problem on LeetCode explores this domain where you need to find the correct position to insert the element in a sorted array. Watch the video to see animations on how to find this index. All along with visuals and a dry-run of code in JAVA.

Chapters:
00:00 - Intro
01:09 - Problem Statement and Description
04:14 - Straight Forward Solution
06:21 - Efficient Approach to search insert position
10:44 - Dry-run of Code
13:06 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

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

Thank you for teaching this. You are doing a great job.

prathijathiruppathy
Автор

your teaching is good, I wached so many videos but dont understand about last part. But from your video I got that. keep it up and thanks

astronaut
Автор

Thanks! After watching many videos, finally find one I can understand....

shuwenzhao
Автор

best explanation sir... i have ever followed. please keep continue

pulastyadas
Автор

your explanations is the best sir
you deserve more followers ♥♥♥♥♥♥♥♥♥♥♥
Thanks for the video sir

amanprajapati
Автор

i think there is some error at timestamp 12:02
high = mid -1
and mid = 2 so high should be 2-1 = 1 but you wrote 2

tejasdonadkar
Автор

Good explanation. Please do more videos on Leet Code problems. Appreciate your efforts !

pragmaticcoder
Автор

I love your talking speed ❤😊 it really helps to understand the solution

sandeepnarwal
Автор

Last approach gives TLE. time lime execced.

Code :-
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
l = 0
h = len(nums) - 1
while(l<=h):
mid = l + (h-l) / 2

if nums[mid] == target:
return mid
elif nums[mid] > target :
h = mid -1
else:
l = mid +1
return l

everyontech
Автор

this code at the end doesn't pass the leetcode pre tests though...

DhundupTseringOfficial