My real question is the question asks us to find the index of the target value and the target value is aready given in the question.. Cant we just do a normal search for the target value and pass the index of the target value?
The question asks us to achieve the time complexity of O(log n), whereas a normal linear search would give a time complexity of O(n) that is larger than required.
first of all sorry if you found this a silly 1, if the given arr is : [4,5,6,7,0,1,2] and target is 0; as per your code, in the main part of ELSE (arr[mid] from the given array going on the mid is 1 and target is 0, how is it even possible? as( 1
You should always write test cases as a good coding practice. Also, the focus should be on writing methods and not the main function. That is why all programming platforms only ask you to implement methods. Given all this, if you still want to write the psvm method…just copy the test case in the main method and call using the object. The code will work as expected.
@@nikoo28 assertEquals(1, searchInRotatedSortedArray.search(nums, 4)); assertEquals(1, searchInRotatedSortedArray.alternateSearch(nums, 4)); what to put instead of assertEquals
@@infinite639 public static void main(String args[]) { // Code to input an array and target // inputArr // target input // Create object SearchInRotatedSortedArray someObject = new SearchInRotatedSortedArray(); // Get the output int result = someObject.search(inputArr, target); // Print the result System.out.println(result); }
When I need solution of any problem first I came and check if your video is present. You provide a greatExplanation. ThankYOu
that is so delightful to hear :)
Your explanation is really awesome bro. you are my goto person .. 👋
Amazing man! Your videos are easy to understand!
Great explanation.... thank you sir 👍😀
bro such a sweet naration
Thank you so much sir!
thanks a lot sir, this explanation really helped a lot!!😄
awesome video!
awesome sir.. pls continue other problems too.
I will keep them coming
extremely good explanation
I think bruteforce approach is enough for this problem, 2nd one also good
thank you sir
Thanks
Thankyou sir.
What happens when both the parts are sorted the serach may be directed to wrong direction when if block condition is being satisfied
can you please clarify your doubt?
🥰🥰🥰ThankYOu
On the 13th min, mid value will be 0+ (3-0)/2 = will be 1.
a small error on my side...but glad you followed it all along 😄
brute force solution is different and question is different , am I one who is finding this difference ?🤔 is it just searching element in array ?
My real question is
the question asks us to find the index of the target value and the target value is aready given in the question.. Cant we just do a normal search for the target value and pass the index of the target value?
same doubt.. :\
The question asks us to achieve the time complexity of O(log n), whereas a normal linear search would give a time complexity of O(n) that is larger than required.
first of all sorry if you found this a silly 1, if the given arr is : [4,5,6,7,0,1,2] and target is 0; as per your code, in the main part of ELSE (arr[mid] from the given array going on the mid is 1 and target is 0, how is it even possible? as( 1
// If right half is sorted
if (arr[mid]
without recursion, simple solution
public int search(int[] nums, int target) {
int n = nums.length;
int left = 0;
int right = n-1;
while(left
why you are using test cases please direct write the psvm code main fully to understadn and can run in intellij ide
You should always write test cases as a good coding practice. Also, the focus should be on writing methods and not the main function. That is why all programming platforms only ask you to implement methods.
Given all this, if you still want to write the psvm method…just copy the test case in the main method and call using the object.
The code will work as expected.
@@nikoo28 i want to know how to run without test cases using psvm
@@nikoo28 assertEquals(1, searchInRotatedSortedArray.search(nums, 4));
assertEquals(1, searchInRotatedSortedArray.alternateSearch(nums, 4));
what to put instead of assertEquals
@@infinite639
public static void main(String args[]) {
// Code to input an array and target
// inputArr
// target input
// Create object
SearchInRotatedSortedArray someObject = new SearchInRotatedSortedArray();
// Get the output
int result = someObject.search(inputArr, target);
// Print the result
System.out.println(result);
}
@@nikoo28 i find this today thank you for your videos and for help ❤️
Bro 3/2 = 2. You are saying on 13.00 min ...ha haa 😂😂. You r wrong
You get the idea what we are doing here :)
@@nikoo28 yes