Find First and Last Position of Element in Sorted Array Leetcode 34 Solution | Searching and Sorting

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

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
1. Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.
2. If target is not found in the array, return [-1, -1].
3. You must write an algorithm with O(log n) runtime complexity.

Topic: #BinarySearch #SearchingAndSorting

Used #DataStructure: #Array

#TimeComplexity: O(log n)

#SpaceComplexity: O(1)

---------------------------------------------------------------

----------------------------------------------------------------

#BinarySearch #Leetcode34 #SearchingAndSorting
Рекомендации по теме
Комментарии
Автор

I watched almost 5 6 video of the same question but belive me this was something that is easy understandable
Thanks

it
Автор

best explaination literally! I have watched several videos then i stopped here

vanshikabajaj
Автор

The best explanation for this question, very very simple solution with minor changes, thanks for making understand the concept so clearly. Liked and subscribed pepcoding for this.

saileshramesh
Автор

Loved the explanation!! One of the best on YouTube!!

pragatiagrawal
Автор

The only tutorial on this problem I understood. Thanks!

anamikaahmed
Автор

Such an easy explanation thank you so much

vansh
Автор

you have best way to explain....lit best <3

avtarchandra
Автор

This is the best ever explanation. Thanks a lot for such a great explanation.

ChandraShekhar-bycd
Автор

I don't understand Indian but your code explained everything to me. Very classic approach and super optimal. Thanks!

KaisarAnvar
Автор

Awesome explaination....thank u ma'am !!!

DipakKumar-eyix
Автор

You just did a Magic in one minute. Great.

thiestmayank
Автор

mam great explanation btw congo for 45k

nischayrawat
Автор

Thank you for taking so much of initiative 👍👍👍🤗🤗

ManishYadav-esgz
Автор

boht hi mast samjahya maam apne, super clear ho gya binary search

mickyman
Автор

Python code:

class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
ans = [-1, -1]
lo = 0; hi = len(nums)-1
while lo <= hi:
mid = (lo+hi)//2
if nums[mid] == target:
ans[0] = mid
hi = mid - 1
elif nums[mid] < target:
lo = mid + 1
else:
hi = mid - 1
lo = 0; hi = len(nums) - 1
while lo <= hi:
mid = (lo+hi) // 2
if nums[mid] == target:
ans[1] = mid
lo = mid + 1
elif nums[mid] < target:
lo = mid + 1
else:
hi = mid - 1

return ans

ialgorithms
Автор

3:54 par aapne last index ko 2 se update kiya hai wahan par 6 se karna hai update

imshivendra
visit shbcf.ru