First And Last Position Of An Element In A Sorted Array | FREE DSA Course in JAVA | Lecture 54

  Рет қаралды 8,794

TAP ACADEMY

TAP ACADEMY

Жыл бұрын

This question has been asked in the interview of Facebook, Google, and Microsoft and is a Leetcode problem number 34.
The question reads - Given an array of integer numbers sorted in ascending order, find the starting and ending position of a given target value.
if the target is not found in the array return [-1,-1].
You must write an algorithm with O(log n) runtime complexity.
Now a simple brute force approach will be to run a loop from the first index and return the index when the element is found first for a first position or starting position.
And, for the ending or last position run a loop from the last index.
But in this method, we will compromise with the time complexity given.
So one thing which is very clear is that we have to use the binary search algorithm for this program.
Let's see how a binary search approach with little changes can give the desired results as asked in this program.
Subscribe to our channel for regular updates on the dsa course and click on the bell icon to never miss an update from our dsa course.
Data Structures and Algorithms Free Course (Learn DSA Without Paise) Playlist - • Data Structures And Al...
For more information, fill this form: forms.gle/8eiUmM92Fx563Aen9
or call us at 8884881203
Facebook: / thetapacademy
Instagram: / tapacademy_online
Linkedin: / 73820805
Website: www.thetapacademy.com
#coding #dsa #dsacourse #java #javainterview #array #binarysearch

Пікірлер: 22
@bhavanimohan6809
@bhavanimohan6809 8 ай бұрын
You are such a genius made me understand very clearly when ever I have doubt on DSA I just immediately landed on your channel.
@arjungillela9565
@arjungillela9565 Жыл бұрын
Sir, You made it this simple, directly entered to the brain, Thank you
@TAPACADEMY
@TAPACADEMY Жыл бұрын
You are very welcome. Do subscribe to the channel.
@krishnavar7219
@krishnavar7219 Жыл бұрын
the way you explained this challenge...it is genius
@bun_bun17
@bun_bun17 Жыл бұрын
you guys make the best effort, you are great
@musicallymad9
@musicallymad9 5 ай бұрын
SUCH A WONDERFUL EXPLAINATION BY YOU SIR. THANKS A LOT SIR. THE WAY YOU EXPLAIN EVERY PROBLEM IS JUST AWESOME😍
@UmaGowda1232
@UmaGowda1232 Жыл бұрын
Superb explaination sir 💥
@anand1557
@anand1557 4 ай бұрын
very nice and simple explanation instead, easy to understand
@aaviff1810
@aaviff1810 4 ай бұрын
Best explanation sir thank u so much❤️
@sohamsonwane1534
@sohamsonwane1534 5 ай бұрын
best explanation sir
@Ashritha_purna
@Ashritha_purna 3 ай бұрын
Great lecture
@garimachawla775
@garimachawla775 9 ай бұрын
what an explaination wowwwwww
@BilalKhanBaraich
@BilalKhanBaraich 2 ай бұрын
Given a list of sorted integers and a ‘key’, find and return the index of the first integer that is not less than the ‘key’. If no such integer exists, return -1. The complexity shall be O(logn). (Marks 10) Example 1: {1, 2, 4, 5, 5, 6}, key = 2, returned index 2; Example 2: {1, 2, 4, 5, 5, 6}, key = 3, returned index 3; Example 3: {1, 2, 4, 5, 5, 6}, key = 5, returned index 4; Example 4: {1, 2, 4, 5, 5, 6}, key = 7, returned index -1; (Note: In the example, the indexing starts with 1 and not 0.) Only PSEUDO-CODE is acceptable. Sir kindly Solve this question
@lerinkuriakose
@lerinkuriakose Жыл бұрын
Super🤩
@pranalinaik2447
@pranalinaik2447 8 ай бұрын
Thank you so much😇
@TAPACADEMY
@TAPACADEMY 8 ай бұрын
You're welcome 😊
@srinivasareddymandem9204
@srinivasareddymandem9204 8 ай бұрын
anybody clear me what if encounter if the first occurence at first index how should we approach we cant compare mid-1 because 0 is the last
@avinashnoubade7272
@avinashnoubade7272 7 ай бұрын
String problem please
@krishnavar7219
@krishnavar7219 Жыл бұрын
sir,paste code in chat or give patreon link
@fariyabkhan8095
@fariyabkhan8095 3 ай бұрын
class Solution { public int[] searchRange(int[] nums, int target) { int[] res={-1,-1}; int beg=0,end=nums.length-1; int mid=0; while(begtarget) end=mid-1; else beg=mid+1; } beg=0; end=nums.length-1; mid=0; while(begtarget) end=mid-1; else beg=mid+1; } return res; } }
@aryanverma1233
@aryanverma1233 Жыл бұрын
THIS CODE IS NOT WORKING
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 4,1 МЛН
ТАМАЕВ vs ВЕНГАЛБИ. ФИНАЛЬНАЯ ГОНКА! BMW M5 против CLS
47:36
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 10 МЛН
PINK STEERING STEERING CAR
00:31
Levsob
Рет қаралды 22 МЛН
The hidden beauty of the A* algorithm
19:22
polylog
Рет қаралды 833 М.
The Algorithm Behind Spell Checkers
13:02
b001
Рет қаралды 404 М.
Dear Functional Bros
16:50
CodeAesthetic
Рет қаралды 466 М.
This is Why Programming Is Hard For you
10:48
The Coding Sloth
Рет қаралды 638 М.
Search in Rotated Sorted Array  #Binary Search Rotations Leetcode 33.
21:09
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 59 М.
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 4,1 МЛН