First and Last Position of Element Sorted Array (LeetCode 34) | Full Solution | Study Algorithms

preview_player
Показать описание
You are gIven an array of integers that is sorted in an ascending order and a target value. Find the index of first and last occurrence of the element in a fastest way possible. The desired complexity is less than linear time. Watch the video to learn how we can derive a clever solution using the concept of binary search. Work along with me to see how it can be solved easily along with the dry-run of code in JAVA.

Chapters:
00:00 - Intro
01:21 - Problem statement and description
03:12 - Brute Force Solution
06:03 - Efficient approach
07:44 - Using Binary Search Twice
10:30 - Dry-run of Code
14:26 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

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

I just started learning DSA when i am unable to solve leet code problem i first search in your youtube channel for a solution, In my opinion you are best at explain algorithms, Keep on going .

saitejanedunoori
Автор

I watched two explanations before this but couldn’t understand them. However, your teaching method was awesome, and I was able to write the code on my own right after understanding your solution. Thank you!

HarshChauhan-urjy
Автор

Fantastic and clear explanation. Thank you!

mikedelta
Автор

the way of teaching makes us to solve the more problems

Sridevikrish
Автор

the best, easy and good approach for the problem thanku so much nikhil for this

bhavyakarma
Автор

It was super smooth and easy to understand. Thanks 👍

krishnenduroy
Автор

The way you make things clear is superr

siva_avinash_
Автор

u explain everything and it was quite easy to understand, thankyouuu

aarzoo
Автор

The way of your explanation excellent 👏👏👏

atifraza
Автор

For input nums =[2, 2] & target =2, it won't work since in else block of find right mid=-1, so add check if(nums[mid]< target){
left= mid+1;
}
if(nums[mid] > target){
right = mid-1;
}

sumitmalpure
Автор

please upload more dsa question.. i only want to learn from you

ashishsonii
Автор

Will this solution work if input is [1, 2, 3] and target is 2

_shezzy
Автор

What happens if the first and the last index both exists in left bound? or right bound? this approach will return last index or first index as -1 right?

madhumithraravi
Автор

please upload more dsa question.. i only want to learn from you

ashishsonii
Автор

please upload more dsa question.. i only want to learn from you

ashishsonii
visit shbcf.ru