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 8344479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:23:13+00:00 2026-06-09T06:23:13+00:00

Given an array, such as [7,8,9,0,1,2,3,4,5,6] , is it possible to determine the index

  • 0

Given an array, such as [7,8,9,0,1,2,3,4,5,6], is it possible to determine the index around which a rotation has occurred faster than O(n)?

With O(n), simply iterate through all the elements and mark the first decreasing element as the index.

A possibly better solution would be to iterate from both ends towards the middle, but this still has a worst case of O(n).

  • 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-06-09T06:23:15+00:00Added an answer on June 9, 2026 at 6:23 am

    (EDIT: The below assumes that elements are distinct. If they aren’t distinct, I don’t think there’s anything better than just scanning the array.)

    You can binary search it. I won’t post any code, but here’s the general idea: (I’ll assume that a >= b for the rest of this. If a < b, then we know it’s still in its sorted order)

    Take the first element, call it a, the last element b, and the middle element, calling it c.

    If a < c, then you know that the pivot is between c and b, and you can recurse (with c and b as your new ends). If a > c, then you know that the pivot is somewhere between the two, and recurse in that half (with a and c as ends) instead.

    ADDENDUM: To extend to cases with repeats, if we have a = c > b then we recurse with c and b as our ends, while if a = c = b, we scan from a to c to see if there is some element d such that it differs. If it doesn’t exist, then all of the numbers between a and c are equal, and thus we recurse with c and b as our ends. If it does, there are two scenarios:

    a > d < b: Here, d is then the smallest element since we scanned from the left, and we’re done.
    a < d > b: Here, we know the answer is somewhere between d and b, and so we recurse with those as our ends.

    In the best case scenario, we never have to use the equality case, giving us O(log n). Worst case, those scans encompass almost all of the array, giving us O(n).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an array. How can we find sum of elements in index interval (i,
Possible Duplicate: Interview Q: given an array of numbers, return array of products of
Given an array of ints, is it possible to choose a group of some
I need a container (like array)for integers in such a way that given x
Given an integer array of size N by the user. Print all the possible
Possible Duplicate: In PHP given a month string such as “November” how can I
Given an array of integers, what is the simplest way to iterate over it
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
given an array: array = [16 16 16 22 23 23 23 25 52
Given an Array A of n subArrays Sn, how can I select the Array

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.