How many times is a sorted array rotated?

  Рет қаралды 172,502

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 153
@Thanapat086
@Thanapat086 5 жыл бұрын
for who don't understand modulo parts case 1 if mid = 0 or the first index for instance arr = [1, 2] prev = mid - 1 = -1 which thrown an error because arr[-1] is out of range prev = (mid - 1 + n) % n = 1, it prevent an error from negative index case 2 if mid = n - 1 or the last index such as arr = [2, 3, 1] , assume that mid = 2 next = mid + 1 = 3, which arr[3] is out of range next = (mid + 1) % n = 0, loop index is initialized to the first index, think like a circular array hope you understand
@harsh.sharma
@harsh.sharma 5 жыл бұрын
Thanks a lot!! This was really required! 🙏
@shikhajain5833
@shikhajain5833 4 жыл бұрын
Well explained👍🏻
@abraarz2971
@abraarz2971 3 жыл бұрын
Thanks
@rayeugene8139
@rayeugene8139 3 жыл бұрын
you all prolly dont give a shit but does any of you know a way to log back into an instagram account..? I stupidly lost the password. I would love any tricks you can give me
@drakemaddox8249
@drakemaddox8249 3 жыл бұрын
@Ray Eugene Instablaster ;)
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks for noticing Sudarshan !!
@cyberpsybin
@cyberpsybin 5 жыл бұрын
If you cannot understand the modulo part; you can try this mid = int(low + ((high - low) / 2)) # safely calculate previous and next indices previous = max(0, mid - 1) next = min(mid + 1, len(arr) - 1) This should always keep your 'next' and 'previous' indices inside the (0, length - 1) range. Rest is taken case by the equalities used all over the code (=)
@zhiyaowang8826
@zhiyaowang8826 11 жыл бұрын
Very well explained. It'd be great if you can do more of such videos!
@vandananayaknayak5511
@vandananayaknayak5511 4 жыл бұрын
i am just revising these concepts, and you indeed are just amazing sir.! thanks a lot
@ravindrabhatt
@ravindrabhatt 11 жыл бұрын
We use a search similar to binary search (or DFS), for every mid element in the array that we find when end > start and check if the mid element satisfies the Pivot property. Eventually one of the mid element will satisfy it if the array is a sorted array. Get the index of the Pivot to determine the num of rotation. The best performance will be O(1) and worst will be O(log n), Also we can have repetitions of same numbers but we can't really tell which of them is rotated.
@jameskelly132
@jameskelly132 6 жыл бұрын
To find the "pivot property", why do you need to check the next element? If prev is greater than mid, you've found your pivot.
@xof8256
@xof8256 5 жыл бұрын
true
@vinaypednekar680
@vinaypednekar680 5 жыл бұрын
what if your next element is greater ? that's why pivot property
@siddharth__pandey
@siddharth__pandey 5 жыл бұрын
@@vinaypednekar680 then it would not be a circularly sorted array
@downtowngedi
@downtowngedi 4 жыл бұрын
True, I don't think there is any need to check the next element, checking prev element is enough.
@thahirThavvagunta
@thahirThavvagunta 4 жыл бұрын
Wt you said is correct
@VoronweMagor
@VoronweMagor 3 жыл бұрын
No need to check the pivot property: def sorted_rotations_bin(a): L, R = 0, len(a) - 1 if R < 0 or a[L] < a[R]: return 0 while R - L > 1: M = (L + R) // 2 if a[M] < a[L]: R = M else: L = M if a[R] < a[L]: return R return L
@adarshverma3372
@adarshverma3372 2 жыл бұрын
One of the variation of the solution can be where we instead of checking the min element(and comparing two elements each time next and prev), as we can check for the maximum element in the array by just doing the one comparison as if (inputs[mid] > inputs[mid + 1) return mid + 1; // Please refer the below code for the same. public class SortedArrayRotated { public static void main(String[] args) { // int []inputs = new int[]{20, 30, 40, 50, 60, 70, 80, 90, 100, 10}; // int []inputs = new int[]{90, 100, 110, 10, 20, 30, 40, 50, 60}; // pivot element to break the recursion will be an element whose next number is smaller (ignoring the last index element). int []inputs = new int[]{100, 110, 120, 130, 140, 50, 60}; int numberOfRotation = numberOfTimesSortedArrayIsRotated(inputs, 0, inputs.length - 1); System.out.println( numberOfRotation != 0 ? "Inputs are rotated: " + numberOfRotation + " times" : "Inputs are not rotated as it is in sorted format already" ); } private static int numberOfTimesSortedArrayIsRotated(int []inputs, int startIndex, int endIndex) { if (startIndex > endIndex) return 0; int mid = (startIndex + endIndex) / 2; if (mid != inputs.length - 1) { if (inputs[mid] > inputs[mid + 1]) return mid + 1; else // as we are not passing (mid - 1) for getting the left segment so we have to add this for the exit condition here. if (mid == 0) return 0; else if (inputs[mid] < inputs[endIndex]) return numberOfTimesSortedArrayIsRotated(inputs, startIndex, mid); // here we have to include mid in taking the left segment becuase the check is only for comparing the next of mid else return numberOfTimesSortedArrayIsRotated(inputs, mid + 1, endIndex); } else { if (inputs[mid] < inputs[mid - 1]) return mid; else return 0; } } }
@sahu059
@sahu059 9 жыл бұрын
I just have doubt regarding pivot statement A[mid]
@igboman2860
@igboman2860 3 жыл бұрын
def search_smallest(arr): left, right = 0, len(arr) - 1 while left < right: mid = (left + right) // 2 if arr[mid] > arr[right]: left = mid + 1 else: right = mid return left found this in the book elements of the programming interview
@swaw11
@swaw11 Жыл бұрын
Simple Solution to find without Pivot: int findMin(vector& nums) { int start = 0; int end = nums.size() - 1; int number_of_times_rotated; while(start
@rishugoyal7970
@rishugoyal7970 4 жыл бұрын
Nice Explanation... You left one case when our A[mid] comes out to be the largest element in the given array.. In this case A[mid] > A[prev] && A[mid] > A[next] ..and so we have found our minimum element which is A[mid+1]
@pranavganorkar2379
@pranavganorkar2379 10 жыл бұрын
Hi Animesh...can we write the case for a[mid]
@no-body7286
@no-body7286 3 жыл бұрын
to solve edge cases like if there is one array
@abhishekguptasarma2060
@abhishekguptasarma2060 4 жыл бұрын
It feels so bad knowing such an amazing tutor will never upload another video 😥
@vikramadityavardhan4067
@vikramadityavardhan4067 4 жыл бұрын
Dude he's not dead his colleague is
@killerboy-mz9bd
@killerboy-mz9bd 3 жыл бұрын
@@vikramadityavardhan4067 what's channel owner name?
@ugh657
@ugh657 7 жыл бұрын
We really only need to check one condition inside the loop: A[mid] > A[right] if true the sub-array A[left .. mid] is sorted, update left = mid + 1 if false the sub-array A[mid .. right] is sorted, update right = mid We are done when: left == right This strategy will also handle duplicates.
@siddhantdeshmukh7120
@siddhantdeshmukh7120 5 жыл бұрын
hmm nice one.more efficient
@aakash4351
@aakash4351 3 жыл бұрын
14,16,18,20,2,4,6,8,10,12 in you case it will take 3 iteration, while with his logic only one iteration is required. If size of array is large then your logic will take more time compared to his. Correct me if i'm wrong.
@igboman2860
@igboman2860 3 жыл бұрын
@@aakash4351 it is still O(logn)
@ivandrofly
@ivandrofly 7 ай бұрын
Very simple/interesting problem (Learned before back in 2k17)
@dankyt9249
@dankyt9249 4 жыл бұрын
Final code in c++ which accepts duplicates and passes any test cases :- int rotation(int a[],int n) { int low=0, high=n-1, mid; while(low
@DilipkumarGangwar
@DilipkumarGangwar 4 жыл бұрын
Hi @Saurav Kumar , it seems it is not working: For example input is : 5, 6,7, 1, 2,2, 3,3,3, 4 No of rotations = 3, but your code is not giving correct answer
@ambarishguntupalli5152
@ambarishguntupalli5152 8 жыл бұрын
If the condition is that there are no duplicates, why are we using = inside the loop?
@ShivamAroraa
@ShivamAroraa 7 жыл бұрын
think when low = high e.g. Array = [1]
@ambarishguntupalli5152
@ambarishguntupalli5152 6 жыл бұрын
@@ShivamAroraa I think we need
@tarandeepsingh8704
@tarandeepsingh8704 4 жыл бұрын
@mycodeschool was, is, & will be the best channel ever!
@abhishekkasam6685
@abhishekkasam6685 4 жыл бұрын
Thank you so much broo u have clarified my all the doubts
@dingusagar
@dingusagar 6 жыл бұрын
def findMin(A,l,h): if A[l]
@sudarshan14sipu
@sudarshan14sipu 11 жыл бұрын
Hi..It was great video..Looks you have great expertise over B.S Just one thing which i would say you rectify here is remove = from conditional statements as here duplicates is not possible as per your condition.At machine level it will optimise the code. Thanx
@Wheelz_for_Feelz
@Wheelz_for_Feelz 5 жыл бұрын
What is the use of taking A[low]
@ashishshah9006
@ashishshah9006 4 жыл бұрын
consider the case where array is --> [1]
@thahirThavvagunta
@thahirThavvagunta 4 жыл бұрын
This case is when array rotated zero times
@captain_vegan
@captain_vegan 2 жыл бұрын
else if (A[mid] >= A[low]) low = mid + 1 ; why A[mid] >= A[low], but not A[mid] >= A[high] cause it doesnt work for arrays like [4,3,2,1]
@abocidejofa9686
@abocidejofa9686 11 жыл бұрын
thanks. great explanations
@ravisrivastava666
@ravisrivastava666 7 жыл бұрын
for this type of input {1,4,6,7,8,12,13,14,5} it goes in first case and return rotation count =0. which is actually the case for sorted array with no rotation. But basically the input is not correct.
@sharangkulkarni5718
@sharangkulkarni5718 4 жыл бұрын
सही है भाई !
@alphazero0
@alphazero0 4 жыл бұрын
hey can anyoe explain me whats the reason for (mid+1)%n? and also (A[mid]
@rpodder
@rpodder 4 жыл бұрын
suppose,for an array of size n, mid=n-1, if you do only next=(mid+1) then it will be, next=n. Which is not possible! So, to avoid this type of situation it is done as next=(mid+1)%n. So, when mid=n-1, the next element will be 0th element. And yes, only A[mid]
@alphazero0
@alphazero0 4 жыл бұрын
@@rpodder actually mid=n-1 case comes only when l=n-1 h=n-1, in this case, the first case if(A[l]
@rpodder
@rpodder 4 жыл бұрын
@@alphazero0 Oh, yes. What you said is correct. 👏
@alphazero0
@alphazero0 4 жыл бұрын
@@rpodder and whats the reason for A[mid]
@nguyenhung2441
@nguyenhung2441 7 жыл бұрын
int findNumberRotation(int A[], int low, int high) { while(low
@PanicIGaming
@PanicIGaming 6 жыл бұрын
in case 3, it should be [] high = mid [] , not [] high = mid-1 [] because if the average of high and low is odd, mid will never be [] (high+low)/2 + 1 []
@Varaprasad865
@Varaprasad865 3 жыл бұрын
Thank you so much
@user-mi8ew2to8e
@user-mi8ew2to8e 4 жыл бұрын
Why do you assume its sorted in increasing order?
@kamalsmusic
@kamalsmusic 10 жыл бұрын
How did you find the (n+mid-1)%n for the prev variable?
@srikanths5227
@srikanths5227 10 жыл бұрын
Great Explanation but the fourth case mentioned if(A[mid] >= A[low] is wrong. It should be A[mid] >= A[high].
@sarjeet91
@sarjeet91 9 жыл бұрын
Srikanth s No, this is right. See the condition: if (A[mid] >= A[low]) { // this will be only true if [low -- mid] range of array is sorted, and // you can skip this portion, and continue looking to rest of array low = mid+1; }
@nilofermehta3781
@nilofermehta3781 9 жыл бұрын
Hi just wondering that you said the condition set is "no duplicates" then why are you checking in case 1 that A[low]
@neerajjoshi9493
@neerajjoshi9493 7 жыл бұрын
no, in worst case, low and end index can simultaneously reach the pivot. for that case we need to write a[low]
@sarthakjoshi3797
@sarthakjoshi3797 5 жыл бұрын
@@neerajjoshi9493 I didn't get you. Can you explain more clearly?
@aayushwadhwa3788
@aayushwadhwa3788 5 жыл бұрын
@@sarthakjoshi3797
@ashishshah9006
@ashishshah9006 4 жыл бұрын
consider the case where array is --> [1]
@roopkishore785
@roopkishore785 7 жыл бұрын
why there is "less than or equal to operator" instead of only "less than" in "case 1: A[low]
@ashishshah9006
@ashishshah9006 4 жыл бұрын
consider the case where array is --> [1]
@tarun4705
@tarun4705 5 жыл бұрын
doesn't work if duplicates are involved. input - 345673
@AP-eh6gr
@AP-eh6gr 9 жыл бұрын
is the modulo part even necessary? the while loop runs 'while' low
@neerajjoshi9493
@neerajjoshi9493 7 жыл бұрын
the modulo part is necessary. for instance, take array having two elements {15,10} and perform dry run by yourself (not by compiler) you will get your answer. answer of this particular example should be 1. Then take array of three elements, for instance [5,10,2]. again do dry run by yourself. answer for this one is 2. BY THE END YOU WILL GET WHY MODULO WAS USED IN BOTH(PREV AND NEXT) STATEMENT.AND ALSO THE REASON OF ADDING n INSIDE BRACKET IN prev=(mid+n-1)%1. array of these length is just an example
@dongxie4756
@dongxie4756 11 ай бұрын
if (A[mid]
@niharikaepuri3305
@niharikaepuri3305 6 жыл бұрын
In 8:20 If change case3 and case 4 to if(arr[low]
@RT-jd9dw
@RT-jd9dw 5 жыл бұрын
Your code looks not to be working for input [2,1]. Output should be 1. Can you check once
@SidharthJhawar
@SidharthJhawar 10 жыл бұрын
mycodeschool Hi, If the 4th case holds true, doesnt that mean that the array is sorted and not rotated even once ? Correct me please if I am wrong.
@anshulsoni477
@anshulsoni477 10 жыл бұрын
Think about a case where the array is rotated more than half the size of array, something like {12, 13, 14, 15, 16, 18, 19, 1, 2}
@reetigarg7398
@reetigarg7398 7 жыл бұрын
Anshul Soni There are duplicates in your example so it won't work.
@anshulsoni477
@anshulsoni477 7 жыл бұрын
Reeti Garg I dont see duplicates unless you confused 1 2 in the end for 12 in the start. I fixed my comment to make it not confusing
@abhiragkesarwani2293
@abhiragkesarwani2293 7 жыл бұрын
I think, we don't need case 4 .
@manojpandey7517
@manojpandey7517 4 жыл бұрын
at 05:34 why you have used equality sign also if array elements are distinct ?
@srinadht7238
@srinadht7238 8 жыл бұрын
Can someone explain me the question . ? In test case: {15,22,23,28,31,38,5,6,8,10,12} and we are inserting 11 . How is this a sorted array, as we have elements less than 38 (i.e., 5,6,8,10,12) Can you please explain with this example ?
@domd511
@domd511 8 жыл бұрын
11 = length of array low = 0; high = 10; (arr[0] = arr[low]) low = mid + 1 = 6 low = 6 high = 10 arr[low]
@srinadht7238
@srinadht7238 8 жыл бұрын
Domenick D'Onofrio i mean i am confused with the question..
@domd511
@domd511 8 жыл бұрын
How many times is a sorted array rotated? ex: original array {1, 2, 3, 4, 5} rotated array {5, 1, 2, 3, 4} Here the original array returns that it is rotated "1" time when we run the code. In his example code we are taking in an already rotated array and finding the number of times it has been rotated.
@MridulBanikcse
@MridulBanikcse 6 жыл бұрын
This is circularly sorted array. Anyway, you asked that question 2 years ago. How r u doing now?
@MultiTalvin
@MultiTalvin 5 жыл бұрын
couldnt understand the modulu part.....
@abhijitpaul7683
@abhijitpaul7683 3 жыл бұрын
I think I have found an error in the algo. 2 4 4 4 5 6 8 circular form: 8 2 4 4 4 5 6, size=7 mid=(6+0)/2 = 3; arr[mid]=4; arr[prev]=4; arr[next]=4; now, arr[mid]
@vikku_19
@vikku_19 3 жыл бұрын
Well this algorithm doesn't work for duplicates.
@amitprasad3495
@amitprasad3495 6 жыл бұрын
You said that we put 'prev=(mid+N-1)%N' so that prev doesnt get a negative value. Can you show a test case where it is possible?
@siddharth__pandey
@siddharth__pandey 5 жыл бұрын
Take mid = 0
@gokulnaathbaskar9808
@gokulnaathbaskar9808 2 жыл бұрын
Thank you
@expertreviews1112
@expertreviews1112 5 жыл бұрын
it's clockwise, not anti clockwise
@nachiketakumar3841
@nachiketakumar3841 9 жыл бұрын
binary search approach is not working for some inputs for e.g {15,22,23,28,31,38,78,5,6,8,10,12} it is giving -1 as output . please correct me if i'm wrong.
@utkarshsaxena8034
@utkarshsaxena8034 7 жыл бұрын
This array is sorted circularly which is the case for this problem. But there is something wrong with the logic of this code. I am also getting such errors on InterviewBit.com
@anjana1700
@anjana1700 5 жыл бұрын
Sir while finding prev,you have used prev=mid+N-1. Why did u add N? pls answer it
@shashishekhar8336
@shashishekhar8336 5 жыл бұрын
so that prev does not become negative
@PraveenKumar-tx4od
@PraveenKumar-tx4od 6 жыл бұрын
I think this algorithm would fail when there are two elements. say [2,1]. here, values for next and previous would be 0 and hence, it will return 0. But 1 is the right answer.
@nishawadhwani909
@nishawadhwani909 5 жыл бұрын
This algorithm fails when a n-sized array is rotated n times.
@harsh.sharma
@harsh.sharma 5 жыл бұрын
@@nishawadhwani909 then the array is in an 'unrotated' state
@harsh.sharma
@harsh.sharma 5 жыл бұрын
Bro you need to understand why he used that modulo part.
@samyakkumbhalwar4296
@samyakkumbhalwar4296 8 жыл бұрын
Cant we take the case 1 out of while loop?
@Arka161
@Arka161 7 жыл бұрын
The code goes in an infinite loop if the array is in reverse sorted order. Example: {6,5,4,3,2,1}. Another simple line fixes the issue though. Add a final else, else low=mid+1; It will handle all corner cases.
@owlandahalf6681
@owlandahalf6681 6 жыл бұрын
That is not a valid rotated sorted array. It has to be sorted in ascending order before it is rotated.
@Achalshah20
@Achalshah20 6 жыл бұрын
@@owlandahalf6681 It won't work in case of 5,4,3,1,2. Basically in case of A[mid] < A[low] and A[mid] > A[high], it will go into infinite loop as none of the if condition executes!
@owlandahalf6681
@owlandahalf6681 6 жыл бұрын
@@Achalshah20 again, that is not a rotated sorted array. If you rotate it to 1, 2, 5, 4, 3, you will see that it is not sorted in ascending order, nor is there any other rotation that works.
@Achalshah20
@Achalshah20 6 жыл бұрын
@@owlandahalf6681 You are right. The given solution should work if array is sorted in ascending order. (Given conditions that array is not rotated+flipped and array is not in descending order)
@basabmukherjeeclass12bci29
@basabmukherjeeclass12bci29 Жыл бұрын
Your code is not running on my Mac ...😢
@daitavan297
@daitavan297 8 жыл бұрын
What problems can be solved by using this method in reality?
@slikdude12592
@slikdude12592 5 жыл бұрын
That's code interviewing in a nutshell!
@cyberpsybin
@cyberpsybin 5 жыл бұрын
Hope to run into sorted, rotated arrays some day lol
@ananths5905
@ananths5905 4 жыл бұрын
interview probs
@karthikperavelli1735
@karthikperavelli1735 5 жыл бұрын
this algorithm is not working for extreme case int A[]={16,15,14,13,12,11,10,8,7,6,3,2}; // try with this array as input
@sohailsayed23
@sohailsayed23 5 жыл бұрын
this is not a valid input. Though not defined explicitly it is clear that the assumption is that the input dataset is sorted in ascending else the conditions will need to change though similiar logic will apply.
@Volton007
@Volton007 7 жыл бұрын
What if the array is rotated clockwise/rotated towards left? How to find out how many times it is rotated?
@shreevatsalamborghin
@shreevatsalamborghin 4 жыл бұрын
Volton007 check for the max ele
@robtangled8816
@robtangled8816 2 жыл бұрын
8:05 ....what did he say?
@salemouail627
@salemouail627 4 жыл бұрын
If u cant get the module part For example an array of 5 elements and the mid is 4 Prev = 4+(5-1) =9 We are passing our array size We need to go the first element when we pass it So we use % (the rest of the divide) 9/5 = 1 and the rest is 4 ( thats the modulo) So index is 4 now :)
@gauravkumarsoni3095
@gauravkumarsoni3095 10 жыл бұрын
I am not getting adding N and modulo N???
@Joyddep
@Joyddep 6 жыл бұрын
What in the case of duplicates?
@ronitmishra8917
@ronitmishra8917 5 жыл бұрын
use linear algorithm..
@asishpatra7556
@asishpatra7556 3 жыл бұрын
what if we have similar elements(same value)?
@涛哥涛哥-i1p
@涛哥涛哥-i1p Жыл бұрын
if all the element is the same value, then the rotation will be a meaningless action. but maybe there are several same elements, in that condition the example code will have bugs. we can change the condition to avoid bugs.
@savar33
@savar33 6 жыл бұрын
thanks for the explanation. in case 2: why do you need to check next? I mean you know the array is cyclically sorted. isn't it enough to check only prev in case 2? prev = (mid +n -1)%n if A[mid]
@gyanasahu1006
@gyanasahu1006 4 жыл бұрын
Doesn't work for [3,1]
@075_ritikkumar7
@075_ritikkumar7 4 жыл бұрын
in your case mid as well as low is 3. so case 4 is applicable. Low becomes 1(low=mid+1).in next iteration low=high(case 1) and function returns 1.
@Chris-cs7nv
@Chris-cs7nv Жыл бұрын
despite essentially copying everything to make sure I am not doing anything different, I am stuck in infinite loops :'(
@amritkanoi8804
@amritkanoi8804 4 жыл бұрын
delete that last else case , otherwise u will get TLE in pure decreasing arrays like [4,3,2,1]
@rohan9354
@rohan9354 7 жыл бұрын
It wont work on 6 5 4 3 2 1
@dipanshu2310
@dipanshu2310 5 жыл бұрын
becuase its not circularly sorted...for which above code is
@shreevatsalamborghin
@shreevatsalamborghin 4 жыл бұрын
Rohan Aggarwal not sorted
@mdshahidulislam3982
@mdshahidulislam3982 4 жыл бұрын
আর সহেজেই করা যায় !!! int FindRotationCount(vector &A) { int limit = A.size(); int n = A[0]; // when we find minimum value then return this index for(int i=0;i
@rpodder
@rpodder 4 жыл бұрын
time complexity: O(n)
@ravindrabhatt
@ravindrabhatt 11 жыл бұрын
Not sure how the linear search code will work? If you take your example 12 2 3 5 8 11,, after the loop 11 will be in min.
@mycodeschool
@mycodeschool 11 жыл бұрын
How will 11 be in min? You start with min = 11, minIndex = 0. Go in loop compare with A[1] = 12, not lesser than min, so move on. Go to A[2] =1, lesser than min, so min is now 2 and minIndex = 2. Now we will not go inside if condition for any A[i]. So. min will be 2 after the loop.
@ravindrabhatt
@ravindrabhatt 11 жыл бұрын
mycodeschool I was taking the 12 2 3 5 8 11 case where it is rotated once,, we start with min= 12 and minIndex=0, A[1]=2 and is less than min so we update min=2 and so on up to n-1=5 i,e 11. Since 11 is also less than 12 it will be stored in min.
@mycodeschool
@mycodeschool 11 жыл бұрын
ravi seetharam - And how exactly? When A[1] = 2, you are updating min. So now, min = 2, min Index =1. Next time for A[2] , A[3] and so on, we will not go inside the if statement because min is now 2.
@yadneshkhode3091
@yadneshkhode3091 3 жыл бұрын
@@ravindrabhatt Bhang peeke coding kar rahe ho kya
@gamoholic7653
@gamoholic7653 3 жыл бұрын
@@yadneshkhode3091 xD
@shakiulanam6569
@shakiulanam6569 7 жыл бұрын
why pre=(mid+n-1)%n; why not pre=(mid-1)??
@BrajeshKumardreamer
@BrajeshKumardreamer 7 жыл бұрын
Think what would happen for mid = 0. pre = -1 % n would be -1. and the code will throw an index out of bound exception.
@bijjalavenkateswarlu9306
@bijjalavenkateswarlu9306 7 жыл бұрын
It was clearly explained in the video itself at 6:40
@sagar7958
@sagar7958 7 жыл бұрын
what % operator did?
@nguyenhung2441
@nguyenhung2441 7 жыл бұрын
return the remainder
@DeepeshMaheshwari17feb
@DeepeshMaheshwari17feb 9 жыл бұрын
Code Fails to identity invalid array : int[] arr = { 11, 12, 15, 1, 18, 2, 5, 6, 8 }
@paulchino81
@paulchino81 9 жыл бұрын
Deepesh Maheshwari thats not a rotated sorted array. 18 cannot be between 1 and 2
Search element in a circular sorted array
12:22
mycodeschool
Рет қаралды 124 М.
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 36 МЛН
Как Я Брата ОБМАНУЛ (смешное видео, прикол, юмор, поржать)
00:59
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Analysis of quicksort
20:17
mycodeschool
Рет қаралды 311 М.
Inorder Successor in a binary search tree
17:58
mycodeschool
Рет қаралды 362 М.
What is binary search
12:45
mycodeschool
Рет қаралды 705 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Quicksort algorithm
20:39
mycodeschool
Рет қаралды 1,8 МЛН
Check if a binary tree is binary search tree or not
16:30
mycodeschool
Рет қаралды 380 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 836 М.
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 36 МЛН