Lecture 23: Binary Search Different Problem || Search Insert Position || Sqrt(x) || Count occurrence

preview_player
Показать описание
Binary Search
What is Binary Search
Binary search in C++.
1: Find First and Last Position of Element in Sorted Array

Day 31/180, #180daysofcode #180 hard

We have made a whole video in c++, How to solve pattern print problem. We explained everything with the help of code.

We are doing 180 days challenge and going to complete the whole course within the duration with quality content on Youtube. I am on the mission to create a tech revolution in our country and in upcoming future we want to create a tech which will create many jobs in India.

Video will come on Mon-Fri at 6am in the morning

Premium Feature includes:

1: Doubt Support
2: Mentorship session
3: Placement Support to Top Students
4: Resume and Linkedin Profile Building
5: Coding contest twice a month
6: Course completion Certificate
7: Home work Discussion


DSA Course for free
C++ Free Course
Rohit Negi DSA Course C++
Coder Army DSA Course c++
Function in C++
Pass by value.
Pass by reference
C++ important topics

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

I have tried a lot of But everyone is telling a concept verbally and directly write the Neither they dry run nor they tell how the loop is iterating.... 🥺❤ ..

sanjanad
Автор

00 q1, 21:14 its code, 26:17 q2 40:47 its code, 42:00 sqrt question 1:00:26 its code 1:07:00 Homework questions

KaranKumar-bhij
Автор

At 1:03:00, we can initialize "mid" as long long rather than int. This will resolve all errors automatically.

mananbatra
Автор

Thankyou Rohit Bhaiya, you explain every topic very patiently and step by step. Amazing Lecture 🥰

rxi-geek
Автор

sabkuch chamak ra bhaiya. Keep continuing the good work.

procrastinator
Автор

36:46 we can directly print "first"
Because first will hold the possible index value of the not found element 👍

hi
Автор

I was stuck on the sqrt(n) problem when you gave that in hw so when I checked the solution people were solving it using binary search but was not able to understand the code then but now
I think it will be made crystal clear by you bhaiya .
Thankyou bhaiya ❤❤

sumitvishwakarma
Автор

27:33
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int start =0, end =nums.size()-1;
int mid;
while(start<=end){
mid = start + (end-start)/2;
if(nums[mid] == target){
return mid;
}
else if(nums[mid]<target)
start = mid+1;
else
end = mid-1;
}
return start;
}
};

atifmalik
Автор

bhaiya logic banana aur implement karna, vo chotey chotey points ko dimaag mein rakhna ab kaafi default sa lagney laga hai aapki videos dekhkar .... thank you for the efforts bhaiya

thriveforsuccess
Автор

2nd question(search insert position) me normal binary search bhi use karr sakte hai bas end me -1 ki jagah start return karna hoga.

tusharagarwal
Автор

00:00= Q1) First & Last position of an element in an Array, 04:25=When to use Linear search & Binary Search, 21:16= Leetcode platform,

narutodihargo
Автор

Solution 5: Count zeroes ✅✅
int start = 0, end = n-1, mid, firstIndex = -1;

while(start<=end){
int mid = start + (end-start)/2;
if(arr[mid]==0){
firstIndex = mid;
if(mid==0 || arr[mid-1]!=0) break;
end = mid - 1;
}else{
start = mid + 1;
}
}

return firstIndex == -1 ? 0 : n-firstIndex;

joydeep-halder
Автор

Bhaiya i watch your videos daily with ongoing college and it will definitely give me an edge in Future so thank you and keep this going❤️

chinmayOP
Автор

00:01 Find First and Last
26:08 Insert Position
43:22 Sqrt(x)

Jv_Singh
Автор

Ram Ram Rohit bhai series bahut baddiya chal rahi hai aur sab kuch chamak raha hai apki wajah se best DSA corse on the internet thanks for the GOAT content man love&&respect++;

ManishKumar-dbj
Автор

1:03:57 we can also do long mid = start+(end-start)/2

RonakAnand-gqur
Автор

In Every video there is something new to learn. ❤❤❤❤

SunnyKadian
Автор

26:03 Optimization to Find First and Last Position of Element in Sorted Array 🚀🚀

We can check the adjacent left or right element matching or not, and this way we can avoid unnecessary search in left and right subarray.

class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
int firstIndex = -1, lastIndex = -1;
int start=0, end = nums.size() - 1, mid;

while(start<=end){
mid = start + (end-start)/2;
if(nums[mid]<target){
start = mid + 1;
}else if(nums[mid]>target){
end = mid - 1;
}else{
firstIndex = mid;
if(mid==0 || nums[mid-1]!=target) break;
end = mid - 1;
}
}

start = 0, end = nums.size() - 1;

while(start<=end){
mid = start + (end-start)/2;
if(nums[mid]<target){
start = mid + 1;
}else if(nums[mid]>target){
end = mid - 1;
}else{
lastIndex = mid;
if(mid==nums.size()-1 || nums[mid+1]!=target) break;
start = mid + 1;
}
}

return {firstIndex, lastIndex};
}
};

joydeep-halder
Автор

Bhaiya i am in class 9th and your teaching methods are so good that i got to know every topic crystal clear . I am watching your videos from day 1 and i will definitely complete the 180 challenge
By Abhay Deep

abhaydeep
Автор

Aapne youtube pr sbse best pdya ..ithe sare questions bhot ache smajae...

sheetalsharma