Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:15+00:00 2026-05-27T14:25:15+00:00

I came across this question in one Interview. Please help me in getting the

  • 0

I came across this question in one Interview. Please help me in getting the solution.

Question is:

You have sorted rotatable array, i. e. the array contains elements which are sorted and it can be rotated circularly, like if the elements in array are [5,6,10,19,20,29] then rotating first time array becomes [29,5,6,10,19,20] and on second time it becomes [20,29,5,6,10,19] and so on.

So you need to find the smallest element in the array at any point. You won’t be provided with number times array is rotated. Just given the rotated array elements and find out the smallest among them. In this case output should be 5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:15+00:00Added an answer on May 27, 2026 at 2:25 pm

    Method 1:

    You can do this in O(logN) time.

    Use a modified binary search to find the point of rotation which is an index i such that
    arr[i] > arr[i+1].

    Example:

    [6,7,8,9,1,2,3,4,5]
           ^
           i
    

    The two sub-arrays
    (arr[1], arr[2], .., arr[i]) and
    (arr[i+1], arr[i+2], ..., arr[n]) are sorted.

    The answer is min(arr[1], arr[i+1])

    Method 2:

    When you split the sorted, rotated array into two halves (arr[1],..,arr[mid]) and (arr[mid+1],..,arr[n]), one of them is always sorted and the other always has the min. We can directly use a modified binary search to keep searching in the unsorted half

    // index of first element
    l = 0
    
    // index of last element.
    h = arr.length - 1
    
    // always restrict the search to the unsorted 
    // sub-array. The min is always there.
    while (arr[l] > arr[h]) {
            // find mid.
            mid = (l + h)/2
            // decide which sub-array to continue with.
            if (arr[mid] > arr[h]) {
                    l = mid + 1
            } else {
                    h = mid
            }
    }
    // answer
    return arr[l]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Help with algorithm problem from SPOJ Came across this interview question. Given
I came across this question on an interview questions thread. Here is the question:
Today I came across this question: you have a code static int counter =
I am preparing for my interview and came across this question: Consider that i
I came across this in an java interview earlier. It was one of the
I came across this post , which reports the following interview question: Given two
I recently came across a Microsoft Interview Question for Software Engineer. Given an array
Recently I came across one interesting question on linked list. Sorted singly linked list
I've been looking at this question and came across the following code in one
I came across this question in an interview. Any number with 3 in its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.