redsox Posted February 9, 2021 Report Posted February 9, 2021 def findMin(nums: List[int]) l = 0; r = len(nums) - 1 while l < r: mid = (l+r)//2 if nums[mid] < nums[r]: r = mid else: l = mid + 1 return nums[r] Quote
dasari4kntr Posted February 10, 2021 Author Report Posted February 10, 2021 8 hours ago, Vaampire said: This works but complexity is O(n). if i understood ur solution correctly, u r totally ignoring the fact that its rotated sorted array. Ur solution will work even for unsorted array. recursive alg should be used very cautiously. also ur solution used extra space too by coping elements into variables.. sorry, dint mean to discourage you. I am just giving feed back as an interviewer actually i agree partially.... one thing i agree with you is ...this program will work on any array not only rotated sorted array... but coming to performance....it can be improved by adding the memoization to the logic ... (dynamic programming..).. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.