Jump to content

Find Minimum in Rotated Sorted Array


dasari4kntr

Recommended Posts

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]

Link to comment
Share on other sites

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..)..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...