Search in Rotated Sorted Array (LeetCode 33) | FREE DSA Course in JAVA | Lecture 55
Vložit
- čas přidán 23. 01. 2023
- This question has been asked in dream companies like Google, and Amazon and is a Leetcode problem number 33.
The question reads - There is an integer array nums sorted in ascending order (with distinct values).
Before being passed to your function, nums may be rotated at an unknown pivot index k. For example, (0,1,2,4,5,6,7) might be turned at pivot index 3 and become (4,5,6,7,0,1,2). You have to find the index of a given target value. if the target value is not present return -1.
You must write an algorithm with O(log n) runtime complexity.
Now if a search has to be done on an array in log n complexity, the only way you can do it, is by making a Binary search.
But the trick is that it is not entirely sorted after the rotation and hence we need to follow a different approach.
Let's see how we can solve this search in the rotated array problem in java.
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
one of the greatest explanation ever.❤❤
Sir you are the best teacher I have ever seen on the CZcams. Your explanation is the best Sir . 🫡
Superb explanation.
Thank you so much Really Great Explanation ❤
Legit explanation
Best explanation
tnq sir for this wonderful explanation
Thanks 🙏
mind blowing explaination way
Thanks. Do subscribe and share our content so that it can reach to every student in need of quality content.
i didnt understand how is that right subarray sorted? @ 05:05
this is really great god pls make this yt channel reach to every cs students
class sorting{
public static void main(String[] arg){
int [] numbers ={9,8,6,6,4,3,3,22,11,23};
Arrays.sort(numbers);
System.out.println("Sorted Array");
for(int number : numbers){
System.out.print(number +" ");
}
it is the easy pattern try it once
int arry[] = {7,8,1,2,3,4,5,6};
int target = 7;
This program fails when array[low] = target . Need to add one more condition to check this
Hello There, I was trying to contact course but I dont see any reply from you. I like your videos . Please do more.Also ,can you do a course for programming targeting goggle, meta, msft amazon. Please reply
Hi please contact +91 88923 91929
even the given example ans is not loved by this approch and i chek that my code and you code maches
class Solution {
public int search(int[] nums, int target) {
for(int i=0; i
this approach is based on linear search,for sorted arrays binary search is optimized approach.
Sir what about full stack development course?
When will this course demo lectures has been started?
Please tell sir please 🙏
Hi please contact +91 88923 91929
sir but what if they have given a array as [2,4,5,6,7,0,1] to said to find 0 then how will we find
3,1 fail ho rha h isse