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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:34:58+00:00 2026-06-13T04:34:58+00:00

Given a sorted but rotated array how do you find the pivot ? I

  • 0

Given a sorted but rotated array how do you find the pivot ? I was asked this question in an interview. What is a rotated array ?

I got this on internet but its not clear at all.

In a rotated sorted array, only one of A and B can be guaranteed to be sorted.

Pivot is the element which is lesser then in left element and right element as well.

  • 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-13T04:35:00+00:00Added an answer on June 13, 2026 at 4:35 am

    I think a sorted, rotated array is something like this:

    Sorted:

    2, 7, 32, 48, 55
    

    Rotated:

     32, 48, 55, 2, 7
    

    2 is the pivot. You need to find the position of the pivot.

    Solution should be simple:
    the pivot is the point where the sorting ends and starts again. This is also what you “found on the Internet”:

    (assuming array is sorted in ascending order. If descending order, change < to >)

    for (i = 0; i<array.length; i++)
    {
        if array[i+1] < array[i]
            return i + 1;
            break;
    }
    

    Added: A divide and conquer logic that I could quickly think of. Keep spliting the array as long as the first element is larger than the last element. If the first element of the split (sub) array is not larger than the last element, the first is the pivot of the original array.

    int left = 0;
    int right = array.length - 1;
    while (array[left] > array[right])
    {
        int mid = left + (left + right) / 2;
        if(array[mid] > array[right])
        {
            left = mid + 1;
        }
        else
        {
            right = mid;
        }
    }
    return left;
    

    BTW, if you were asked this question in an interview, and you did not know what a sorted rotated array is, you can ask. If the interviewer explain it to you and then you give them a solution, you should be good. Personally I wouldn’t care if someone does not know terminology. As long as they can think, find logic and code, it should be fine.

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

Sidebar

Related Questions

Possible Duplicate: Easy interview question got harder: given numbers 1..100, find the missing number(s)
I know this question has been asked several times but the answers given don't
Question: Given a sorted array A find all possible difference of elements from A.
Here is one of my interview question. Given an array of N elements and
This is an interview question (phone screen): write a function (in Java) to find
(I know there's a similar post about this, but the solution given is not
the question is like this: there is a sorted list of n numbers. Given
this is a google interview question : Given a N*N Matrix. All rows are
Yet another interview question asked me to find the maximum possible subarray of repeated
I've been given an array that needs to be sorted by its key (associative

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.